| 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/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/json/json_string_value_serializer.h" |
| 11 #include "base/json/json_writer.h" |
| 10 #include "base/location.h" | 12 #include "base/location.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 13 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| 17 #include "chromeos/network/device_state.h" | 19 #include "chromeos/network/device_state.h" |
| 18 #include "chromeos/network/managed_state.h" | 20 #include "chromeos/network/managed_state.h" |
| 19 #include "chromeos/network/network_event_log.h" | 21 #include "chromeos/network/network_event_log.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 44 return ""; | 46 return ""; |
| 45 } | 47 } |
| 46 | 48 |
| 47 std::string GetLogName(const ManagedState* state) { | 49 std::string GetLogName(const ManagedState* state) { |
| 48 if (!state) | 50 if (!state) |
| 49 return "None"; | 51 return "None"; |
| 50 return base::StringPrintf("%s (%s)", state->name().c_str(), | 52 return base::StringPrintf("%s (%s)", state->name().c_str(), |
| 51 state->path().c_str()); | 53 state->path().c_str()); |
| 52 } | 54 } |
| 53 | 55 |
| 56 std::string ValueAsString(const base::Value& value) { |
| 57 std::string vstr; |
| 58 base::JSONWriter::WriteWithOptions( |
| 59 &value, base::JSONWriter::OPTIONS_OMIT_BINARY_VALUES, &vstr); |
| 60 return vstr.empty() ? "''" : vstr; |
| 61 } |
| 62 |
| 54 } // namespace | 63 } // namespace |
| 55 | 64 |
| 56 const char NetworkStateHandler::kDefaultCheckPortalList[] = | 65 const char NetworkStateHandler::kDefaultCheckPortalList[] = |
| 57 "ethernet,wifi,cellular"; | 66 "ethernet,wifi,cellular"; |
| 58 | 67 |
| 59 NetworkStateHandler::NetworkStateHandler() | 68 NetworkStateHandler::NetworkStateHandler() |
| 60 : network_list_sorted_(false) { | 69 : network_list_sorted_(false) { |
| 61 } | 70 } |
| 62 | 71 |
| 63 NetworkStateHandler::~NetworkStateHandler() { | 72 NetworkStateHandler::~NetworkStateHandler() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 75 NetworkStateHandler* NetworkStateHandler::InitializeForTest() { | 84 NetworkStateHandler* NetworkStateHandler::InitializeForTest() { |
| 76 NetworkStateHandler* handler = new NetworkStateHandler(); | 85 NetworkStateHandler* handler = new NetworkStateHandler(); |
| 77 handler->InitShillPropertyHandler(); | 86 handler->InitShillPropertyHandler(); |
| 78 return handler; | 87 return handler; |
| 79 } | 88 } |
| 80 | 89 |
| 81 void NetworkStateHandler::AddObserver( | 90 void NetworkStateHandler::AddObserver( |
| 82 NetworkStateHandlerObserver* observer, | 91 NetworkStateHandlerObserver* observer, |
| 83 const tracked_objects::Location& from_here) { | 92 const tracked_objects::Location& from_here) { |
| 84 observers_.AddObserver(observer); | 93 observers_.AddObserver(observer); |
| 85 network_event_log::internal::AddEntry( | 94 device_event_log::AddEntry( |
| 86 from_here.file_name(), from_here.line_number(), | 95 from_here.file_name(), from_here.line_number(), |
| 87 network_event_log::LOG_LEVEL_DEBUG, | 96 device_event_log::LOG_TYPE_NETWORK, |
| 88 "NetworkStateHandler::AddObserver", ""); | 97 device_event_log::LOG_LEVEL_DEBUG, |
| 98 "NetworkStateHandler::AddObserver"); |
| 89 } | 99 } |
| 90 | 100 |
| 91 void NetworkStateHandler::RemoveObserver( | 101 void NetworkStateHandler::RemoveObserver( |
| 92 NetworkStateHandlerObserver* observer, | 102 NetworkStateHandlerObserver* observer, |
| 93 const tracked_objects::Location& from_here) { | 103 const tracked_objects::Location& from_here) { |
| 94 observers_.RemoveObserver(observer); | 104 observers_.RemoveObserver(observer); |
| 95 network_event_log::internal::AddEntry( | 105 device_event_log::AddEntry( |
| 96 from_here.file_name(), from_here.line_number(), | 106 from_here.file_name(), from_here.line_number(), |
| 97 network_event_log::LOG_LEVEL_DEBUG, | 107 device_event_log::LOG_TYPE_NETWORK, |
| 98 "NetworkStateHandler::RemoveObserver", ""); | 108 device_event_log::LOG_LEVEL_DEBUG, |
| 109 "NetworkStateHandler::RemoveObserver"); |
| 99 } | 110 } |
| 100 | 111 |
| 101 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( | 112 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( |
| 102 const NetworkTypePattern& type) const { | 113 const NetworkTypePattern& type) const { |
| 103 std::string technology = GetTechnologyForType(type); | 114 std::string technology = GetTechnologyForType(type); |
| 104 TechnologyState state; | 115 TechnologyState state; |
| 105 if (shill_property_handler_->IsTechnologyEnabled(technology)) | 116 if (shill_property_handler_->IsTechnologyEnabled(technology)) |
| 106 state = TECHNOLOGY_ENABLED; | 117 state = TECHNOLOGY_ENABLED; |
| 107 else if (shill_property_handler_->IsTechnologyEnabling(technology)) | 118 else if (shill_property_handler_->IsTechnologyEnabling(technology)) |
| 108 state = TECHNOLOGY_ENABLING; | 119 state = TECHNOLOGY_ENABLING; |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 key != shill::kWifiFrequencyListProperty && | 573 key != shill::kWifiFrequencyListProperty && |
| 563 (key != shill::kDeviceProperty || value_str != "/")) { | 574 (key != shill::kDeviceProperty || value_str != "/")) { |
| 564 std::string log_event = "NetworkPropertyUpdated"; | 575 std::string log_event = "NetworkPropertyUpdated"; |
| 565 // Trigger a default network update for interesting changes only. | 576 // Trigger a default network update for interesting changes only. |
| 566 if (network->path() == default_network_path_) { | 577 if (network->path() == default_network_path_) { |
| 567 NotifyDefaultNetworkChanged(network); | 578 NotifyDefaultNetworkChanged(network); |
| 568 log_event = "Default" + log_event; | 579 log_event = "Default" + log_event; |
| 569 } | 580 } |
| 570 // Log event. | 581 // Log event. |
| 571 std::string detail = network->name() + "." + key; | 582 std::string detail = network->name() + "." + key; |
| 572 detail += " = " + network_event_log::ValueAsString(value); | 583 detail += " = " + ValueAsString(value); |
| 573 network_event_log::LogLevel log_level; | 584 device_event_log::LogLevel log_level; |
| 574 if (key == shill::kErrorProperty || key == shill::kErrorDetailsProperty) { | 585 if (key == shill::kErrorProperty || key == shill::kErrorDetailsProperty) { |
| 575 log_level = network_event_log::LOG_LEVEL_ERROR; | 586 log_level = device_event_log::LOG_LEVEL_ERROR; |
| 576 } else { | 587 } else { |
| 577 log_level = network_event_log::LOG_LEVEL_EVENT; | 588 log_level = device_event_log::LOG_LEVEL_EVENT; |
| 578 } | 589 } |
| 579 NET_LOG_LEVEL(log_level, log_event, detail); | 590 NET_LOG_LEVEL(log_level, log_event, detail); |
| 580 } | 591 } |
| 581 } | 592 } |
| 582 | 593 |
| 583 // All property updates signal 'NetworkPropertiesUpdated'. | 594 // All property updates signal 'NetworkPropertiesUpdated'. |
| 584 NotifyNetworkPropertiesUpdated(network); | 595 NotifyNetworkPropertiesUpdated(network); |
| 585 | 596 |
| 586 // If added to a Profile, request a full update so that a NetworkState | 597 // If added to a Profile, request a full update so that a NetworkState |
| 587 // gets created. | 598 // gets created. |
| 588 if (prev_profile_path.empty() && !network->profile_path().empty()) | 599 if (prev_profile_path.empty() && !network->profile_path().empty()) |
| 589 RequestUpdateForNetwork(service_path); | 600 RequestUpdateForNetwork(service_path); |
| 590 } | 601 } |
| 591 | 602 |
| 592 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, | 603 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, |
| 593 const std::string& key, | 604 const std::string& key, |
| 594 const base::Value& value) { | 605 const base::Value& value) { |
| 595 DeviceState* device = GetModifiableDeviceState(device_path); | 606 DeviceState* device = GetModifiableDeviceState(device_path); |
| 596 if (!device) | 607 if (!device) |
| 597 return; | 608 return; |
| 598 if (!device->PropertyChanged(key, value)) | 609 if (!device->PropertyChanged(key, value)) |
| 599 return; | 610 return; |
| 600 | 611 |
| 601 std::string detail = device->name() + "." + key; | 612 std::string detail = device->name() + "." + key; |
| 602 detail += " = " + network_event_log::ValueAsString(value); | 613 detail += " = " + ValueAsString(value); |
| 603 NET_LOG_EVENT("DevicePropertyUpdated", detail); | 614 NET_LOG_EVENT("DevicePropertyUpdated", detail); |
| 604 | 615 |
| 605 NotifyDeviceListChanged(); | 616 NotifyDeviceListChanged(); |
| 606 NotifyDevicePropertiesUpdated(device); | 617 NotifyDevicePropertiesUpdated(device); |
| 607 | 618 |
| 608 if (key == shill::kScanningProperty && device->scanning() == false) { | 619 if (key == shill::kScanningProperty && device->scanning() == false) { |
| 609 NotifyScanCompleted(device); | 620 NotifyScanCompleted(device); |
| 610 } | 621 } |
| 611 if (key == shill::kEapAuthenticationCompletedProperty) { | 622 if (key == shill::kEapAuthenticationCompletedProperty) { |
| 612 // Notify a change for each Ethernet service using this device. | 623 // Notify a change for each Ethernet service using this device. |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 if (type.MatchesType(shill::kTypeBluetooth)) | 954 if (type.MatchesType(shill::kTypeBluetooth)) |
| 944 technologies.push_back(new std::string(shill::kTypeBluetooth)); | 955 technologies.push_back(new std::string(shill::kTypeBluetooth)); |
| 945 if (type.MatchesType(shill::kTypeVPN)) | 956 if (type.MatchesType(shill::kTypeVPN)) |
| 946 technologies.push_back(new std::string(shill::kTypeVPN)); | 957 technologies.push_back(new std::string(shill::kTypeVPN)); |
| 947 | 958 |
| 948 CHECK_GT(technologies.size(), 0ul); | 959 CHECK_GT(technologies.size(), 0ul); |
| 949 return technologies.Pass(); | 960 return technologies.Pass(); |
| 950 } | 961 } |
| 951 | 962 |
| 952 } // namespace chromeos | 963 } // namespace chromeos |
| OLD | NEW |