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 "base/string_util.h" |
9 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
10 #include "chromeos/network/network_change_notifier_chromeos.h" | 11 #include "chromeos/network/network_change_notifier_chromeos.h" |
11 #include "chromeos/network/network_state.h" | 12 #include "chromeos/network/network_state.h" |
12 #include "chromeos/network/network_state_handler.h" | 13 #include "chromeos/network/network_state_handler.h" |
13 #include "net/base/network_change_notifier.h" | 14 #include "net/base/network_change_notifier.h" |
14 #include "net/dns/dns_config_service_posix.h" | 15 #include "net/dns/dns_config_service_posix.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 17 |
17 namespace chromeos { | 18 namespace chromeos { |
18 | 19 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 105 } |
105 | 106 |
106 void NetworkChangeNotifierChromeos::UpdateState( | 107 void NetworkChangeNotifierChromeos::UpdateState( |
107 const chromeos::NetworkState* default_network, | 108 const chromeos::NetworkState* default_network, |
108 bool* connection_type_changed, | 109 bool* connection_type_changed, |
109 bool* ip_address_changed, | 110 bool* ip_address_changed, |
110 bool* dns_changed) { | 111 bool* dns_changed) { |
111 *connection_type_changed = false; | 112 *connection_type_changed = false; |
112 *ip_address_changed = false; | 113 *ip_address_changed = false; |
113 *dns_changed = false; | 114 *dns_changed = false; |
114 // TODO(gauravsh): DNS changes will be detected once ip config | |
115 // support is hooked into NetworkStateHandler. For now, | |
116 // we report a DNS change on changes to the default network (including | |
117 // loss). | |
118 if (!default_network || !default_network->IsConnectedState()) { | 115 if (!default_network || !default_network->IsConnectedState()) { |
119 // If we lost a default network, we must update our state and notify | 116 // If we lost a default network, we must update our state and notify |
120 // observers, otherwise we have nothing do. (Under normal circumstances, | 117 // observers, otherwise we have nothing to do. (Under normal circumstances, |
121 // we should never get duplicate no default network notifications). | 118 // we should never get duplicate no default network notifications). |
122 if (connection_type_ != CONNECTION_NONE) { | 119 if (connection_type_ != CONNECTION_NONE) { |
| 120 VLOG(1) << "Lost default network!"; |
123 *ip_address_changed = true; | 121 *ip_address_changed = true; |
124 *dns_changed = true; | 122 *dns_changed = true; |
125 *connection_type_changed = true; | 123 *connection_type_changed = true; |
126 connection_type_ = CONNECTION_NONE; | 124 connection_type_ = CONNECTION_NONE; |
127 service_path_.clear(); | 125 service_path_.clear(); |
128 ip_address_.clear(); | 126 ip_address_.clear(); |
| 127 dns_servers_.clear(); |
129 } | 128 } |
130 return; | 129 return; |
131 } | 130 } |
132 | 131 |
133 // We do have a default network and it is connected. | 132 // We do have a default network and it is connected. |
134 net::NetworkChangeNotifier::ConnectionType new_connection_type = | 133 net::NetworkChangeNotifier::ConnectionType new_connection_type = |
135 ConnectionTypeFromShill(default_network->type(), | 134 ConnectionTypeFromShill(default_network->type(), |
136 default_network->technology()); | 135 default_network->technology()); |
137 if (new_connection_type != connection_type_) { | 136 if (new_connection_type != connection_type_) { |
138 VLOG(1) << "Connection type changed from " << connection_type_ << " -> " | 137 VLOG(1) << "Connection type changed from " << connection_type_ << " -> " |
139 << new_connection_type; | 138 << new_connection_type; |
140 *connection_type_changed = true; | 139 *connection_type_changed = true; |
| 140 } |
| 141 if (default_network->path() != service_path_) { |
| 142 VLOG(1) << "Service path changed from " << service_path_ << " -> " |
| 143 << default_network->path(); |
| 144 // If we had a default network service change, network resources |
| 145 // must always be invalidated. |
| 146 *ip_address_changed = true; |
141 *dns_changed = true; | 147 *dns_changed = true; |
142 } | 148 } |
143 if (default_network->path() != service_path_ || | 149 if (default_network->ip_address() != ip_address_) { |
144 default_network->ip_address() != ip_address_) { | |
145 VLOG(1) << "Service path changed from " << service_path_ << " -> " | |
146 << default_network->path(); | |
147 VLOG(1) << "IP Address changed from " << ip_address_ << " -> " | 150 VLOG(1) << "IP Address changed from " << ip_address_ << " -> " |
148 << default_network->ip_address(); | 151 << default_network->ip_address(); |
149 *ip_address_changed = true; | 152 *ip_address_changed = true; |
| 153 } |
| 154 if (default_network->dns_servers() != dns_servers_) { |
| 155 VLOG(1) << "DNS servers changed.\n" |
| 156 << "Old DNS servers were: " |
| 157 << JoinString(dns_servers_, ",") << "\n" |
| 158 << "New DNS servers are: " |
| 159 << JoinString(default_network->dns_servers(), ","); |
150 *dns_changed = true; | 160 *dns_changed = true; |
151 } | 161 } |
| 162 |
152 connection_type_ = new_connection_type; | 163 connection_type_ = new_connection_type; |
153 service_path_ = default_network->path(); | 164 service_path_ = default_network->path(); |
154 ip_address_ = default_network->ip_address(); | 165 ip_address_ = default_network->ip_address(); |
| 166 dns_servers_ = default_network->dns_servers(); |
155 } | 167 } |
156 | 168 |
157 // static | 169 // static |
158 net::NetworkChangeNotifier::ConnectionType | 170 net::NetworkChangeNotifier::ConnectionType |
159 NetworkChangeNotifierChromeos::ConnectionTypeFromShill( | 171 NetworkChangeNotifierChromeos::ConnectionTypeFromShill( |
160 const std::string& type, const std::string& technology) { | 172 const std::string& type, const std::string& technology) { |
161 if (type == flimflam::kTypeEthernet) | 173 if (type == flimflam::kTypeEthernet) |
162 return CONNECTION_ETHERNET; | 174 return CONNECTION_ETHERNET; |
163 else if (type == flimflam::kTypeWifi) | 175 else if (type == flimflam::kTypeWifi) |
164 return CONNECTION_WIFI; | 176 return CONNECTION_WIFI; |
(...skipping 27 matching lines...) Expand all Loading... |
192 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); | 204 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); |
193 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); | 205 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); |
194 params.connection_type_offline_delay_ = | 206 params.connection_type_offline_delay_ = |
195 base::TimeDelta::FromMilliseconds(500); | 207 base::TimeDelta::FromMilliseconds(500); |
196 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); | 208 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); |
197 return params; | 209 return params; |
198 } | 210 } |
199 | 211 |
200 } // namespace chromeos | 212 } // namespace chromeos |
201 | 213 |
OLD | NEW |