| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | 5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ |
| 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include <SystemConfiguration/SCDynamicStore.h> |
| 9 #include "base/non_thread_safe.h" | 9 |
| 10 #include "base/observer_list.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/scoped_cftyperef.h" |
| 12 #include "base/scoped_ptr.h" | |
| 13 #include "base/task.h" | |
| 14 #include "net/base/network_change_notifier.h" | 12 #include "net/base/network_change_notifier.h" |
| 15 | 13 |
| 16 class MessageLoop; | |
| 17 namespace base { | 14 namespace base { |
| 18 class Thread; | 15 class Thread; |
| 19 } // namespace base | 16 } |
| 20 | 17 |
| 21 namespace net { | 18 namespace net { |
| 22 | 19 |
| 23 class NetworkChangeNotifierMac : public NetworkChangeNotifier, | 20 class NetworkChangeNotifierMac : public MessageLoop::DestructionObserver, |
| 24 public NonThreadSafe { | 21 public NetworkChangeNotifier { |
| 25 public: | 22 public: |
| 26 NetworkChangeNotifierMac(); | 23 NetworkChangeNotifierMac(); |
| 27 | 24 |
| 28 void OnIPAddressChanged(); | |
| 29 | |
| 30 // NetworkChangeNotifier methods: | |
| 31 virtual void AddObserver(Observer* observer); | |
| 32 virtual void RemoveObserver(Observer* observer); | |
| 33 | |
| 34 private: | 25 private: |
| 35 friend class base::RefCounted<NetworkChangeNotifierMac>; | |
| 36 | |
| 37 virtual ~NetworkChangeNotifierMac(); | 26 virtual ~NetworkChangeNotifierMac(); |
| 38 | 27 |
| 39 // Initializes the notifier thread. The SystemConfiguration calls in this | 28 // Called back by OS. Calls OnNetworkConfigChange(). |
| 40 // function can lead to contention early on, so we invoke this function later | 29 static void DynamicStoreCallback(SCDynamicStoreRef /* store */, |
| 41 // on in startup to keep it fast. | 30 CFArrayRef changed_keys, |
| 42 // See http://crbug.com/34926 for details. | 31 void* config); |
| 43 void InitializeNotifierThread(MessageLoop* loop); | |
| 44 | 32 |
| 45 // Receives the OS X network change notifications on this thread. | 33 // MessageLoop::DestructionObserver: |
| 34 virtual void WillDestroyCurrentMessageLoop(); |
| 35 |
| 36 // Called on the notifier thread to initialize the notification |
| 37 // implementation. The SystemConfiguration calls in this function can lead to |
| 38 // contention early on, so we invoke this function later on in startup to keep |
| 39 // it fast. |
| 40 void Init(); |
| 41 |
| 42 // Called by DynamicStoreCallback() when something about the network config |
| 43 // changes. |
| 44 void OnNetworkConfigChange(CFArrayRef changed_keys); |
| 45 |
| 46 // The thread used to listen for notifications. This relays the notification |
| 47 // to the registered observers without posting back to the thread the object |
| 48 // was created on. |
| 46 scoped_ptr<base::Thread> notifier_thread_; | 49 scoped_ptr<base::Thread> notifier_thread_; |
| 47 | 50 |
| 48 // TODO(willchan): Fix the URLRequestContextGetter leaks and flip the false to | 51 scoped_cftyperef<CFRunLoopSourceRef> run_loop_source_; |
| 49 // true so we assert that all observers have been removed. | |
| 50 ObserverList<Observer, false> observers_; | |
| 51 | |
| 52 // Used to initialize the notifier thread. | |
| 53 ScopedRunnableMethodFactory<NetworkChangeNotifierMac> method_factory_; | |
| 54 | 52 |
| 55 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); | 53 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 } // namespace net | 56 } // namespace net |
| 59 | 57 |
| 60 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | 58 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ |
| OLD | NEW |