| 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 #include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h" | 5 #include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/chromeos/cros/cros_library.h" | 8 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 9 #include "chromeos/dbus/dbus_thread_manager.h" | 9 #include "chromeos/dbus/dbus_thread_manager.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "net/dns/dns_config_service_posix.h" |
| 11 | 12 |
| 12 using content::BrowserThread; | 13 using content::BrowserThread; |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // Delay for online change notification reporting. | 17 // Delay for online change notification reporting. |
| 17 const int kOnlineNotificationDelayMS = 500; | 18 const int kOnlineNotificationDelayMS = 500; |
| 18 const int kInitialNotificationCheckDelayMS = 1000; | 19 const int kInitialNotificationCheckDelayMS = 1000; |
| 19 | 20 |
| 20 bool IsOnline(chromeos::ConnectionState state) { | 21 bool IsOnline(chromeos::ConnectionState state) { |
| 21 return state == chromeos::STATE_ONLINE || | 22 return state == chromeos::STATE_ONLINE || |
| 22 state == chromeos::STATE_PORTAL; | 23 state == chromeos::STATE_PORTAL; |
| 23 } | 24 } |
| 24 | 25 |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace chromeos { | 28 namespace chromeos { |
| 28 | 29 |
| 30 class NetworkChangeNotifierChromeos::DnsConfigServiceChromeos |
| 31 : public net::internal::DnsConfigServicePosix { |
| 32 public: |
| 33 DnsConfigServiceChromeos() {} |
| 34 |
| 35 virtual ~DnsConfigServiceChromeos() {} |
| 36 |
| 37 // net::DnsConfigServicePosix: |
| 38 virtual bool StartWatching() OVERRIDE { |
| 39 // Notifications from NetworkLibrary are sent to |
| 40 // NetworkChangeNotifierChromeos. |
| 41 return true; |
| 42 } |
| 43 |
| 44 void OnNetworkChange() { |
| 45 InvalidateConfig(); |
| 46 InvalidateHosts(); |
| 47 ReadNow(); |
| 48 } |
| 49 }; |
| 50 |
| 29 NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos() | 51 NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos() |
| 30 : has_active_network_(false), | 52 : has_active_network_(false), |
| 31 connection_state_(chromeos::STATE_UNKNOWN), | 53 connection_state_(chromeos::STATE_UNKNOWN), |
| 32 connection_type_(CONNECTION_NONE), | 54 connection_type_(CONNECTION_NONE), |
| 33 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 55 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 34 BrowserThread::PostDelayedTask( | 56 BrowserThread::PostDelayedTask( |
| 35 BrowserThread::UI, FROM_HERE, | 57 BrowserThread::UI, FROM_HERE, |
| 36 base::Bind( | 58 base::Bind( |
| 37 &NetworkChangeNotifierChromeos::UpdateInitialState, this), | 59 &NetworkChangeNotifierChromeos::UpdateInitialState, this), |
| 38 base::TimeDelta::FromMilliseconds(kInitialNotificationCheckDelayMS)); | 60 base::TimeDelta::FromMilliseconds(kInitialNotificationCheckDelayMS)); |
| 39 } | 61 } |
| 40 | 62 |
| 41 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { | 63 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { |
| 42 } | 64 } |
| 43 | 65 |
| 44 void NetworkChangeNotifierChromeos::Init() { | 66 void NetworkChangeNotifierChromeos::Init() { |
| 45 chromeos::NetworkLibrary* network_library = | 67 chromeos::NetworkLibrary* network_library = |
| 46 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 68 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 47 network_library->AddNetworkManagerObserver(this); | 69 network_library->AddNetworkManagerObserver(this); |
| 48 | 70 |
| 49 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 71 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 50 | 72 |
| 73 dns_config_service_.reset(new DnsConfigServiceChromeos()); |
| 74 dns_config_service_->WatchConfig( |
| 75 base::Bind(NetworkChangeNotifier::SetDnsConfig)); |
| 76 |
| 51 UpdateNetworkState(network_library); | 77 UpdateNetworkState(network_library); |
| 52 } | 78 } |
| 53 | 79 |
| 54 void NetworkChangeNotifierChromeos::Shutdown() { | 80 void NetworkChangeNotifierChromeos::Shutdown() { |
| 55 weak_factory_.InvalidateWeakPtrs(); | 81 weak_factory_.InvalidateWeakPtrs(); |
| 56 | 82 |
| 83 dns_config_service_.reset(); |
| 84 |
| 57 if (!chromeos::CrosLibrary::Get()) | 85 if (!chromeos::CrosLibrary::Get()) |
| 58 return; | 86 return; |
| 59 | 87 |
| 60 chromeos::NetworkLibrary* lib = | 88 chromeos::NetworkLibrary* lib = |
| 61 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 89 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 62 lib->RemoveNetworkManagerObserver(this); | 90 lib->RemoveNetworkManagerObserver(this); |
| 63 lib->RemoveObserverForAllNetworks(this); | 91 lib->RemoveObserverForAllNetworks(this); |
| 64 | 92 |
| 65 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 93 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
| 66 } | 94 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 lib->RemoveObserverForAllNetworks(this); | 148 lib->RemoveObserverForAllNetworks(this); |
| 121 if (!network) { | 149 if (!network) { |
| 122 has_active_network_ = false; | 150 has_active_network_ = false; |
| 123 service_path_.clear(); | 151 service_path_.clear(); |
| 124 ip_address_.clear(); | 152 ip_address_.clear(); |
| 125 } else { | 153 } else { |
| 126 has_active_network_ = true; | 154 has_active_network_ = true; |
| 127 service_path_ = network->service_path(); | 155 service_path_ = network->service_path(); |
| 128 ip_address_ = network->ip_address(); | 156 ip_address_ = network->ip_address(); |
| 129 } | 157 } |
| 158 // TODO(szym): detect user DNS changes. http://crbug.com/148394 |
| 159 dns_config_service_->OnNetworkChange(); |
| 130 UpdateConnectivityState(network); | 160 UpdateConnectivityState(network); |
| 131 // If there is an active network, add observer to track its changes. | 161 // If there is an active network, add observer to track its changes. |
| 132 if (network) | 162 if (network) |
| 133 lib->AddNetworkObserver(network->service_path(), this); | 163 lib->AddNetworkObserver(network->service_path(), this); |
| 134 | 164 |
| 135 BrowserThread::PostTask( | 165 BrowserThread::PostTask( |
| 136 BrowserThread::IO, FROM_HERE, | 166 BrowserThread::IO, FROM_HERE, |
| 137 base::Bind( | 167 base::Bind( |
| 138 &NetworkChangeNotifier::NotifyObserversOfIPAddressChange)); | 168 &NetworkChangeNotifier::NotifyObserversOfIPAddressChange)); |
| 139 } | 169 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 283 } |
| 254 case chromeos::TYPE_BLUETOOTH: | 284 case chromeos::TYPE_BLUETOOTH: |
| 255 case chromeos::TYPE_VPN: | 285 case chromeos::TYPE_VPN: |
| 256 case chromeos::TYPE_UNKNOWN: | 286 case chromeos::TYPE_UNKNOWN: |
| 257 break; | 287 break; |
| 258 } | 288 } |
| 259 return net::NetworkChangeNotifier::CONNECTION_UNKNOWN; | 289 return net::NetworkChangeNotifier::CONNECTION_UNKNOWN; |
| 260 } | 290 } |
| 261 | 291 |
| 262 } // namespace chromeos | 292 } // namespace chromeos |
| OLD | NEW |