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 "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/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chromeos/network/device_state.h" | 13 #include "chromeos/network/device_state.h" |
14 #include "chromeos/network/managed_state.h" | 14 #include "chromeos/network/managed_state.h" |
15 #include "chromeos/network/network_event_log.h" | 15 #include "chromeos/network/network_event_log.h" |
16 #include "chromeos/network/network_state.h" | 16 #include "chromeos/network/network_state.h" |
17 #include "chromeos/network/network_state_handler_observer.h" | 17 #include "chromeos/network/network_state_handler_observer.h" |
18 #include "chromeos/network/shill_property_handler.h" | 18 #include "chromeos/network/shill_property_handler.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char kLogModule[] = "NetworkStateHandler"; | |
24 | |
25 // Returns true if |network->type()| == |match_type|, or it matches one of the | 23 // Returns true if |network->type()| == |match_type|, or it matches one of the |
26 // following special match types: | 24 // following special match types: |
27 // * kMatchTypeDefault matches any network (i.e. the first instance) | 25 // * kMatchTypeDefault matches any network (i.e. the first instance) |
28 // * kMatchTypeNonVirtual matches non virtual networks | 26 // * kMatchTypeNonVirtual matches non virtual networks |
29 // * kMatchTypeWireless matches wireless networks | 27 // * kMatchTypeWireless matches wireless networks |
30 // * kMatchTypeMobile matches cellular or wimax networks | 28 // * kMatchTypeMobile matches cellular or wimax networks |
31 bool ManagedStateMatchesType(const chromeos::ManagedState* managed, | 29 bool ManagedStateMatchesType(const chromeos::ManagedState* managed, |
32 const std::string& match_type) { | 30 const std::string& match_type) { |
33 const std::string& type = managed->type(); | 31 const std::string& type = managed->type(); |
34 if (match_type == chromeos::NetworkStateHandler::kMatchTypeDefault) | 32 if (match_type == chromeos::NetworkStateHandler::kMatchTypeDefault) |
35 return true; | 33 return true; |
36 if (match_type == type) | 34 if (match_type == type) |
37 return true; | 35 return true; |
38 if (match_type == chromeos::NetworkStateHandler::kMatchTypeNonVirtual && | 36 if (match_type == chromeos::NetworkStateHandler::kMatchTypeNonVirtual && |
39 type != flimflam::kTypeVPN) { | 37 type != flimflam::kTypeVPN) { |
40 return true; | 38 return true; |
41 } | 39 } |
42 if (match_type == chromeos::NetworkStateHandler::kMatchTypeWireless && | 40 if (match_type == chromeos::NetworkStateHandler::kMatchTypeWireless && |
43 type != flimflam::kTypeEthernet && type != flimflam::kTypeVPN) { | 41 type != flimflam::kTypeEthernet && type != flimflam::kTypeVPN) { |
44 return true; | 42 return true; |
45 } | 43 } |
46 if (match_type == chromeos::NetworkStateHandler::kMatchTypeMobile && | 44 if (match_type == chromeos::NetworkStateHandler::kMatchTypeMobile && |
47 (type == flimflam::kTypeCellular || type == flimflam::kTypeWimax)) { | 45 (type == flimflam::kTypeCellular || type == flimflam::kTypeWimax)) { |
48 return true; | 46 return true; |
49 } | 47 } |
50 return false; | 48 return false; |
51 } | 49 } |
52 | 50 |
53 std::string ValueAsString(const base::Value& value) { | |
54 if (value.GetType() == base::Value::TYPE_BOOLEAN) { | |
55 bool bval = false; | |
56 value.GetAsBoolean(&bval); | |
57 return bval ? "true" : "false"; | |
58 } else if (value.GetType() == base::Value::TYPE_INTEGER) { | |
59 int intval = 0; | |
60 value.GetAsInteger(&intval); | |
61 return base::StringPrintf("%d", intval); | |
62 } else if (value.GetType() == base::Value::TYPE_DOUBLE) { | |
63 double dval = 0; | |
64 value.GetAsDouble(&dval); | |
65 return base::StringPrintf("%g", dval); | |
66 } else if (value.GetType() == base::Value::TYPE_STRING) { | |
67 std::string vstr; | |
68 value.GetAsString(&vstr); | |
69 return vstr; | |
70 } | |
71 return ""; | |
72 } | |
73 | |
74 bool ConnectionStateChanged(chromeos::NetworkState* network, | 51 bool ConnectionStateChanged(chromeos::NetworkState* network, |
75 const std::string& prev_connection_state) { | 52 const std::string& prev_connection_state) { |
76 return (network->connection_state() != prev_connection_state) && | 53 return (network->connection_state() != prev_connection_state) && |
77 (network->connection_state() != flimflam::kStateIdle || | 54 (network->connection_state() != flimflam::kStateIdle || |
78 !prev_connection_state.empty()); | 55 !prev_connection_state.empty()); |
79 } | 56 } |
80 | 57 |
58 std::string GetManagedStateLogName(const chromeos::ManagedState* network) { | |
pneubeck (no reviews)
2013/05/13 13:16:25
either the function name and argument type are wro
stevenjb
2013/05/13 19:36:39
Done.
| |
59 if (!network) | |
60 return "None"; | |
61 return base::StringPrintf("%s (%s)", network->name().c_str(), | |
62 network->path().c_str()); | |
63 } | |
64 | |
81 } // namespace | 65 } // namespace |
82 | 66 |
83 namespace chromeos { | 67 namespace chromeos { |
84 | 68 |
85 const char NetworkStateHandler::kMatchTypeDefault[] = "default"; | 69 const char NetworkStateHandler::kMatchTypeDefault[] = "default"; |
86 const char NetworkStateHandler::kMatchTypeWireless[] = "wireless"; | 70 const char NetworkStateHandler::kMatchTypeWireless[] = "wireless"; |
87 const char NetworkStateHandler::kMatchTypeMobile[] = "mobile"; | 71 const char NetworkStateHandler::kMatchTypeMobile[] = "mobile"; |
88 const char NetworkStateHandler::kMatchTypeNonVirtual[] = "non-virtual"; | 72 const char NetworkStateHandler::kMatchTypeNonVirtual[] = "non-virtual"; |
89 | 73 |
90 static NetworkStateHandler* g_network_state_handler = NULL; | 74 static NetworkStateHandler* g_network_state_handler = NULL; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 state = TECHNOLOGY_UNAVAILABLE; | 137 state = TECHNOLOGY_UNAVAILABLE; |
154 VLOG(2) << "GetTechnologyState: " << type << " = " << state; | 138 VLOG(2) << "GetTechnologyState: " << type << " = " << state; |
155 return state; | 139 return state; |
156 } | 140 } |
157 | 141 |
158 void NetworkStateHandler::SetTechnologyEnabled( | 142 void NetworkStateHandler::SetTechnologyEnabled( |
159 const std::string& type, | 143 const std::string& type, |
160 bool enabled, | 144 bool enabled, |
161 const network_handler::ErrorCallback& error_callback) { | 145 const network_handler::ErrorCallback& error_callback) { |
162 std::string technology = GetTechnologyForType(type); | 146 std::string technology = GetTechnologyForType(type); |
163 network_event_log::AddEntry( | 147 NET_LOG_EVENT("SetTechnologyEnabled", |
164 kLogModule, "SetTechnologyEnabled", | 148 base::StringPrintf("%s:%d", technology.c_str(), enabled)); |
165 base::StringPrintf("%s:%d", technology.c_str(), enabled)); | |
166 shill_property_handler_->SetTechnologyEnabled( | 149 shill_property_handler_->SetTechnologyEnabled( |
167 technology, enabled, error_callback); | 150 technology, enabled, error_callback); |
168 ManagerPropertyChanged(); // Technology state changed -> ENABLING | 151 // Signal Technology state changed -> ENABLING |
152 NotifyManagerPropertyChanged(); | |
169 } | 153 } |
170 | 154 |
171 const DeviceState* NetworkStateHandler::GetDeviceState( | 155 const DeviceState* NetworkStateHandler::GetDeviceState( |
172 const std::string& device_path) const { | 156 const std::string& device_path) const { |
173 return GetModifiableDeviceState(device_path); | 157 return GetModifiableDeviceState(device_path); |
174 } | 158 } |
175 | 159 |
176 const DeviceState* NetworkStateHandler::GetDeviceStateByType( | 160 const DeviceState* NetworkStateHandler::GetDeviceStateByType( |
177 const std::string& type) const { | 161 const std::string& type) const { |
178 for (ManagedStateList::const_iterator iter = device_list_.begin(); | 162 for (ManagedStateList::const_iterator iter = device_list_.begin(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 list->clear(); | 269 list->clear(); |
286 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 270 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
287 iter != network_list_.end(); ++iter) { | 271 iter != network_list_.end(); ++iter) { |
288 const NetworkState* network = (*iter)->AsNetworkState(); | 272 const NetworkState* network = (*iter)->AsNetworkState(); |
289 DCHECK(network); | 273 DCHECK(network); |
290 list->push_back(network); | 274 list->push_back(network); |
291 } | 275 } |
292 } | 276 } |
293 | 277 |
294 void NetworkStateHandler::RequestScan() const { | 278 void NetworkStateHandler::RequestScan() const { |
295 network_event_log::AddEntry(kLogModule, "RequestScan", ""); | 279 NET_LOG_EVENT("RequestScan", ""); |
296 shill_property_handler_->RequestScan(); | 280 shill_property_handler_->RequestScan(); |
297 } | 281 } |
298 | 282 |
299 void NetworkStateHandler::WaitForScan(const std::string& type, | 283 void NetworkStateHandler::WaitForScan(const std::string& type, |
300 const base::Closure& callback) { | 284 const base::Closure& callback) { |
301 scan_complete_callbacks_[type].push_back(callback); | 285 scan_complete_callbacks_[type].push_back(callback); |
302 if (!GetScanningByType(type)) | 286 if (!GetScanningByType(type)) |
303 RequestScan(); | 287 RequestScan(); |
304 } | 288 } |
305 | 289 |
306 void NetworkStateHandler::ConnectToBestWifiNetwork() { | 290 void NetworkStateHandler::ConnectToBestWifiNetwork() { |
307 network_event_log::AddEntry(kLogModule, "ConnectToBestWifiNetwork", ""); | 291 NET_LOG_EVENT("ConnectToBestWifiNetwork", ""); |
308 WaitForScan(flimflam::kTypeWifi, | 292 WaitForScan(flimflam::kTypeWifi, |
309 base::Bind(&internal::ShillPropertyHandler::ConnectToBestServices, | 293 base::Bind(&internal::ShillPropertyHandler::ConnectToBestServices, |
310 shill_property_handler_->AsWeakPtr())); | 294 shill_property_handler_->AsWeakPtr())); |
311 } | 295 } |
312 | 296 |
313 void NetworkStateHandler::SetConnectingNetwork( | 297 void NetworkStateHandler::SetConnectingNetwork( |
314 const std::string& service_path) { | 298 const std::string& service_path) { |
315 connecting_network_ = service_path; | 299 connecting_network_ = service_path; |
316 network_event_log::AddEntry( | 300 NET_LOG_EVENT("SetConnectingNetwork", GetNameFromPath(service_path)); |
pneubeck (no reviews)
2013/05/13 13:16:25
Does GetNameFromPath really have to exposed in the
stevenjb
2013/05/13 19:36:39
Eliminated GetNameFromPath
| |
317 kLogModule, "SetConnectingNetwork", service_path); | |
318 } | 301 } |
319 | 302 |
320 void NetworkStateHandler::GetNetworkStatePropertiesForTest( | 303 void NetworkStateHandler::GetNetworkStatePropertiesForTest( |
321 base::DictionaryValue* dictionary) const { | 304 base::DictionaryValue* dictionary) const { |
322 for (ManagedStateList::const_iterator iter = network_list_.begin(); | 305 for (ManagedStateList::const_iterator iter = network_list_.begin(); |
323 iter != network_list_.end(); ++iter) { | 306 iter != network_list_.end(); ++iter) { |
324 base::DictionaryValue* network_dict = new base::DictionaryValue; | 307 base::DictionaryValue* network_dict = new base::DictionaryValue; |
325 (*iter)->AsNetworkState()->GetProperties(network_dict); | 308 (*iter)->AsNetworkState()->GetProperties(network_dict); |
326 dictionary->SetWithoutPathExpansion((*iter)->path(), network_dict); | 309 dictionary->SetWithoutPathExpansion((*iter)->path(), network_dict); |
327 } | 310 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 if (is_observing) | 351 if (is_observing) |
369 managed->set_is_observed(true); | 352 managed->set_is_observed(true); |
370 if (request_properties) | 353 if (request_properties) |
371 shill_property_handler_->RequestProperties(type, path); | 354 shill_property_handler_->RequestProperties(type, path); |
372 } | 355 } |
373 // Delete any remaning entries in managed_map. | 356 // Delete any remaning entries in managed_map. |
374 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); | 357 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); |
375 } | 358 } |
376 | 359 |
377 void NetworkStateHandler::ProfileListChanged() { | 360 void NetworkStateHandler::ProfileListChanged() { |
378 network_event_log::AddEntry( | 361 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties"); |
379 kLogModule, "ProfileListChanged", "Re-Requesting Network Properties"); | |
380 for (ManagedStateList::iterator iter = network_list_.begin(); | 362 for (ManagedStateList::iterator iter = network_list_.begin(); |
381 iter != network_list_.end(); ++iter) { | 363 iter != network_list_.end(); ++iter) { |
382 shill_property_handler_->RequestProperties( | 364 shill_property_handler_->RequestProperties( |
383 ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path()); | 365 ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path()); |
384 } | 366 } |
385 } | 367 } |
386 | 368 |
387 void NetworkStateHandler::UpdateManagedStateProperties( | 369 void NetworkStateHandler::UpdateManagedStateProperties( |
388 ManagedState::ManagedType type, | 370 ManagedState::ManagedType type, |
389 const std::string& path, | 371 const std::string& path, |
(...skipping 10 matching lines...) Expand all Loading... | |
400 for (base::DictionaryValue::Iterator iter(properties); | 382 for (base::DictionaryValue::Iterator iter(properties); |
401 !iter.IsAtEnd(); iter.Advance()) { | 383 !iter.IsAtEnd(); iter.Advance()) { |
402 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 384 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
403 if (managed->PropertyChanged(iter.key(), iter.value())) | 385 if (managed->PropertyChanged(iter.key(), iter.value())) |
404 network_property_updated = true; | 386 network_property_updated = true; |
405 } else { | 387 } else { |
406 managed->PropertyChanged(iter.key(), iter.value()); | 388 managed->PropertyChanged(iter.key(), iter.value()); |
407 } | 389 } |
408 } | 390 } |
409 managed->InitialPropertiesReceived(); | 391 managed->InitialPropertiesReceived(); |
410 network_event_log::AddEntry( | 392 NET_LOG_DEBUG("PropertiesReceived", GetNameFromPath(path)); |
pneubeck (no reviews)
2013/05/13 13:16:25
should use GetManagedStateLogName(managed) instead
stevenjb
2013/05/13 19:36:39
Done.
| |
411 kLogModule, "PropertiesReceived", | |
412 base::StringPrintf("%s (%s)", path.c_str(), managed->name().c_str())); | |
413 // Notify observers. | 393 // Notify observers. |
414 if (network_property_updated) { | 394 if (network_property_updated) { |
415 NetworkState* network = managed->AsNetworkState(); | 395 NetworkState* network = managed->AsNetworkState(); |
416 DCHECK(network); | 396 DCHECK(network); |
417 // Signal connection state changed after all properties have been updated. | 397 // Signal connection state changed after all properties have been updated. |
418 if (ConnectionStateChanged(network, prev_connection_state)) | 398 if (ConnectionStateChanged(network, prev_connection_state)) |
419 OnNetworkConnectionStateChanged(network); | 399 OnNetworkConnectionStateChanged(network); |
420 NetworkPropertiesUpdated(network); | 400 NetworkPropertiesUpdated(network); |
421 } | 401 } |
422 } | 402 } |
(...skipping 13 matching lines...) Expand all Loading... | |
436 if (ConnectionStateChanged(network, prev_connection_state)) | 416 if (ConnectionStateChanged(network, prev_connection_state)) |
437 OnNetworkConnectionStateChanged(network); | 417 OnNetworkConnectionStateChanged(network); |
438 } else { | 418 } else { |
439 if (network->path() == default_network_path_ && | 419 if (network->path() == default_network_path_ && |
440 key != flimflam::kSignalStrengthProperty) { | 420 key != flimflam::kSignalStrengthProperty) { |
441 // WiFi signal strength updates are too noisy, so don't | 421 // WiFi signal strength updates are too noisy, so don't |
442 // trigger default network updates for those changes. | 422 // trigger default network updates for those changes. |
443 OnDefaultNetworkChanged(); | 423 OnDefaultNetworkChanged(); |
444 } | 424 } |
445 std::string detail = network->name() + "." + key; | 425 std::string detail = network->name() + "." + key; |
446 std::string vstr = ValueAsString(value); | 426 std::string vstr = network_event_log::DBusValueAsString(value); |
447 if (!vstr.empty()) | 427 if (!vstr.empty()) |
448 detail += " = " + vstr; | 428 detail += " = " + vstr; |
449 network_event_log::AddEntry(kLogModule, "NetworkPropertyUpdated", detail); | 429 network_event_log::LogLevel log_level = |
430 (key == flimflam::kSignalStrengthProperty) | |
431 ? network_event_log::LOG_LEVEL_DEBUG | |
432 : network_event_log::LOG_LEVEL_EVENT; | |
433 NET_LOG_LEVEL(log_level, "NetworkPropertyUpdated", detail); | |
450 } | 434 } |
451 NetworkPropertiesUpdated(network); | 435 NetworkPropertiesUpdated(network); |
452 } | 436 } |
453 | 437 |
454 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, | 438 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, |
455 const std::string& key, | 439 const std::string& key, |
456 const base::Value& value) { | 440 const base::Value& value) { |
457 DeviceState* device = GetModifiableDeviceState(device_path); | 441 DeviceState* device = GetModifiableDeviceState(device_path); |
458 if (!device) | 442 if (!device) |
459 return; | 443 return; |
460 if (!device->PropertyChanged(key, value)) | 444 if (!device->PropertyChanged(key, value)) |
461 return; | 445 return; |
462 | 446 |
463 std::string detail = device->name() + "." + key; | 447 std::string detail = device->name() + "." + key; |
464 std::string vstr = ValueAsString(value); | 448 std::string vstr = network_event_log::DBusValueAsString(value); |
465 if (!vstr.empty()) | 449 if (!vstr.empty()) |
466 detail += " = " + vstr; | 450 detail += " = " + vstr; |
467 network_event_log::AddEntry(kLogModule, "DevicePropertyUpdated", detail); | 451 NET_LOG_EVENT("DevicePropertyUpdated", detail); |
468 | 452 |
469 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 453 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
470 DeviceListChanged()); | 454 DeviceListChanged()); |
471 | 455 |
472 if (key == flimflam::kScanningProperty && device->scanning() == false) | 456 if (key == flimflam::kScanningProperty && device->scanning() == false) |
473 ScanCompleted(device->type()); | 457 ScanCompleted(device->type()); |
474 } | 458 } |
475 | 459 |
476 void NetworkStateHandler::ManagerPropertyChanged() { | 460 void NetworkStateHandler::NotifyManagerPropertyChanged() { |
477 network_event_log::AddEntry(kLogModule, "NetworkManagerChanged", ""); | 461 NET_LOG_DEBUG("NotifyManagerPropertyChanged", ""); |
478 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 462 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
479 NetworkManagerChanged()); | 463 NetworkManagerChanged()); |
480 } | 464 } |
481 | 465 |
482 void NetworkStateHandler::ManagedStateListChanged( | 466 void NetworkStateHandler::ManagedStateListChanged( |
483 ManagedState::ManagedType type) { | 467 ManagedState::ManagedType type) { |
484 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 468 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
485 // Notify observers that the list of networks has changed. | 469 // Notify observers that the list of networks has changed. |
486 network_event_log::AddEntry( | 470 NET_LOG_EVENT("NetworkListChanged", |
487 kLogModule, "NetworkListChanged", | 471 base::StringPrintf("Size:%"PRIuS, network_list_.size())); |
488 base::StringPrintf("Size:%"PRIuS, network_list_.size())); | |
489 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 472 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
490 NetworkListChanged()); | 473 NetworkListChanged()); |
491 // The list order may have changed, so check if the default network changed. | 474 // The list order may have changed, so check if the default network changed. |
492 if (CheckDefaultNetworkChanged()) | 475 if (CheckDefaultNetworkChanged()) |
493 OnDefaultNetworkChanged(); | 476 OnDefaultNetworkChanged(); |
494 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | 477 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
495 network_event_log::AddEntry( | 478 NET_LOG_DEBUG("DeviceListChanged", |
496 kLogModule, "DeviceListChanged", | 479 base::StringPrintf("Size:%"PRIuS, device_list_.size())); |
497 base::StringPrintf("Size:%"PRIuS, device_list_.size())); | |
498 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 480 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
499 DeviceListChanged()); | 481 DeviceListChanged()); |
500 } else { | 482 } else { |
501 NOTREACHED(); | 483 NOTREACHED(); |
502 } | 484 } |
503 } | 485 } |
504 | 486 |
505 //------------------------------------------------------------------------------ | 487 //------------------------------------------------------------------------------ |
506 // Private methods | 488 // Private methods |
507 | 489 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 case ManagedState::MANAGED_TYPE_DEVICE: | 524 case ManagedState::MANAGED_TYPE_DEVICE: |
543 return &device_list_; | 525 return &device_list_; |
544 } | 526 } |
545 NOTREACHED(); | 527 NOTREACHED(); |
546 return NULL; | 528 return NULL; |
547 } | 529 } |
548 | 530 |
549 void NetworkStateHandler::OnNetworkConnectionStateChanged( | 531 void NetworkStateHandler::OnNetworkConnectionStateChanged( |
550 NetworkState* network) { | 532 NetworkState* network) { |
551 DCHECK(network); | 533 DCHECK(network); |
552 network_event_log::AddEntry( | 534 NET_LOG_EVENT("NetworkConnectionStateChanged", base::StringPrintf( |
553 kLogModule, "NetworkConnectionStateChanged", | 535 "%s:%s", GetManagedStateLogName(network).c_str(), |
554 base::StringPrintf("%s:%s", network->path().c_str(), | 536 network->connection_state().c_str())); |
555 network->connection_state().c_str())); | |
556 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 537 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
557 NetworkConnectionStateChanged(network)); | 538 NetworkConnectionStateChanged(network)); |
558 if (CheckDefaultNetworkChanged() || network->path() == default_network_path_) | 539 if (CheckDefaultNetworkChanged() || network->path() == default_network_path_) |
559 OnDefaultNetworkChanged(); | 540 OnDefaultNetworkChanged(); |
560 } | 541 } |
561 | 542 |
562 bool NetworkStateHandler::CheckDefaultNetworkChanged() { | 543 bool NetworkStateHandler::CheckDefaultNetworkChanged() { |
563 std::string new_default_network_path; | 544 std::string new_default_network_path; |
564 const NetworkState* new_default_network = DefaultNetwork(); | 545 const NetworkState* new_default_network = DefaultNetwork(); |
565 if (new_default_network) | 546 if (new_default_network) |
566 new_default_network_path = new_default_network->path(); | 547 new_default_network_path = new_default_network->path(); |
567 if (new_default_network_path == default_network_path_) | 548 if (new_default_network_path == default_network_path_) |
568 return false; | 549 return false; |
569 default_network_path_ = new_default_network_path; | 550 default_network_path_ = new_default_network_path; |
570 return true; | 551 return true; |
571 } | 552 } |
572 | 553 |
573 void NetworkStateHandler::OnDefaultNetworkChanged() { | 554 void NetworkStateHandler::OnDefaultNetworkChanged() { |
574 const NetworkState* default_network = DefaultNetwork(); | 555 const NetworkState* default_network = DefaultNetwork(); |
575 network_event_log::AddEntry( | 556 NET_LOG_EVENT("DefaultNetworkChanged", |
576 kLogModule, "DefaultNetworkChanged", | 557 GetManagedStateLogName(default_network)); |
577 default_network ? default_network->path() : "None"); | |
578 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 558 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
579 DefaultNetworkChanged(default_network)); | 559 DefaultNetworkChanged(default_network)); |
580 } | 560 } |
581 | 561 |
582 void NetworkStateHandler::NetworkPropertiesUpdated( | 562 void NetworkStateHandler::NetworkPropertiesUpdated( |
583 const NetworkState* network) { | 563 const NetworkState* network) { |
584 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 564 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
585 NetworkPropertiesUpdated(network)); | 565 NetworkPropertiesUpdated(network)); |
586 // If |connecting_network_| transitions to a non-idle, non-connecting state, | 566 // If |connecting_network_| transitions to a non-idle, non-connecting state, |
587 // clear it *after* signalling observers. | 567 // clear it *after* signalling observers. |
588 if (network->path() == connecting_network_ && | 568 if (network->path() == connecting_network_ && |
589 !network->IsConnectingState() && | 569 !network->IsConnectingState() && |
590 network->connection_state() != flimflam::kStateIdle) { | 570 network->connection_state() != flimflam::kStateIdle) { |
591 connecting_network_.clear(); | 571 connecting_network_.clear(); |
592 network_event_log::AddEntry( | 572 NET_LOG_EVENT("ClearConnectingNetwork", base::StringPrintf( |
593 kLogModule, "ClearConnectingNetwork", | 573 "%s:%s", GetManagedStateLogName(network).c_str(), |
594 base::StringPrintf("%s:%s", network->path().c_str(), | 574 network->connection_state().c_str())); |
595 network->connection_state().c_str())); | |
596 } | 575 } |
597 } | 576 } |
598 | 577 |
599 void NetworkStateHandler::ScanCompleted(const std::string& type) { | 578 void NetworkStateHandler::ScanCompleted(const std::string& type) { |
600 size_t num_callbacks = scan_complete_callbacks_.count(type); | 579 size_t num_callbacks = scan_complete_callbacks_.count(type); |
601 network_event_log::AddEntry( | 580 NET_LOG_EVENT("ScanCompleted", |
602 kLogModule, "ScanCompleted", | 581 base::StringPrintf("%s:%"PRIuS, type.c_str(), num_callbacks)); |
603 base::StringPrintf("%s:%"PRIuS, type.c_str(), num_callbacks)); | |
604 if (num_callbacks == 0) | 582 if (num_callbacks == 0) |
605 return; | 583 return; |
606 ScanCallbackList& callback_list = scan_complete_callbacks_[type]; | 584 ScanCallbackList& callback_list = scan_complete_callbacks_[type]; |
607 for (ScanCallbackList::iterator iter = callback_list.begin(); | 585 for (ScanCallbackList::iterator iter = callback_list.begin(); |
608 iter != callback_list.end(); ++iter) { | 586 iter != callback_list.end(); ++iter) { |
609 (*iter).Run(); | 587 (*iter).Run(); |
610 } | 588 } |
611 scan_complete_callbacks_.erase(type); | 589 scan_complete_callbacks_.erase(type); |
612 } | 590 } |
613 | 591 |
614 std::string NetworkStateHandler::GetTechnologyForType( | 592 std::string NetworkStateHandler::GetTechnologyForType( |
615 const std::string& type) const { | 593 const std::string& type) const { |
616 if (type == kMatchTypeMobile) { | 594 if (type == kMatchTypeMobile) { |
617 if (shill_property_handler_->IsTechnologyAvailable(flimflam::kTypeWimax)) | 595 if (shill_property_handler_->IsTechnologyAvailable(flimflam::kTypeWimax)) |
618 return flimflam::kTypeWimax; | 596 return flimflam::kTypeWimax; |
619 else | 597 else |
620 return flimflam::kTypeCellular; | 598 return flimflam::kTypeCellular; |
621 } | 599 } |
622 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual || | 600 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual || |
623 type == kMatchTypeWireless) { | 601 type == kMatchTypeWireless) { |
624 NOTREACHED(); | 602 NOTREACHED(); |
625 return flimflam::kTypeWifi; | 603 return flimflam::kTypeWifi; |
626 } | 604 } |
627 return type; | 605 return type; |
628 } | 606 } |
629 | 607 |
608 std::string NetworkStateHandler::GetNameFromPath( | |
609 const std::string& path) const { | |
pneubeck (no reviews)
2013/05/13 13:16:25
after fixing my other comment, this is only used f
stevenjb
2013/05/13 19:36:39
Eliminated GetNameFromPath
| |
610 ManagedState* managed = GetModifiableManagedState(&network_list_, path); | |
611 if (!managed) | |
612 managed = GetModifiableManagedState(&device_list_, path); | |
613 if (managed) | |
614 return GetManagedStateLogName(managed); | |
615 return path; | |
616 } | |
617 | |
630 } // namespace chromeos | 618 } // namespace chromeos |
OLD | NEW |