| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_COMMON_NET_NETWORK_CHANGE_NOTIFIER_PROXY_H_ | |
| 6 #define CHROME_COMMON_NET_NETWORK_CHANGE_NOTIFIER_PROXY_H_ | |
| 7 | |
| 8 // NetworkChangeNotifierProxy is a class that lets observers listen to | |
| 9 // a NetworkChangeNotifier that lives on another thread. | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/non_thread_safe.h" | |
| 13 #include "base/observer_list.h" | |
| 14 #include "base/ref_counted.h" | |
| 15 #include "net/base/network_change_notifier.h" | |
| 16 | |
| 17 class MessageLoop; | |
| 18 | |
| 19 namespace chrome_common_net { | |
| 20 | |
| 21 class NetworkChangeNotifierThread; | |
| 22 class NetworkChangeObserverProxy; | |
| 23 | |
| 24 class NetworkChangeNotifierProxy : public net::NetworkChangeNotifier, | |
| 25 public NonThreadSafe { | |
| 26 public: | |
| 27 // |source_thread| must be guaranteed to outlive the current thread. | |
| 28 // Does not take ownership of any arguments. | |
| 29 explicit NetworkChangeNotifierProxy( | |
| 30 NetworkChangeNotifierThread* source_thread); | |
| 31 | |
| 32 virtual ~NetworkChangeNotifierProxy(); | |
| 33 | |
| 34 // net::NetworkChangeNotifier implementation. | |
| 35 virtual void AddObserver(net::NetworkChangeNotifier::Observer* observer); | |
| 36 virtual void RemoveObserver(net::NetworkChangeNotifier::Observer* observer); | |
| 37 | |
| 38 private: | |
| 39 typedef ObserverList<net::NetworkChangeNotifier::Observer, true> | |
| 40 NetworkObserverList; | |
| 41 | |
| 42 // Utility class that routes received notifications to a list of | |
| 43 // observers. | |
| 44 class ObserverRepeater : public net::NetworkChangeNotifier::Observer, | |
| 45 public NonThreadSafe { | |
| 46 public: | |
| 47 // Does not take ownership of the given observer list. | |
| 48 explicit ObserverRepeater(NetworkObserverList* observers); | |
| 49 | |
| 50 virtual ~ObserverRepeater(); | |
| 51 | |
| 52 // net::NetworkChangeNotifier::Observer implementation. | |
| 53 virtual void OnIPAddressChanged(); | |
| 54 | |
| 55 private: | |
| 56 NetworkObserverList* observers_; | |
| 57 | |
| 58 DISALLOW_COPY_AND_ASSIGN(ObserverRepeater); | |
| 59 }; | |
| 60 | |
| 61 scoped_refptr<NetworkChangeObserverProxy> observer_proxy_; | |
| 62 NetworkObserverList observers_; | |
| 63 ObserverRepeater observer_repeater_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierProxy); | |
| 66 }; | |
| 67 | |
| 68 } // namespace chrome_common_net | |
| 69 | |
| 70 #endif // CHROME_COMMON_NET_NETWORK_CHANGE_NOTIFIER_PROXY_H_ | |
| OLD | NEW |