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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "chromeos/dbus/dbus_thread_manager.h" |
9 #include "chromeos/network/network_change_notifier_chromeos.h" | 10 #include "chromeos/network/network_change_notifier_chromeos.h" |
10 #include "chromeos/network/network_state.h" | 11 #include "chromeos/network/network_state.h" |
11 #include "chromeos/network/network_state_handler.h" | 12 #include "chromeos/network/network_state_handler.h" |
12 #include "net/base/network_change_notifier.h" | 13 #include "net/base/network_change_notifier.h" |
13 #include "net/dns/dns_config_service_posix.h" | 14 #include "net/dns/dns_config_service_posix.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 16 |
16 namespace chromeos { | 17 namespace chromeos { |
17 | 18 |
18 // DNS config services on Chrome OS are signalled by the network state handler | 19 // DNS config services on Chrome OS are signalled by the network state handler |
(...skipping 29 matching lines...) Expand all Loading... |
48 | 49 |
49 NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos() | 50 NetworkChangeNotifierChromeos::NetworkChangeNotifierChromeos() |
50 : NetworkChangeNotifier(NetworkChangeCalculatorParamsChromeos()), | 51 : NetworkChangeNotifier(NetworkChangeCalculatorParamsChromeos()), |
51 connection_type_(CONNECTION_NONE) { | 52 connection_type_(CONNECTION_NONE) { |
52 } | 53 } |
53 | 54 |
54 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { | 55 NetworkChangeNotifierChromeos::~NetworkChangeNotifierChromeos() { |
55 } | 56 } |
56 | 57 |
57 void NetworkChangeNotifierChromeos::Initialize() { | 58 void NetworkChangeNotifierChromeos::Initialize() { |
| 59 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
58 NetworkStateHandler::Get()->AddObserver(this); | 60 NetworkStateHandler::Get()->AddObserver(this); |
59 | 61 |
60 dns_config_service_.reset(new DnsConfigService()); | 62 dns_config_service_.reset(new DnsConfigService()); |
61 dns_config_service_->WatchConfig( | 63 dns_config_service_->WatchConfig( |
62 base::Bind(net::NetworkChangeNotifier::SetDnsConfig)); | 64 base::Bind(net::NetworkChangeNotifier::SetDnsConfig)); |
63 | 65 |
64 // Update initial connection state. | 66 // Update initial connection state. |
65 DefaultNetworkChanged(NetworkStateHandler::Get()->DefaultNetwork()); | 67 DefaultNetworkChanged(NetworkStateHandler::Get()->DefaultNetwork()); |
66 } | 68 } |
67 | 69 |
68 void NetworkChangeNotifierChromeos::Shutdown() { | 70 void NetworkChangeNotifierChromeos::Shutdown() { |
69 dns_config_service_.reset(); | 71 dns_config_service_.reset(); |
70 if (NetworkStateHandler::Get()) | 72 if (NetworkStateHandler::Get()) |
71 NetworkStateHandler::Get()->RemoveObserver(this); | 73 NetworkStateHandler::Get()->RemoveObserver(this); |
| 74 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
72 } | 75 } |
73 | 76 |
74 net::NetworkChangeNotifier::ConnectionType | 77 net::NetworkChangeNotifier::ConnectionType |
75 NetworkChangeNotifierChromeos::GetCurrentConnectionType() const { | 78 NetworkChangeNotifierChromeos::GetCurrentConnectionType() const { |
76 return connection_type_; | 79 return connection_type_; |
77 } | 80 } |
78 | 81 |
| 82 void NetworkChangeNotifierChromeos::SystemResumed( |
| 83 const base::TimeDelta& sleep_duration) { |
| 84 // Force invalidation of network resources on resume. |
| 85 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); |
| 86 } |
| 87 |
| 88 |
79 void NetworkChangeNotifierChromeos::DefaultNetworkChanged( | 89 void NetworkChangeNotifierChromeos::DefaultNetworkChanged( |
80 const chromeos::NetworkState* default_network) { | 90 const chromeos::NetworkState* default_network) { |
81 bool connection_type_changed = false; | 91 bool connection_type_changed = false; |
82 bool ip_address_changed = false; | 92 bool ip_address_changed = false; |
83 bool dns_changed = false; | 93 bool dns_changed = false; |
84 | 94 |
85 UpdateState(default_network, &connection_type_changed, | 95 UpdateState(default_network, &connection_type_changed, |
86 &ip_address_changed, &dns_changed); | 96 &ip_address_changed, &dns_changed); |
87 | 97 |
88 if (connection_type_changed) | 98 if (connection_type_changed) |
89 NetworkChangeNotifierChromeos:: NotifyObserversOfConnectionTypeChange(); | 99 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); |
90 if (ip_address_changed) | 100 if (ip_address_changed) |
91 NetworkChangeNotifierChromeos::NotifyObserversOfIPAddressChange(); | 101 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); |
92 if (dns_changed) | 102 if (dns_changed) |
93 dns_config_service_->OnNetworkChange(); | 103 dns_config_service_->OnNetworkChange(); |
94 } | 104 } |
95 | 105 |
96 void NetworkChangeNotifierChromeos::UpdateState( | 106 void NetworkChangeNotifierChromeos::UpdateState( |
97 const chromeos::NetworkState* default_network, | 107 const chromeos::NetworkState* default_network, |
98 bool* connection_type_changed, | 108 bool* connection_type_changed, |
99 bool* ip_address_changed, | 109 bool* ip_address_changed, |
100 bool* dns_changed) { | 110 bool* dns_changed) { |
101 *connection_type_changed = false; | 111 *connection_type_changed = false; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); | 192 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); |
183 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); | 193 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); |
184 params.connection_type_offline_delay_ = | 194 params.connection_type_offline_delay_ = |
185 base::TimeDelta::FromMilliseconds(500); | 195 base::TimeDelta::FromMilliseconds(500); |
186 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); | 196 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); |
187 return params; | 197 return params; |
188 } | 198 } |
189 | 199 |
190 } // namespace chromeos | 200 } // namespace chromeos |
191 | 201 |
OLD | NEW |