• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_H_
6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_
7 
8 #include "base/basictypes.h"
9 #include "base/non_thread_safe.h"
10 
11 namespace net {
12 
13 // NetworkChangeNotifier monitors the system for network changes, and notifies
14 // observers on those events.
15 class NetworkChangeNotifier : public NonThreadSafe {
16  public:
17   class Observer {
18    public:
~Observer()19     virtual ~Observer() {}
20 
21     // Will be called when the IP address of the primary interface changes.
22     // This includes when the primary interface itself changes.
23     virtual void OnIPAddressChanged() = 0;
24 
25    protected:
Observer()26     Observer() {}
27 
28    private:
29     DISALLOW_COPY_AND_ASSIGN(Observer);
30   };
31 
NetworkChangeNotifier()32   NetworkChangeNotifier() {}
~NetworkChangeNotifier()33   virtual ~NetworkChangeNotifier() {}
34 
35   // These functions add and remove observers to/from the NetworkChangeNotifier.
36   // Each call to AddObserver() must be matched with a corresponding call to
37   // RemoveObserver() with the same parameter.  Observers must remove themselves
38   // before they get deleted, otherwise the NetworkChangeNotifier may try to
39   // notify the wrong object.
40   virtual void AddObserver(Observer* observer) = 0;
41   virtual void RemoveObserver(Observer* observer) = 0;
42 
43   // This will create the platform specific default NetworkChangeNotifier.
44   static NetworkChangeNotifier* CreateDefaultNetworkChangeNotifier();
45 
46  private:
47   DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier);
48 };
49 
50 }  // namespace net
51 
52 #endif  // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_
53