Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chromeos/network/network_state_handler.cc

Issue 289383004: Merge FavoriteState into NetworkState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Elim UpdateManagerProperties, feedback Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chromeos/network/network_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chromeos/network/device_state.h" 17 #include "chromeos/network/device_state.h"
18 #include "chromeos/network/favorite_state.h"
19 #include "chromeos/network/managed_state.h" 18 #include "chromeos/network/managed_state.h"
20 #include "chromeos/network/network_event_log.h" 19 #include "chromeos/network/network_event_log.h"
21 #include "chromeos/network/network_state.h" 20 #include "chromeos/network/network_state.h"
22 #include "chromeos/network/network_state_handler_observer.h" 21 #include "chromeos/network/network_state_handler_observer.h"
23 #include "chromeos/network/shill_property_handler.h" 22 #include "chromeos/network/shill_property_handler.h"
24 #include "third_party/cros_system_api/dbus/service_constants.h" 23 #include "third_party/cros_system_api/dbus/service_constants.h"
25 24
26 namespace chromeos { 25 namespace chromeos {
27 26
28 namespace { 27 namespace {
29 28
30 bool ConnectionStateChanged(NetworkState* network, 29 bool ConnectionStateChanged(NetworkState* network,
31 const std::string& prev_connection_state) { 30 const std::string& prev_connection_state) {
32 return (network->connection_state() != prev_connection_state) && 31 return (network->connection_state() != prev_connection_state) &&
33 (network->connection_state() != shill::kStateIdle || 32 (network->connection_state() != shill::kStateIdle ||
34 !prev_connection_state.empty()); 33 !prev_connection_state.empty());
35 } 34 }
36 35
37 std::string GetManagedStateLogType(const ManagedState* state) { 36 std::string GetManagedStateLogType(const ManagedState* state) {
38 switch (state->managed_type()) { 37 switch (state->managed_type()) {
39 case ManagedState::MANAGED_TYPE_NETWORK: 38 case ManagedState::MANAGED_TYPE_NETWORK:
40 return "Network"; 39 return "Network";
41 case ManagedState::MANAGED_TYPE_FAVORITE:
42 return "Favorite";
43 case ManagedState::MANAGED_TYPE_DEVICE: 40 case ManagedState::MANAGED_TYPE_DEVICE:
44 return "Device"; 41 return "Device";
45 } 42 }
46 NOTREACHED(); 43 NOTREACHED();
47 return ""; 44 return "";
48 } 45 }
49 46
50 std::string GetManagedStateLogName(const ManagedState* state) { 47 std::string GetLogName(const ManagedState* state) {
51 if (!state) 48 if (!state)
52 return "None"; 49 return "None";
53 return base::StringPrintf("%s (%s)", state->name().c_str(), 50 return base::StringPrintf("%s (%s)", state->name().c_str(),
54 state->path().c_str()); 51 state->path().c_str());
55 } 52 }
56 53
57 } // namespace 54 } // namespace
58 55
59 const char NetworkStateHandler::kDefaultCheckPortalList[] = 56 const char NetworkStateHandler::kDefaultCheckPortalList[] =
60 "ethernet,wifi,cellular"; 57 "ethernet,wifi,cellular";
61 58
62 NetworkStateHandler::NetworkStateHandler() { 59 NetworkStateHandler::NetworkStateHandler() {
63 } 60 }
64 61
65 NetworkStateHandler::~NetworkStateHandler() { 62 NetworkStateHandler::~NetworkStateHandler() {
66 STLDeleteContainerPointers(network_list_.begin(), network_list_.end()); 63 STLDeleteContainerPointers(network_list_.begin(), network_list_.end());
67 STLDeleteContainerPointers(favorite_list_.begin(), favorite_list_.end());
68 STLDeleteContainerPointers(device_list_.begin(), device_list_.end()); 64 STLDeleteContainerPointers(device_list_.begin(), device_list_.end());
69 } 65 }
70 66
71 void NetworkStateHandler::InitShillPropertyHandler() { 67 void NetworkStateHandler::InitShillPropertyHandler() {
72 shill_property_handler_.reset(new internal::ShillPropertyHandler(this)); 68 shill_property_handler_.reset(new internal::ShillPropertyHandler(this));
73 shill_property_handler_->Init(); 69 shill_property_handler_->Init();
74 } 70 }
75 71
76 // static 72 // static
77 NetworkStateHandler* NetworkStateHandler::InitializeForTest() { 73 NetworkStateHandler* NetworkStateHandler::InitializeForTest() {
(...skipping 15 matching lines...) Expand all
93 void NetworkStateHandler::RemoveObserver( 89 void NetworkStateHandler::RemoveObserver(
94 NetworkStateHandlerObserver* observer, 90 NetworkStateHandlerObserver* observer,
95 const tracked_objects::Location& from_here) { 91 const tracked_objects::Location& from_here) {
96 observers_.RemoveObserver(observer); 92 observers_.RemoveObserver(observer);
97 network_event_log::internal::AddEntry( 93 network_event_log::internal::AddEntry(
98 from_here.file_name(), from_here.line_number(), 94 from_here.file_name(), from_here.line_number(),
99 network_event_log::LOG_LEVEL_DEBUG, 95 network_event_log::LOG_LEVEL_DEBUG,
100 "NetworkStateHandler::RemoveObserver", ""); 96 "NetworkStateHandler::RemoveObserver", "");
101 } 97 }
102 98
103 void NetworkStateHandler::UpdateManagerProperties() {
104 NET_LOG_USER("UpdateManagerProperties", "");
105 shill_property_handler_->UpdateManagerProperties();
106 }
107
108 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( 99 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState(
109 const NetworkTypePattern& type) const { 100 const NetworkTypePattern& type) const {
110 std::string technology = GetTechnologyForType(type); 101 std::string technology = GetTechnologyForType(type);
111 TechnologyState state; 102 TechnologyState state;
112 if (shill_property_handler_->IsTechnologyEnabled(technology)) 103 if (shill_property_handler_->IsTechnologyEnabled(technology))
113 state = TECHNOLOGY_ENABLED; 104 state = TECHNOLOGY_ENABLED;
114 else if (shill_property_handler_->IsTechnologyEnabling(technology)) 105 else if (shill_property_handler_->IsTechnologyEnabling(technology))
115 state = TECHNOLOGY_ENABLING; 106 state = TECHNOLOGY_ENABLING;
116 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) 107 else if (shill_property_handler_->IsTechnologyUninitialized(technology))
117 state = TECHNOLOGY_UNINITIALIZED; 108 state = TECHNOLOGY_UNINITIALIZED;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return NULL; 174 return NULL;
184 return network; 175 return network;
185 } 176 }
186 177
187 const NetworkState* NetworkStateHandler::DefaultNetwork() const { 178 const NetworkState* NetworkStateHandler::DefaultNetwork() const {
188 if (default_network_path_.empty()) 179 if (default_network_path_.empty())
189 return NULL; 180 return NULL;
190 return GetNetworkState(default_network_path_); 181 return GetNetworkState(default_network_path_);
191 } 182 }
192 183
193 const FavoriteState* NetworkStateHandler::DefaultFavoriteNetwork() const {
194 const NetworkState* default_network = DefaultNetwork();
195 if (!default_network)
196 return NULL;
197 const FavoriteState* default_favorite = GetFavoriteStateFromServicePath(
198 default_network->path(), true /* configured_only */);
199 DCHECK(default_network->type() != shill::kTypeWifi || default_favorite)
200 << "No favorite for: " << default_network->path();
201 DCHECK(!default_favorite || default_favorite->update_received())
202 << "No update received for: " << default_network->path();
203 return default_favorite;
204 }
205
206 const NetworkState* NetworkStateHandler::ConnectedNetworkByType( 184 const NetworkState* NetworkStateHandler::ConnectedNetworkByType(
207 const NetworkTypePattern& type) const { 185 const NetworkTypePattern& type) const {
208 for (ManagedStateList::const_iterator iter = network_list_.begin(); 186 for (ManagedStateList::const_iterator iter = network_list_.begin();
209 iter != network_list_.end(); ++iter) { 187 iter != network_list_.end(); ++iter) {
210 const NetworkState* network = (*iter)->AsNetworkState(); 188 const NetworkState* network = (*iter)->AsNetworkState();
211 DCHECK(network); 189 DCHECK(network);
212 if (!network->update_received()) 190 if (!network->update_received())
213 continue; 191 continue;
214 if (!network->IsConnectedState()) 192 if (!network->visible() || !network->IsConnectedState())
215 break; // Connected networks are listed first. 193 break; // Connected networks are listed first.
216 if (network->Matches(type)) 194 if (network->Matches(type))
217 return network; 195 return network;
218 } 196 }
219 return NULL; 197 return NULL;
220 } 198 }
221 199
222 const NetworkState* NetworkStateHandler::ConnectingNetworkByType( 200 const NetworkState* NetworkStateHandler::ConnectingNetworkByType(
223 const NetworkTypePattern& type) const { 201 const NetworkTypePattern& type) const {
224 for (ManagedStateList::const_iterator iter = network_list_.begin(); 202 for (ManagedStateList::const_iterator iter = network_list_.begin();
225 iter != network_list_.end(); ++iter) { 203 iter != network_list_.end(); ++iter) {
226 const NetworkState* network = (*iter)->AsNetworkState(); 204 const NetworkState* network = (*iter)->AsNetworkState();
227 DCHECK(network); 205 DCHECK(network);
228 if (!network->update_received() || network->IsConnectedState()) 206 if (!network->update_received() || network->IsConnectedState())
229 continue; 207 continue;
230 if (!network->IsConnectingState()) 208 if (!network->visible() || !network->IsConnectingState())
231 break; // Connected and connecting networks are listed first. 209 break; // Connected and connecting networks are listed first.
232 if (network->Matches(type)) 210 if (network->Matches(type))
233 return network; 211 return network;
234 } 212 }
235 return NULL; 213 return NULL;
236 } 214 }
237 215
238 const NetworkState* NetworkStateHandler::FirstNetworkByType( 216 const NetworkState* NetworkStateHandler::FirstNetworkByType(
239 const NetworkTypePattern& type) const { 217 const NetworkTypePattern& type) const {
240 for (ManagedStateList::const_iterator iter = network_list_.begin(); 218 for (ManagedStateList::const_iterator iter = network_list_.begin();
(...skipping 14 matching lines...) Expand all
255 const NetworkState* network = ConnectedNetworkByType(type); 233 const NetworkState* network = ConnectedNetworkByType(type);
256 if (network) 234 if (network)
257 device = GetDeviceState(network->device_path()); 235 device = GetDeviceState(network->device_path());
258 else 236 else
259 device = GetDeviceStateByType(type); 237 device = GetDeviceStateByType(type);
260 if (!device) 238 if (!device)
261 return std::string(); 239 return std::string();
262 return network_util::FormattedMacAddress(device->mac_address()); 240 return network_util::FormattedMacAddress(device->mac_address());
263 } 241 }
264 242
265 void NetworkStateHandler::GetNetworkList(NetworkStateList* list) const { 243 void NetworkStateHandler::GetVisibleNetworkListByType(
266 GetNetworkListByType(NetworkTypePattern::Default(), list); 244 const NetworkTypePattern& type,
245 NetworkStateList* list) const {
246 GetNetworkListByType(type,
247 false /* configured_only */,
248 true /* visible_only */,
249 0 /* no limit */,
250 list);
251 }
252
253 void NetworkStateHandler::GetVisibleNetworkList(NetworkStateList* list) const {
254 GetVisibleNetworkListByType(NetworkTypePattern::Default(), list);
267 } 255 }
268 256
269 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type, 257 void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type,
258 bool configured_only,
259 bool visible_only,
260 int limit,
270 NetworkStateList* list) const { 261 NetworkStateList* list) const {
271 DCHECK(list); 262 DCHECK(list);
272 list->clear(); 263 list->clear();
264 int count = 0;
273 for (ManagedStateList::const_iterator iter = network_list_.begin(); 265 for (ManagedStateList::const_iterator iter = network_list_.begin();
274 iter != network_list_.end(); ++iter) { 266 iter != network_list_.end(); ++iter) {
275 const NetworkState* network = (*iter)->AsNetworkState(); 267 const NetworkState* network = (*iter)->AsNetworkState();
276 DCHECK(network); 268 DCHECK(network);
277 if (network->update_received() && network->Matches(type)) 269 if (!network->update_received() || !network->Matches(type))
278 list->push_back(network); 270 continue;
271 if (configured_only && !network->IsInProfile())
272 continue;
273 if (visible_only && !network->visible())
274 continue;
275 list->push_back(network);
276 if (limit > 0 && ++count >= limit)
277 break;
279 } 278 }
280 } 279 }
281 280
281 const NetworkState* NetworkStateHandler::GetNetworkStateFromServicePath(
282 const std::string& service_path,
283 bool configured_only) const {
284 ManagedState* managed =
285 GetModifiableManagedState(&network_list_, service_path);
286 if (!managed)
287 return NULL;
288 const NetworkState* network = managed->AsNetworkState();
289 DCHECK(network);
290 if (!network->update_received() ||
291 (configured_only && !network->IsInProfile())) {
292 return NULL;
293 }
294 return network;
295 }
296
297 const NetworkState* NetworkStateHandler::GetNetworkStateFromGuid(
298 const std::string& guid) const {
299 DCHECK(!guid.empty());
300 for (ManagedStateList::const_iterator iter = network_list_.begin();
301 iter != network_list_.end(); ++iter) {
302 const NetworkState* network = (*iter)->AsNetworkState();
303 if (network->guid() == guid)
304 return network;
305 }
306 return NULL;
307 }
308
282 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { 309 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const {
283 GetDeviceListByType(NetworkTypePattern::Default(), list); 310 GetDeviceListByType(NetworkTypePattern::Default(), list);
284 } 311 }
285 312
286 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type, 313 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type,
287 DeviceStateList* list) const { 314 DeviceStateList* list) const {
288 DCHECK(list); 315 DCHECK(list);
289 list->clear(); 316 list->clear();
290 for (ManagedStateList::const_iterator iter = device_list_.begin(); 317 for (ManagedStateList::const_iterator iter = device_list_.begin();
291 iter != device_list_.end(); ++iter) { 318 iter != device_list_.end(); ++iter) {
292 const DeviceState* device = (*iter)->AsDeviceState(); 319 const DeviceState* device = (*iter)->AsDeviceState();
293 DCHECK(device); 320 DCHECK(device);
294 if (device->update_received() && device->Matches(type)) 321 if (device->update_received() && device->Matches(type))
295 list->push_back(device); 322 list->push_back(device);
296 } 323 }
297 } 324 }
298 325
299 void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const {
300 GetFavoriteListByType(NetworkTypePattern::Default(),
301 true /* configured_only */,
302 false /* visible_only */,
303 0 /* no limit */,
304 list);
305 }
306
307 void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type,
308 bool configured_only,
309 bool visible_only,
310 int limit,
311 FavoriteStateList* list) const {
312 DCHECK(list);
313 std::set<std::string> visible_networks;
314 if (visible_only) {
315 // Prepare a set of visible network service paths for fast lookup.
316 for (ManagedStateList::const_iterator iter = network_list_.begin();
317 iter != network_list_.end(); ++iter) {
318 visible_networks.insert((*iter)->path());
319 }
320 }
321 FavoriteStateList result;
322 list->clear();
323 int count = 0;
324 for (ManagedStateList::const_iterator iter = favorite_list_.begin();
325 iter != favorite_list_.end(); ++iter) {
326 const FavoriteState* favorite = (*iter)->AsFavoriteState();
327 DCHECK(favorite);
328 if (!favorite->update_received() || !favorite->Matches(type))
329 continue;
330 if (configured_only && !favorite->IsInProfile())
331 continue;
332 if (visible_only && !ContainsKey(visible_networks, favorite->path()))
333 continue;
334 list->push_back(favorite);
335 if (limit > 0 && ++count >= limit)
336 break;
337 }
338 }
339
340 const FavoriteState* NetworkStateHandler::GetFavoriteStateFromServicePath(
341 const std::string& service_path,
342 bool configured_only) const {
343 ManagedState* managed =
344 GetModifiableManagedState(&favorite_list_, service_path);
345 if (!managed)
346 return NULL;
347 const FavoriteState* favorite = managed->AsFavoriteState();
348 DCHECK(favorite);
349 if (!favorite->update_received() ||
350 (configured_only && !favorite->IsInProfile())) {
351 return NULL;
352 }
353 return favorite;
354 }
355
356 const FavoriteState* NetworkStateHandler::GetFavoriteStateFromGuid(
357 const std::string& guid) const {
358 DCHECK(!guid.empty());
359 for (ManagedStateList::const_iterator iter = favorite_list_.begin();
360 iter != favorite_list_.end(); ++iter) {
361 const FavoriteState* favorite = (*iter)->AsFavoriteState();
362 if (favorite->guid() == guid)
363 return favorite;
364 }
365 return NULL;
366 }
367
368 void NetworkStateHandler::RequestScan() const { 326 void NetworkStateHandler::RequestScan() const {
369 NET_LOG_USER("RequestScan", ""); 327 NET_LOG_USER("RequestScan", "");
370 shill_property_handler_->RequestScan(); 328 shill_property_handler_->RequestScan();
371 } 329 }
372 330
373 void NetworkStateHandler::WaitForScan(const std::string& type, 331 void NetworkStateHandler::WaitForScan(const std::string& type,
374 const base::Closure& callback) { 332 const base::Closure& callback) {
375 scan_complete_callbacks_[type].push_back(callback); 333 scan_complete_callbacks_[type].push_back(callback);
376 if (!GetScanningByType(NetworkTypePattern::Primitive(type))) 334 if (!GetScanningByType(NetworkTypePattern::Primitive(type)))
377 RequestScan(); 335 RequestScan();
(...skipping 22 matching lines...) Expand all
400 if (network) 358 if (network)
401 network->clear_last_error(); 359 network->clear_last_error();
402 } 360 }
403 361
404 void NetworkStateHandler::SetCheckPortalList( 362 void NetworkStateHandler::SetCheckPortalList(
405 const std::string& check_portal_list) { 363 const std::string& check_portal_list) {
406 NET_LOG_EVENT("SetCheckPortalList", check_portal_list); 364 NET_LOG_EVENT("SetCheckPortalList", check_portal_list);
407 shill_property_handler_->SetCheckPortalList(check_portal_list); 365 shill_property_handler_->SetCheckPortalList(check_portal_list);
408 } 366 }
409 367
410 const FavoriteState* NetworkStateHandler::GetEAPForEthernet( 368 const NetworkState* NetworkStateHandler::GetEAPForEthernet(
411 const std::string& service_path) const { 369 const std::string& service_path) const {
412 const NetworkState* network = GetNetworkState(service_path); 370 const NetworkState* network = GetNetworkState(service_path);
413 if (!network) { 371 if (!network) {
414 NET_LOG_ERROR("GetEAPForEthernet", "Unknown service path " + service_path); 372 NET_LOG_ERROR("GetEAPForEthernet", "Unknown service path " + service_path);
415 return NULL; 373 return NULL;
416 } 374 }
417 if (network->type() != shill::kTypeEthernet) { 375 if (network->type() != shill::kTypeEthernet) {
418 NET_LOG_ERROR("GetEAPForEthernet", "Not of type Ethernet: " + service_path); 376 NET_LOG_ERROR("GetEAPForEthernet", "Not of type Ethernet: " + service_path);
419 return NULL; 377 return NULL;
420 } 378 }
421 if (!network->IsConnectedState()) 379 if (!network->IsConnectedState())
422 return NULL; 380 return NULL;
423 381
424 // The same EAP service is shared for all ethernet services/devices. 382 // The same EAP service is shared for all ethernet services/devices.
425 // However EAP is used/enabled per device and only if the connection was 383 // However EAP is used/enabled per device and only if the connection was
426 // successfully established. 384 // successfully established.
427 const DeviceState* device = GetDeviceState(network->device_path()); 385 const DeviceState* device = GetDeviceState(network->device_path());
428 if (!device) { 386 if (!device) {
429 NET_LOG_ERROR( 387 NET_LOG_ERROR(
430 "GetEAPForEthernet", 388 "GetEAPForEthernet",
431 base::StringPrintf("Unknown device %s of connected ethernet service %s", 389 base::StringPrintf("Unknown device %s of connected ethernet service %s",
432 network->device_path().c_str(), 390 network->device_path().c_str(),
433 service_path.c_str())); 391 service_path.c_str()));
434 return NULL; 392 return NULL;
435 } 393 }
436 if (!device->eap_authentication_completed()) 394 if (!device->eap_authentication_completed())
437 return NULL; 395 return NULL;
438 396
439 FavoriteStateList list; 397 NetworkStateList list;
440 GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap), 398 GetNetworkListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap),
441 true /* configured_only */, 399 true /* configured_only */,
442 false /* visible_only */, 400 false /* visible_only */,
443 1 /* limit */, 401 1 /* limit */,
444 &list); 402 &list);
445 if (list.empty()) { 403 if (list.empty()) {
446 NET_LOG_ERROR("GetEAPForEthernet", 404 NET_LOG_ERROR("GetEAPForEthernet",
447 base::StringPrintf( 405 base::StringPrintf(
448 "Ethernet service %s connected using EAP, but no " 406 "Ethernet service %s connected using EAP, but no "
449 "EAP service found.", 407 "EAP service found.",
450 service_path.c_str())); 408 service_path.c_str()));
451 return NULL; 409 return NULL;
452 } 410 }
453 return list.front(); 411 return list.front();
454 } 412 }
455 413
456 //------------------------------------------------------------------------------ 414 //------------------------------------------------------------------------------
457 // ShillPropertyHandler::Delegate overrides 415 // ShillPropertyHandler::Delegate overrides
458 416
459 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, 417 void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type,
460 const base::ListValue& entries) { 418 const base::ListValue& entries) {
461 ManagedStateList* managed_list = GetManagedList(type); 419 ManagedStateList* managed_list = GetManagedList(type);
462 NET_LOG_DEBUG(base::StringPrintf("UpdateManagedList:%d", type), 420 NET_LOG_DEBUG("UpdateManagedList: " + ManagedState::TypeToString(type),
463 base::StringPrintf("%" PRIuS, entries.GetSize())); 421 base::StringPrintf("%" PRIuS, entries.GetSize()));
464 // Create a map of existing entries. Assumes all entries in |managed_list| 422 // Create a map of existing entries. Assumes all entries in |managed_list|
465 // are unique. 423 // are unique.
466 std::map<std::string, ManagedState*> managed_map; 424 typedef std::map<std::string, ManagedState*> ManagedMap;
425 ManagedMap managed_map;
467 for (ManagedStateList::iterator iter = managed_list->begin(); 426 for (ManagedStateList::iterator iter = managed_list->begin();
468 iter != managed_list->end(); ++iter) { 427 iter != managed_list->end(); ++iter) {
469 ManagedState* managed = *iter; 428 ManagedState* managed = *iter;
470 DCHECK(!ContainsKey(managed_map, managed->path())); 429 DCHECK(!ContainsKey(managed_map, managed->path()));
471 managed_map[managed->path()] = managed; 430 managed_map[managed->path()] = managed;
472 } 431 }
473 // Clear the list (pointers are temporarily owned by managed_map). 432 // Clear the list (pointers are temporarily owned by managed_map).
474 managed_list->clear(); 433 managed_list->clear();
475 // Updates managed_list and request updates for new entries. 434 // Updates managed_list and request updates for new entries.
476 std::set<std::string> list_entries; 435 std::set<std::string> list_entries;
477 for (base::ListValue::const_iterator iter = entries.begin(); 436 for (base::ListValue::const_iterator iter = entries.begin();
478 iter != entries.end(); ++iter) { 437 iter != entries.end(); ++iter) {
479 std::string path; 438 std::string path;
480 (*iter)->GetAsString(&path); 439 (*iter)->GetAsString(&path);
481 if (path.empty() || path == shill::kFlimflamServicePath) { 440 if (path.empty() || path == shill::kFlimflamServicePath) {
482 NET_LOG_ERROR(base::StringPrintf("Bad path in list:%d", type), path); 441 NET_LOG_ERROR(base::StringPrintf("Bad path in list:%d", type), path);
483 continue; 442 continue;
484 } 443 }
485 std::map<std::string, ManagedState*>::iterator found = 444 ManagedMap::iterator found = managed_map.find(path);
486 managed_map.find(path);
487 ManagedState* managed;
488 if (found == managed_map.end()) { 445 if (found == managed_map.end()) {
489 if (list_entries.count(path) != 0) { 446 if (list_entries.count(path) != 0) {
490 NET_LOG_ERROR("Duplicate entry in list", path); 447 NET_LOG_ERROR("Duplicate entry in list", path);
491 continue; 448 continue;
492 } 449 }
493 managed = ManagedState::Create(type, path); 450 ManagedState* managed = ManagedState::Create(type, path);
494 managed_list->push_back(managed); 451 managed_list->push_back(managed);
495 } else { 452 } else {
496 managed = found->second; 453 managed_list->push_back(found->second);
497 managed_list->push_back(managed);
498 managed_map.erase(found); 454 managed_map.erase(found);
499 } 455 }
500 list_entries.insert(path); 456 list_entries.insert(path);
501 } 457 }
502 // Delete any remaining entries in managed_map. 458 // Delete any remaining entries in managed_map.
503 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); 459 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end());
504 } 460 }
505 461
462 void NetworkStateHandler::UpdateVisibleNetworks(
463 const base::ListValue& entries) {
464 NET_LOG_DEBUG(base::StringPrintf("UpdateVisibleNetworks"),
465 base::StringPrintf("%" PRIuS, entries.GetSize()));
466 // Create a map of all networks and clear the visible state.
467 ManagedStateList* network_list =
468 GetManagedList(ManagedState::MANAGED_TYPE_NETWORK);
469 typedef std::map<std::string, NetworkState*> NetworkMap;
470 NetworkMap network_map;
471 for (ManagedStateList::iterator iter = network_list->begin();
472 iter != network_list->end(); ++iter) {
473 NetworkState* network = (*iter)->AsNetworkState();
474 network_map[network->path()] = network;
475 network->set_visible(false);
476 }
477 // Look up each entry and set the associated network to visible.
478 for (base::ListValue::const_iterator iter = entries.begin();
479 iter != entries.end(); ++iter) {
480 std::string path;
481 (*iter)->GetAsString(&path);
482 NetworkMap::iterator found = network_map.find(path);
483 if (found != network_map.end())
484 found->second->set_visible(true);
485 else
486 NET_LOG_DEBUG("Visible network not in list", path);
487 }
488 }
489
506 void NetworkStateHandler::ProfileListChanged() { 490 void NetworkStateHandler::ProfileListChanged() {
507 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties"); 491 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties");
508 for (ManagedStateList::iterator iter = favorite_list_.begin(); 492 for (ManagedStateList::iterator iter = network_list_.begin();
509 iter != favorite_list_.end(); ++iter) { 493 iter != network_list_.end(); ++iter) {
494 NetworkState* network = (*iter)->AsNetworkState();
495 DCHECK(network);
510 shill_property_handler_->RequestProperties( 496 shill_property_handler_->RequestProperties(
511 ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path()); 497 ManagedState::MANAGED_TYPE_NETWORK, network->path());
512 } 498 }
513 } 499 }
514 500
515 void NetworkStateHandler::UpdateManagedStateProperties( 501 void NetworkStateHandler::UpdateManagedStateProperties(
516 ManagedState::ManagedType type, 502 ManagedState::ManagedType type,
517 const std::string& path, 503 const std::string& path,
518 const base::DictionaryValue& properties) { 504 const base::DictionaryValue& properties) {
519 ManagedStateList* managed_list = GetManagedList(type); 505 ManagedStateList* managed_list = GetManagedList(type);
520 ManagedState* managed = GetModifiableManagedState(managed_list, path); 506 ManagedState* managed = GetModifiableManagedState(managed_list, path);
521 if (!managed) { 507 if (!managed) {
522 if (type != ManagedState::MANAGED_TYPE_FAVORITE) { 508 // The network has been removed from the list of networks.
523 // The network has been removed from the list of visible networks. 509 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path);
524 NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path); 510 return;
525 return;
526 }
527 // A Favorite may not have been created yet if it was added later (e.g.
528 // through ConfigureService) since ServiceCompleteList updates are not
529 // emitted. Add and update the state here.
530 managed = ManagedState::Create(type, path);
531 managed_list->push_back(managed);
532 } 511 }
533 managed->set_update_received(); 512 managed->set_update_received();
534 513
535 std::string desc = GetManagedStateLogType(managed) + " Properties Received"; 514 std::string desc = GetManagedStateLogType(managed) + " Properties Received";
536 NET_LOG_DEBUG(desc, GetManagedStateLogName(managed)); 515 NET_LOG_DEBUG(desc, GetLogName(managed));
537 516
538 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 517 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
539 UpdateNetworkStateProperties(managed->AsNetworkState(), properties); 518 UpdateNetworkStateProperties(managed->AsNetworkState(), properties);
540 } else { 519 } else {
541 // Device, Favorite 520 // Device
542 for (base::DictionaryValue::Iterator iter(properties); 521 for (base::DictionaryValue::Iterator iter(properties);
543 !iter.IsAtEnd(); iter.Advance()) { 522 !iter.IsAtEnd(); iter.Advance()) {
544 managed->PropertyChanged(iter.key(), iter.value()); 523 managed->PropertyChanged(iter.key(), iter.value());
545 } 524 }
546 managed->InitialPropertiesReceived(properties); 525 managed->InitialPropertiesReceived(properties);
547 } 526 }
548 UpdateGuid(managed);
549 managed->set_update_requested(false); 527 managed->set_update_requested(false);
550 } 528 }
551 529
552 void NetworkStateHandler::UpdateNetworkStateProperties( 530 void NetworkStateHandler::UpdateNetworkStateProperties(
553 NetworkState* network, 531 NetworkState* network,
554 const base::DictionaryValue& properties) { 532 const base::DictionaryValue& properties) {
555 DCHECK(network); 533 DCHECK(network);
556 bool network_property_updated = false; 534 bool network_property_updated = false;
557 std::string prev_connection_state = network->connection_state(); 535 std::string prev_connection_state = network->connection_state();
558 for (base::DictionaryValue::Iterator iter(properties); 536 for (base::DictionaryValue::Iterator iter(properties);
559 !iter.IsAtEnd(); iter.Advance()) { 537 !iter.IsAtEnd(); iter.Advance()) {
560 if (network->PropertyChanged(iter.key(), iter.value())) 538 if (network->PropertyChanged(iter.key(), iter.value()))
561 network_property_updated = true; 539 network_property_updated = true;
562 } 540 }
563 network_property_updated |= network->InitialPropertiesReceived(properties); 541 network_property_updated |= network->InitialPropertiesReceived(properties);
564 // Notify observers of NetworkState changes. 542 // Notify observers of NetworkState changes.
565 if (network_property_updated || network->update_requested()) { 543 if (network_property_updated || network->update_requested()) {
566 // Signal connection state changed after all properties have been updated. 544 // Signal connection state changed after all properties have been updated.
567 if (ConnectionStateChanged(network, prev_connection_state)) 545 if (ConnectionStateChanged(network, prev_connection_state))
568 OnNetworkConnectionStateChanged(network); 546 OnNetworkConnectionStateChanged(network);
569 NET_LOG_EVENT("NetworkPropertiesUpdated", GetManagedStateLogName(network)); 547 NET_LOG_EVENT("NetworkPropertiesUpdated", GetLogName(network));
570 NotifyNetworkPropertiesUpdated(network); 548 NotifyNetworkPropertiesUpdated(network);
571 } 549 }
550 UpdateGuid(network);
572 } 551 }
573 552
574 void NetworkStateHandler::UpdateNetworkServiceProperty( 553 void NetworkStateHandler::UpdateNetworkServiceProperty(
575 const std::string& service_path, 554 const std::string& service_path,
576 const std::string& key, 555 const std::string& key,
577 const base::Value& value) { 556 const base::Value& value) {
578 // Update any associated FavoriteState.
579 ManagedState* favorite =
580 GetModifiableManagedState(&favorite_list_, service_path);
581 bool changed = false; 557 bool changed = false;
582 if (favorite)
583 changed |= favorite->PropertyChanged(key, value);
584
585 // Update the NetworkState.
586 NetworkState* network = GetModifiableNetworkState(service_path); 558 NetworkState* network = GetModifiableNetworkState(service_path);
587 if (!network) 559 if (!network)
588 return; 560 return;
589 std::string prev_connection_state = network->connection_state(); 561 std::string prev_connection_state = network->connection_state();
590 std::string prev_profile_path = network->profile_path(); 562 std::string prev_profile_path = network->profile_path();
591 changed |= network->PropertyChanged(key, value); 563 changed |= network->PropertyChanged(key, value);
592 if (!changed) 564 if (!changed)
593 return; 565 return;
594 566
595 if (key == shill::kStateProperty) { 567 if (key == shill::kStateProperty) {
(...skipping 28 matching lines...) Expand all
624 } else { 596 } else {
625 log_level = network_event_log::LOG_LEVEL_EVENT; 597 log_level = network_event_log::LOG_LEVEL_EVENT;
626 } 598 }
627 NET_LOG_LEVEL(log_level, log_event, detail); 599 NET_LOG_LEVEL(log_level, log_event, detail);
628 } 600 }
629 } 601 }
630 602
631 // All property updates signal 'NetworkPropertiesUpdated'. 603 // All property updates signal 'NetworkPropertiesUpdated'.
632 NotifyNetworkPropertiesUpdated(network); 604 NotifyNetworkPropertiesUpdated(network);
633 605
634 // If added to a Profile, request a full update so that a FavoriteState 606 // If added to a Profile, request a full update so that a NetworkState
635 // gets created. 607 // gets created.
636 if (prev_profile_path.empty() && !network->profile_path().empty()) 608 if (prev_profile_path.empty() && !network->profile_path().empty())
637 RequestUpdateForNetwork(service_path); 609 RequestUpdateForNetwork(service_path);
638 } 610 }
639 611
640 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, 612 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path,
641 const std::string& key, 613 const std::string& key,
642 const base::Value& value) { 614 const base::Value& value) {
643 DeviceState* device = GetModifiableDeviceState(device_path); 615 DeviceState* device = GetModifiableDeviceState(device_path);
644 if (!device) 616 if (!device)
645 return; 617 return;
646 if (!device->PropertyChanged(key, value)) 618 if (!device->PropertyChanged(key, value))
647 return; 619 return;
648 620
649 std::string detail = device->name() + "." + key; 621 std::string detail = device->name() + "." + key;
650 detail += " = " + network_event_log::ValueAsString(value); 622 detail += " = " + network_event_log::ValueAsString(value);
651 NET_LOG_EVENT("DevicePropertyUpdated", detail); 623 NET_LOG_EVENT("DevicePropertyUpdated", detail);
652 624
653 NotifyDeviceListChanged(); 625 NotifyDeviceListChanged();
654 626
655 if (key == shill::kScanningProperty && device->scanning() == false) 627 if (key == shill::kScanningProperty && device->scanning() == false)
656 ScanCompleted(device->type()); 628 ScanCompleted(device->type());
657 if (key == shill::kEapAuthenticationCompletedProperty) { 629 if (key == shill::kEapAuthenticationCompletedProperty) {
658 // Notify a change for each Ethernet service using this device. 630 // Notify a change for each Ethernet service using this device.
659 NetworkStateList ethernet_services; 631 NetworkStateList ethernet_services;
660 GetNetworkListByType(NetworkTypePattern::Ethernet(), &ethernet_services); 632 GetNetworkListByType(NetworkTypePattern::Ethernet(),
633 false /* configured_only */,
634 false /* visible_only */,
635 0 /* no limit */,
636 &ethernet_services);
661 for (NetworkStateList::const_iterator it = ethernet_services.begin(); 637 for (NetworkStateList::const_iterator it = ethernet_services.begin();
662 it != ethernet_services.end(); ++it) { 638 it != ethernet_services.end(); ++it) {
663 const NetworkState* ethernet_service = *it; 639 const NetworkState* ethernet_service = *it;
664 if (ethernet_service->update_received() || 640 if (ethernet_service->update_received() ||
665 ethernet_service->device_path() != device->path()) { 641 ethernet_service->device_path() != device->path()) {
666 continue; 642 continue;
667 } 643 }
668 RequestUpdateForNetwork(ethernet_service->path()); 644 RequestUpdateForNetwork(ethernet_service->path());
669 } 645 }
670 } 646 }
(...skipping 25 matching lines...) Expand all
696 void NetworkStateHandler::TechnologyListChanged() { 672 void NetworkStateHandler::TechnologyListChanged() {
697 // Eventually we would like to replace Technology state with Device state. 673 // Eventually we would like to replace Technology state with Device state.
698 // For now, treat technology state changes as device list changes. 674 // For now, treat technology state changes as device list changes.
699 NotifyDeviceListChanged(); 675 NotifyDeviceListChanged();
700 } 676 }
701 677
702 void NetworkStateHandler::ManagedStateListChanged( 678 void NetworkStateHandler::ManagedStateListChanged(
703 ManagedState::ManagedType type) { 679 ManagedState::ManagedType type) {
704 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 680 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
705 // Notify observers that the list of networks has changed. 681 // Notify observers that the list of networks has changed.
706 NET_LOG_EVENT("NetworkListChanged", 682 NET_LOG_EVENT("NOTIFY:NetworkListChanged",
707 base::StringPrintf("Size:%" PRIuS, network_list_.size())); 683 base::StringPrintf("Size:%" PRIuS, network_list_.size()));
708 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 684 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
709 NetworkListChanged()); 685 NetworkListChanged());
710 // Update UMA stats. 686 // Update UMA stats.
711 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", network_list_.size()); 687 size_t shared = 0, unshared = 0, visible = 0;
712 } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) { 688 for (ManagedStateList::iterator iter = network_list_.begin();
713 NET_LOG_DEBUG("FavoriteListChanged", 689 iter != network_list_.end(); ++iter) {
714 base::StringPrintf("Size:%" PRIuS, favorite_list_.size())); 690 NetworkState* network = (*iter)->AsNetworkState();
715 // The FavoriteState list only changes when the NetworkState list changes, 691 if (network->visible())
716 // so no need to signal observers here again. 692 ++visible;
717 693 if (network->IsInProfile()) {
718 // Update UMA stats. 694 if (network->IsPrivate())
719 size_t shared = 0, unshared = 0; 695 ++unshared;
720 for (ManagedStateList::iterator iter = favorite_list_.begin(); 696 else
721 iter != favorite_list_.end(); ++iter) { 697 ++shared;
722 FavoriteState* favorite = (*iter)->AsFavoriteState(); 698 }
723 if (!favorite->IsInProfile())
724 continue;
725 if (favorite->IsPrivate())
726 ++unshared;
727 else
728 ++shared;
729 } 699 }
700 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", visible);
730 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared); 701 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared);
731 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared); 702 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared);
732 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 703 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
733 std::string devices; 704 std::string devices;
734 for (ManagedStateList::const_iterator iter = device_list_.begin(); 705 for (ManagedStateList::const_iterator iter = device_list_.begin();
735 iter != device_list_.end(); ++iter) { 706 iter != device_list_.end(); ++iter) {
736 if (iter != device_list_.begin()) 707 if (iter != device_list_.begin())
737 devices += ", "; 708 devices += ", ";
738 devices += (*iter)->name(); 709 devices += (*iter)->name();
739 } 710 }
740 NET_LOG_EVENT("DeviceList:", devices); 711 NET_LOG_EVENT("DeviceList", devices);
741 NotifyDeviceListChanged(); 712 NotifyDeviceListChanged();
742 } else { 713 } else {
743 NOTREACHED(); 714 NOTREACHED();
744 } 715 }
745 } 716 }
746 717
747 void NetworkStateHandler::DefaultNetworkServiceChanged( 718 void NetworkStateHandler::DefaultNetworkServiceChanged(
748 const std::string& service_path) { 719 const std::string& service_path) {
749 // Shill uses '/' for empty service path values; check explicitly for that. 720 // Shill uses '/' for empty service path values; check explicitly for that.
750 const char* kEmptyServicePath = "/"; 721 const char* kEmptyServicePath = "/";
751 if (service_path == kEmptyServicePath) 722 std::string new_service_path =
752 default_network_path_.clear(); 723 (service_path != kEmptyServicePath) ? service_path : "";
753 else 724 if (new_service_path == default_network_path_)
754 default_network_path_ = service_path; 725 return;
726
727 default_network_path_ = service_path;
755 NET_LOG_EVENT("DefaultNetworkServiceChanged:", default_network_path_); 728 NET_LOG_EVENT("DefaultNetworkServiceChanged:", default_network_path_);
756 const NetworkState* network = NULL; 729 const NetworkState* network = NULL;
757 if (!default_network_path_.empty()) { 730 if (!default_network_path_.empty()) {
758 network = GetNetworkState(default_network_path_); 731 network = GetNetworkState(default_network_path_);
759 if (!network) { 732 if (!network) {
760 // If NetworkState is not available yet, do not notify observers here, 733 // If NetworkState is not available yet, do not notify observers here,
761 // they will be notified when the state is received. 734 // they will be notified when the state is received.
762 NET_LOG_DEBUG("Default NetworkState not available", 735 NET_LOG_DEBUG("Default NetworkState not available",
763 default_network_path_); 736 default_network_path_);
764 return; 737 return;
765 } 738 }
766 } 739 }
767 if (network && !network->IsConnectedState()) { 740 if (network && !network->IsConnectedState()) {
768 NET_LOG_ERROR( 741 NET_LOG_ERROR(
769 "DefaultNetwork is not connected: " + network->connection_state(), 742 "DefaultNetwork is not connected: " + network->connection_state(),
770 network->path()); 743 network->path());
771 } 744 }
772 NotifyDefaultNetworkChanged(network); 745 NotifyDefaultNetworkChanged(network);
773 } 746 }
774 747
775 //------------------------------------------------------------------------------ 748 //------------------------------------------------------------------------------
776 // Private methods 749 // Private methods
777 750
778 void NetworkStateHandler::UpdateGuid(ManagedState* managed) { 751 void NetworkStateHandler::UpdateGuid(NetworkState* network) {
779 if (managed->managed_type() == ManagedState::MANAGED_TYPE_FAVORITE) { 752 std::string specifier = network->GetSpecifier();
780 FavoriteState* favorite = managed->AsFavoriteState(); 753 DCHECK(!specifier.empty());
781 std::string specifier = favorite->GetSpecifier(); 754 if (!network->guid().empty()) {
782 if (!favorite->guid().empty()) { 755 // If the network is saved in a profile, remove the entry from the map.
783 // If the favorite is saved in a profile, remove the entry from the map. 756 // Otherwise ensure that the entry matches the specified GUID. (e.g. in
784 // Otherwise ensure that the entry matches the specified GUID. 757 // case a visible network with a specified guid gets configured with a
785 if (favorite->IsInProfile()) 758 // new guid).
786 specifier_guid_map_.erase(specifier); 759 if (network->IsInProfile())
787 else 760 specifier_guid_map_.erase(specifier);
788 specifier_guid_map_[specifier] = favorite->guid(); 761 else
789 return; 762 specifier_guid_map_[specifier] = network->guid();
790 } 763 return;
791 // Ensure that the FavoriteState has a valid GUID.
792 std::string guid;
793 SpecifierGuidMap::iterator iter = specifier_guid_map_.find(specifier);
794 if (iter != specifier_guid_map_.end()) {
795 guid = iter->second;
796 } else {
797 guid = base::GenerateGUID();
798 specifier_guid_map_[specifier] = guid;
799 }
800 favorite->SetGuid(guid);
801 NetworkState* network = GetModifiableNetworkState(favorite->path());
802 if (network)
803 network->SetGuid(guid);
804 } else if (managed->managed_type() == ManagedState::MANAGED_TYPE_NETWORK) {
805 // If the GUID is not set and a corresponding FavoriteState exists, get the
806 // GUID from the FavoriteState. Otherwise it will get set when the Favorite
807 // is created.
808 NetworkState* network = managed->AsNetworkState();
809 if (!network->guid().empty())
810 return;
811 // ShillPropertyHandler will always call UpdateManagedStateProperties with
812 // type FAVORITE before type NETWORK, so there should always be a
813 // corresponding FavoriteState here.
814 FavoriteState* favorite = GetModifiableFavoriteState(network->path());
815 DCHECK(favorite);
816 if (favorite && !favorite->guid().empty())
817 network->SetGuid(favorite->guid());
818 } 764 }
765 // Ensure that the NetworkState has a valid GUID.
766 std::string guid;
767 SpecifierGuidMap::iterator iter = specifier_guid_map_.find(specifier);
768 if (iter != specifier_guid_map_.end()) {
769 guid = iter->second;
770 } else {
771 guid = base::GenerateGUID();
772 specifier_guid_map_[specifier] = guid;
773 }
774 network->SetGuid(guid);
819 } 775 }
820 776
821 void NetworkStateHandler::NotifyDeviceListChanged() { 777 void NetworkStateHandler::NotifyDeviceListChanged() {
822 NET_LOG_DEBUG("NotifyDeviceListChanged", 778 NET_LOG_DEBUG("NOTIFY:DeviceListChanged",
823 base::StringPrintf("Size:%" PRIuS, device_list_.size())); 779 base::StringPrintf("Size:%" PRIuS, device_list_.size()));
824 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 780 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
825 DeviceListChanged()); 781 DeviceListChanged());
826 } 782 }
827 783
828 DeviceState* NetworkStateHandler::GetModifiableDeviceState( 784 DeviceState* NetworkStateHandler::GetModifiableDeviceState(
829 const std::string& device_path) const { 785 const std::string& device_path) const {
830 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path); 786 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path);
831 if (!managed) 787 if (!managed)
832 return NULL; 788 return NULL;
833 return managed->AsDeviceState(); 789 return managed->AsDeviceState();
834 } 790 }
835 791
836 NetworkState* NetworkStateHandler::GetModifiableNetworkState( 792 NetworkState* NetworkStateHandler::GetModifiableNetworkState(
837 const std::string& service_path) const { 793 const std::string& service_path) const {
838 ManagedState* managed = 794 ManagedState* managed =
839 GetModifiableManagedState(&network_list_, service_path); 795 GetModifiableManagedState(&network_list_, service_path);
840 if (!managed) 796 if (!managed)
841 return NULL; 797 return NULL;
842 return managed->AsNetworkState(); 798 return managed->AsNetworkState();
843 } 799 }
844 800
845 FavoriteState* NetworkStateHandler::GetModifiableFavoriteState(
846 const std::string& service_path) const {
847 ManagedState* managed =
848 GetModifiableManagedState(&favorite_list_, service_path);
849 if (!managed)
850 return NULL;
851 return managed->AsFavoriteState();
852 }
853
854 ManagedState* NetworkStateHandler::GetModifiableManagedState( 801 ManagedState* NetworkStateHandler::GetModifiableManagedState(
855 const ManagedStateList* managed_list, 802 const ManagedStateList* managed_list,
856 const std::string& path) const { 803 const std::string& path) const {
857 for (ManagedStateList::const_iterator iter = managed_list->begin(); 804 for (ManagedStateList::const_iterator iter = managed_list->begin();
858 iter != managed_list->end(); ++iter) { 805 iter != managed_list->end(); ++iter) {
859 ManagedState* managed = *iter; 806 ManagedState* managed = *iter;
860 if (managed->path() == path) 807 if (managed->path() == path)
861 return managed; 808 return managed;
862 } 809 }
863 return NULL; 810 return NULL;
864 } 811 }
865 812
866 NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList( 813 NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList(
867 ManagedState::ManagedType type) { 814 ManagedState::ManagedType type) {
868 switch (type) { 815 switch (type) {
869 case ManagedState::MANAGED_TYPE_NETWORK: 816 case ManagedState::MANAGED_TYPE_NETWORK:
870 return &network_list_; 817 return &network_list_;
871 case ManagedState::MANAGED_TYPE_FAVORITE:
872 return &favorite_list_;
873 case ManagedState::MANAGED_TYPE_DEVICE: 818 case ManagedState::MANAGED_TYPE_DEVICE:
874 return &device_list_; 819 return &device_list_;
875 } 820 }
876 NOTREACHED(); 821 NOTREACHED();
877 return NULL; 822 return NULL;
878 } 823 }
879 824
880 void NetworkStateHandler::OnNetworkConnectionStateChanged( 825 void NetworkStateHandler::OnNetworkConnectionStateChanged(
881 NetworkState* network) { 826 NetworkState* network) {
882 DCHECK(network); 827 DCHECK(network);
883 std::string event = "NetworkConnectionStateChanged"; 828 std::string event = "NetworkConnectionStateChanged";
884 if (network->path() == default_network_path_) { 829 if (network->path() == default_network_path_) {
885 event = "Default" + event; 830 event = "Default" + event;
886 if (!network->IsConnectedState()) { 831 if (!network->IsConnectedState()) {
887 NET_LOG_ERROR( 832 NET_LOG_ERROR(
888 "DefaultNetwork is not connected: " + network->connection_state(), 833 "DefaultNetwork is not connected: " + network->connection_state(),
889 network->path()); 834 network->path());
890 } 835 }
891 } 836 }
892 NET_LOG_EVENT(event + ": " + network->connection_state(), 837 NET_LOG_EVENT("NOTIFY:" + event + ": " + network->connection_state(),
893 GetManagedStateLogName(network)); 838 GetLogName(network));
894 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 839 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
895 NetworkConnectionStateChanged(network)); 840 NetworkConnectionStateChanged(network));
896 if (network->path() == default_network_path_) 841 if (network->path() == default_network_path_)
897 NotifyDefaultNetworkChanged(network); 842 NotifyDefaultNetworkChanged(network);
898 } 843 }
899 844
900 void NetworkStateHandler::NotifyDefaultNetworkChanged( 845 void NetworkStateHandler::NotifyDefaultNetworkChanged(
901 const NetworkState* default_network) { 846 const NetworkState* default_network) {
847 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network));
902 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 848 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
903 DefaultNetworkChanged(default_network)); 849 DefaultNetworkChanged(default_network));
904 } 850 }
905 851
906 void NetworkStateHandler::NotifyNetworkPropertiesUpdated( 852 void NetworkStateHandler::NotifyNetworkPropertiesUpdated(
907 const NetworkState* network) { 853 const NetworkState* network) {
854 NET_LOG_DEBUG("NOTIFY:NetworkPropertiesUpdated", GetLogName(network));
908 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 855 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
909 NetworkPropertiesUpdated(network)); 856 NetworkPropertiesUpdated(network));
910 } 857 }
911 858
912 void NetworkStateHandler::ScanCompleted(const std::string& type) { 859 void NetworkStateHandler::ScanCompleted(const std::string& type) {
913 size_t num_callbacks = scan_complete_callbacks_.count(type); 860 size_t num_callbacks = scan_complete_callbacks_.count(type);
914 NET_LOG_EVENT("ScanCompleted", 861 NET_LOG_EVENT("ScanCompleted",
915 base::StringPrintf("%s:%" PRIuS, type.c_str(), num_callbacks)); 862 base::StringPrintf("%s:%" PRIuS, type.c_str(), num_callbacks));
916 if (num_callbacks == 0) 863 if (num_callbacks == 0)
917 return; 864 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 if (type.MatchesType(shill::kTypeBluetooth)) 908 if (type.MatchesType(shill::kTypeBluetooth))
962 technologies.push_back(new std::string(shill::kTypeBluetooth)); 909 technologies.push_back(new std::string(shill::kTypeBluetooth));
963 if (type.MatchesType(shill::kTypeVPN)) 910 if (type.MatchesType(shill::kTypeVPN))
964 technologies.push_back(new std::string(shill::kTypeVPN)); 911 technologies.push_back(new std::string(shill::kTypeVPN));
965 912
966 CHECK_GT(technologies.size(), 0ul); 913 CHECK_GT(technologies.size(), 0ul);
967 return technologies.Pass(); 914 return technologies.Pass();
968 } 915 }
969 916
970 } // namespace chromeos 917 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698