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" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 value.GetAsDouble(&dval); | 64 value.GetAsDouble(&dval); |
65 return base::StringPrintf("%g", dval); | 65 return base::StringPrintf("%g", dval); |
66 } else if (value.GetType() == base::Value::TYPE_STRING) { | 66 } else if (value.GetType() == base::Value::TYPE_STRING) { |
67 std::string vstr; | 67 std::string vstr; |
68 value.GetAsString(&vstr); | 68 value.GetAsString(&vstr); |
69 return vstr; | 69 return vstr; |
70 } | 70 } |
71 return ""; | 71 return ""; |
72 } | 72 } |
73 | 73 |
| 74 bool ConnectionStateChanged(chromeos::NetworkState* network, |
| 75 const std::string& prev_connection_state) { |
| 76 return (network->connection_state() != prev_connection_state) && |
| 77 (network->connection_state() != flimflam::kStateIdle || |
| 78 !prev_connection_state.empty()); |
| 79 } |
| 80 |
74 } // namespace | 81 } // namespace |
75 | 82 |
76 namespace chromeos { | 83 namespace chromeos { |
77 | 84 |
78 const char NetworkStateHandler::kMatchTypeDefault[] = "default"; | 85 const char NetworkStateHandler::kMatchTypeDefault[] = "default"; |
79 const char NetworkStateHandler::kMatchTypeWireless[] = "wireless"; | 86 const char NetworkStateHandler::kMatchTypeWireless[] = "wireless"; |
80 const char NetworkStateHandler::kMatchTypeMobile[] = "mobile"; | 87 const char NetworkStateHandler::kMatchTypeMobile[] = "mobile"; |
81 const char NetworkStateHandler::kMatchTypeNonVirtual[] = "non-virtual"; | 88 const char NetworkStateHandler::kMatchTypeNonVirtual[] = "non-virtual"; |
82 | 89 |
83 static NetworkStateHandler* g_network_state_handler = NULL; | 90 static NetworkStateHandler* g_network_state_handler = NULL; |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 408 } |
402 managed->InitialPropertiesReceived(); | 409 managed->InitialPropertiesReceived(); |
403 network_event_log::AddEntry( | 410 network_event_log::AddEntry( |
404 kLogModule, "PropertiesReceived", | 411 kLogModule, "PropertiesReceived", |
405 base::StringPrintf("%s (%s)", path.c_str(), managed->name().c_str())); | 412 base::StringPrintf("%s (%s)", path.c_str(), managed->name().c_str())); |
406 // Notify observers. | 413 // Notify observers. |
407 if (network_property_updated) { | 414 if (network_property_updated) { |
408 NetworkState* network = managed->AsNetworkState(); | 415 NetworkState* network = managed->AsNetworkState(); |
409 DCHECK(network); | 416 DCHECK(network); |
410 // Signal connection state changed after all properties have been updated. | 417 // Signal connection state changed after all properties have been updated. |
411 if (network->connection_state() != prev_connection_state) | 418 if (ConnectionStateChanged(network, prev_connection_state)) |
412 OnNetworkConnectionStateChanged(network); | 419 OnNetworkConnectionStateChanged(network); |
413 NetworkPropertiesUpdated(network); | 420 NetworkPropertiesUpdated(network); |
414 } | 421 } |
415 } | 422 } |
416 | 423 |
417 void NetworkStateHandler::UpdateNetworkServiceProperty( | 424 void NetworkStateHandler::UpdateNetworkServiceProperty( |
418 const std::string& service_path, | 425 const std::string& service_path, |
419 const std::string& key, | 426 const std::string& key, |
420 const base::Value& value) { | 427 const base::Value& value) { |
421 NetworkState* network = GetModifiableNetworkState(service_path); | 428 NetworkState* network = GetModifiableNetworkState(service_path); |
422 if (!network) | 429 if (!network) |
423 return; | 430 return; |
424 std::string prev_connection_state = network->connection_state(); | 431 std::string prev_connection_state = network->connection_state(); |
425 if (!network->PropertyChanged(key, value)) | 432 if (!network->PropertyChanged(key, value)) |
426 return; | 433 return; |
427 | 434 |
428 std::string detail = network->name() + "." + key; | 435 if (key == flimflam::kStateProperty) { |
429 std::string vstr = ValueAsString(value); | 436 if (ConnectionStateChanged(network, prev_connection_state)) |
430 if (!vstr.empty()) | 437 OnNetworkConnectionStateChanged(network); |
431 detail += " = " + vstr; | 438 } else { |
432 network_event_log::AddEntry(kLogModule, "NetworkPropertyUpdated", detail); | 439 if (network->path() == default_network_path_ && |
433 | 440 key != flimflam::kSignalStrengthProperty) { |
434 if (network->connection_state() != prev_connection_state) { | 441 // WiFi signal strength updates are too noisy, so don't |
435 OnNetworkConnectionStateChanged(network); | 442 // trigger default network updates for those changes. |
436 } else if (network->path() == default_network_path_ && | 443 OnDefaultNetworkChanged(); |
437 key != flimflam::kSignalStrengthProperty) { | 444 } |
438 // WiFi signal strength updates are too noisy, so don't | 445 std::string detail = network->name() + "." + key; |
439 // trigger default network updates for those changes. | 446 std::string vstr = ValueAsString(value); |
440 OnDefaultNetworkChanged(); | 447 if (!vstr.empty()) |
| 448 detail += " = " + vstr; |
| 449 network_event_log::AddEntry(kLogModule, "NetworkPropertyUpdated", detail); |
441 } | 450 } |
442 | |
443 NetworkPropertiesUpdated(network); | 451 NetworkPropertiesUpdated(network); |
444 } | 452 } |
445 | 453 |
446 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, | 454 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, |
447 const std::string& key, | 455 const std::string& key, |
448 const base::Value& value) { | 456 const base::Value& value) { |
449 DeviceState* device = GetModifiableDeviceState(device_path); | 457 DeviceState* device = GetModifiableDeviceState(device_path); |
450 if (!device) | 458 if (!device) |
451 return; | 459 return; |
452 if (!device->PropertyChanged(key, value)) | 460 if (!device->PropertyChanged(key, value)) |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 } | 621 } |
614 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual || | 622 if (type == kMatchTypeDefault || type == kMatchTypeNonVirtual || |
615 type == kMatchTypeWireless) { | 623 type == kMatchTypeWireless) { |
616 NOTREACHED(); | 624 NOTREACHED(); |
617 return flimflam::kTypeWifi; | 625 return flimflam::kTypeWifi; |
618 } | 626 } |
619 return type; | 627 return type; |
620 } | 628 } |
621 | 629 |
622 } // namespace chromeos | 630 } // namespace chromeos |
OLD | NEW |