Chromium Code Reviews| 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::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 is_online_(false), | 55 is_online_(false), |
| 34 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 56 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 35 BrowserThread::PostDelayedTask( | 57 BrowserThread::PostDelayedTask( |
| 36 BrowserThread::UI, FROM_HERE, | 58 BrowserThread::UI, FROM_HERE, |
| 37 base::Bind( | 59 base::Bind( |
| 38 &NetworkChangeNotifierChromeos::UpdateInitialState, this), | 60 &NetworkChangeNotifierChromeos::UpdateInitialState, this), |
| 39 base::TimeDelta::FromMilliseconds(kInitialNotificationCheckDelayMS)); | 61 base::TimeDelta::FromMilliseconds(kInitialNotificationCheckDelayMS)); |
| 40 } | 62 } |
| 41 | 63 |
| 42 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { | 64 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { |
| 43 } | 65 } |
| 44 | 66 |
| 45 void NetworkChangeNotifierChromeos::Init() { | 67 void NetworkChangeNotifierChromeos::Init() { |
| 46 chromeos::NetworkLibrary* network_library = | 68 chromeos::NetworkLibrary* network_library = |
| 47 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 69 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 48 network_library->AddNetworkManagerObserver(this); | 70 network_library->AddNetworkManagerObserver(this); |
| 49 | 71 |
| 50 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 72 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 51 | 73 |
| 74 dns_config_service_.reset(new DnsConfigServiceChromeos()); | |
| 75 dns_config_service_->WatchConfig( | |
| 76 base::Bind(NetworkChangeNotifier::SetDnsConfig)); | |
| 77 | |
| 52 UpdateNetworkState(network_library); | 78 UpdateNetworkState(network_library); |
| 53 } | 79 } |
| 54 | 80 |
| 55 void NetworkChangeNotifierChromeos::Shutdown() { | 81 void NetworkChangeNotifierChromeos::Shutdown() { |
| 56 weak_factory_.InvalidateWeakPtrs(); | 82 weak_factory_.InvalidateWeakPtrs(); |
| 57 | 83 |
| 84 dns_config_service_.reset(); | |
| 85 | |
| 58 if (!chromeos::CrosLibrary::Get()) | 86 if (!chromeos::CrosLibrary::Get()) |
| 59 return; | 87 return; |
| 60 | 88 |
| 61 chromeos::NetworkLibrary* lib = | 89 chromeos::NetworkLibrary* lib = |
| 62 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 90 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 63 lib->RemoveNetworkManagerObserver(this); | 91 lib->RemoveNetworkManagerObserver(this); |
| 64 lib->RemoveObserverForAllNetworks(this); | 92 lib->RemoveObserverForAllNetworks(this); |
| 65 | 93 |
| 66 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 94 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
| 67 } | 95 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 chromeos::NetworkLibrary* lib) { | 133 chromeos::NetworkLibrary* lib) { |
| 106 const chromeos::Network* network = lib->active_network(); | 134 const chromeos::Network* network = lib->active_network(); |
| 107 | 135 |
| 108 if (network) { | 136 if (network) { |
| 109 VLOG(1) << "UpdateNetworkState: " << network->name() | 137 VLOG(1) << "UpdateNetworkState: " << network->name() |
| 110 << ", type= " << network->type() | 138 << ", type= " << network->type() |
| 111 << ", device= " << network->device_path() | 139 << ", device= " << network->device_path() |
| 112 << ", state= " << network->state(); | 140 << ", state= " << network->state(); |
| 113 } | 141 } |
| 114 | 142 |
| 143 dns_config_service_->OnNetworkChange(); | |
|
zel
2012/09/04 17:16:11
This will fire way too often for what you are tryi
szym
2012/09/04 17:29:31
How often does this fire?
If I correctly understa
zel
2012/09/05 19:26:59
For an active network this will fire when any of i
szym
2012/09/05 19:48:29
That is indeed a bit too often, but note that this
| |
| 144 | |
| 115 // Check if active network was added, removed or changed. | 145 // Check if active network was added, removed or changed. |
| 116 if ((!network && has_active_network_) || | 146 if ((!network && has_active_network_) || |
| 117 (network && (!has_active_network_ || | 147 (network && (!has_active_network_ || |
| 118 network->service_path() != service_path_ || | 148 network->service_path() != service_path_ || |
| 119 network->ip_address() != ip_address_))) { | 149 network->ip_address() != ip_address_))) { |
| 120 if (has_active_network_) | 150 if (has_active_network_) |
| 121 lib->RemoveObserverForAllNetworks(this); | 151 lib->RemoveObserverForAllNetworks(this); |
| 122 if (!network) { | 152 if (!network) { |
| 123 has_active_network_ = false; | 153 has_active_network_ = false; |
| 124 service_path_.clear(); | 154 service_path_.clear(); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 } | 291 } |
| 262 case chromeos::TYPE_BLUETOOTH: | 292 case chromeos::TYPE_BLUETOOTH: |
| 263 case chromeos::TYPE_VPN: | 293 case chromeos::TYPE_VPN: |
| 264 case chromeos::TYPE_UNKNOWN: | 294 case chromeos::TYPE_UNKNOWN: |
| 265 break; | 295 break; |
| 266 } | 296 } |
| 267 return net::NetworkChangeNotifier::CONNECTION_UNKNOWN; | 297 return net::NetworkChangeNotifier::CONNECTION_UNKNOWN; |
| 268 } | 298 } |
| 269 | 299 |
| 270 } // namespace chromeos | 300 } // namespace chromeos |
| OLD | NEW |