| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/observer_list_threadsafe.h" | 10 #include "base/observer_list_threadsafe.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 DISALLOW_COPY_AND_ASSIGN(DNSObserver); | 77 DISALLOW_COPY_AND_ASSIGN(DNSObserver); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 virtual ~NetworkChangeNotifier(); | 80 virtual ~NetworkChangeNotifier(); |
| 81 | 81 |
| 82 // See the description of NetworkChangeNotifier::IsOffline(). | 82 // See the description of NetworkChangeNotifier::IsOffline(). |
| 83 // Implementations must be thread-safe. Implementations must also be | 83 // Implementations must be thread-safe. Implementations must also be |
| 84 // cheap as this could be called (repeatedly) from the IO thread. | 84 // cheap as this could be called (repeatedly) from the IO thread. |
| 85 virtual bool IsCurrentlyOffline() const = 0; | 85 virtual bool IsCurrentlyOffline() const = 0; |
| 86 | 86 |
| 87 // Returns true if DNS watchers are operational. |
| 88 // Otherwise, OnDNSChanged might not be issued for future changes. |
| 89 // TODO(szym): This is a temporary interface, consider restarting them. |
| 90 // http://crbug.com/116139 |
| 91 virtual bool IsCurrentlyWatchingDNS() const; |
| 92 |
| 87 // Replaces the default class factory instance of NetworkChangeNotifier class. | 93 // Replaces the default class factory instance of NetworkChangeNotifier class. |
| 88 // The method will take over the ownership of |factory| object. | 94 // The method will take over the ownership of |factory| object. |
| 89 static void SetFactory(NetworkChangeNotifierFactory* factory); | 95 static void SetFactory(NetworkChangeNotifierFactory* factory); |
| 90 | 96 |
| 91 // Creates the process-wide, platform-specific NetworkChangeNotifier. The | 97 // Creates the process-wide, platform-specific NetworkChangeNotifier. The |
| 92 // caller owns the returned pointer. You may call this on any thread. You | 98 // caller owns the returned pointer. You may call this on any thread. You |
| 93 // may also avoid creating this entirely (in which case nothing will be | 99 // may also avoid creating this entirely (in which case nothing will be |
| 94 // monitored), but if you do create it, you must do so before any other | 100 // monitored), but if you do create it, you must do so before any other |
| 95 // threads try to access the API below, and it must outlive all other threads | 101 // threads try to access the API below, and it must outlive all other threads |
| 96 // which might try to use it. | 102 // which might try to use it. |
| 97 static NetworkChangeNotifier* Create(); | 103 static NetworkChangeNotifier* Create(); |
| 98 | 104 |
| 99 // Returns true if there is currently no internet connection. | 105 // Returns true if there is currently no internet connection. |
| 100 // | 106 // |
| 101 // A return value of |true| is a pretty strong indicator that the user | 107 // A return value of |true| is a pretty strong indicator that the user |
| 102 // won't be able to connect to remote sites. However, a return value of | 108 // won't be able to connect to remote sites. However, a return value of |
| 103 // |false| is inconclusive; even if some link is up, it is uncertain | 109 // |false| is inconclusive; even if some link is up, it is uncertain |
| 104 // whether a particular connection attempt to a particular remote site | 110 // whether a particular connection attempt to a particular remote site |
| 105 // will be successfully. | 111 // will be successfully. |
| 106 static bool IsOffline(); | 112 static bool IsOffline(); |
| 107 | 113 |
| 114 // Returns true if DNS watchers are operational. |
| 115 static bool IsWatchingDNS(); |
| 116 |
| 108 // Like Create(), but for use in tests. The mock object doesn't monitor any | 117 // Like Create(), but for use in tests. The mock object doesn't monitor any |
| 109 // events, it merely rebroadcasts notifications when requested. | 118 // events, it merely rebroadcasts notifications when requested. |
| 110 static NetworkChangeNotifier* CreateMock(); | 119 static NetworkChangeNotifier* CreateMock(); |
| 111 | 120 |
| 112 // Registers |observer| to receive notifications of network changes. The | 121 // Registers |observer| to receive notifications of network changes. The |
| 113 // thread on which this is called is the thread on which |observer| will be | 122 // thread on which this is called is the thread on which |observer| will be |
| 114 // called back with notifications. This is safe to call if Create() has not | 123 // called back with notifications. This is safe to call if Create() has not |
| 115 // been called (as long as it doesn't race the Create() call on another | 124 // been called (as long as it doesn't race the Create() call on another |
| 116 // thread), in which case it will simply do nothing. | 125 // thread), in which case it will simply do nothing. |
| 117 static void AddIPAddressObserver(IPAddressObserver* observer); | 126 static void AddIPAddressObserver(IPAddressObserver* observer); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 online_state_observer_list_; | 180 online_state_observer_list_; |
| 172 const scoped_refptr<ObserverListThreadSafe<DNSObserver> > | 181 const scoped_refptr<ObserverListThreadSafe<DNSObserver> > |
| 173 resolver_state_observer_list_; | 182 resolver_state_observer_list_; |
| 174 | 183 |
| 175 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); | 184 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); |
| 176 }; | 185 }; |
| 177 | 186 |
| 178 } // namespace net | 187 } // namespace net |
| 179 | 188 |
| 180 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 189 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| OLD | NEW |