Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromeos / network / device_state.cc
blobd736e16671e175d37bd2dc61c15ed0b8f3e28f31
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
3 // found in the LICENSE file.
5 #include "chromeos/network/device_state.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9 #include "base/strings/stringprintf.h"
10 #include "chromeos/network/network_event_log.h"
11 #include "chromeos/network/shill_property_util.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h"
14 namespace chromeos {
16 DeviceState::DeviceState(const std::string& path)
17 : ManagedState(MANAGED_TYPE_DEVICE, path),
18 allow_roaming_(false),
19 provider_requires_roaming_(false),
20 support_network_scan_(false),
21 scanning_(false),
22 sim_retries_left_(0),
23 sim_present_(true),
24 eap_authentication_completed_(false) {
27 DeviceState::~DeviceState() {
30 bool DeviceState::PropertyChanged(const std::string& key,
31 const base::Value& value) {
32 // All property values get stored in |properties_|.
33 properties_.SetWithoutPathExpansion(key, value.DeepCopy());
35 if (ManagedStatePropertyChanged(key, value))
36 return true;
37 if (key == shill::kAddressProperty) {
38 return GetStringValue(key, value, &mac_address_);
39 } else if (key == shill::kScanningProperty) {
40 return GetBooleanValue(key, value, &scanning_);
41 } else if (key == shill::kSupportNetworkScanProperty) {
42 return GetBooleanValue(key, value, &support_network_scan_);
43 } else if (key == shill::kCellularAllowRoamingProperty) {
44 return GetBooleanValue(key, value, &allow_roaming_);
45 } else if (key == shill::kProviderRequiresRoamingProperty) {
46 return GetBooleanValue(key, value, &provider_requires_roaming_);
47 } else if (key == shill::kHomeProviderProperty) {
48 return shill_property_util::GetHomeProviderFromProperty(
49 value, &home_provider_id_);
50 } else if (key == shill::kTechnologyFamilyProperty) {
51 return GetStringValue(key, value, &technology_family_);
52 } else if (key == shill::kCarrierProperty) {
53 return GetStringValue(key, value, &carrier_);
54 } else if (key == shill::kFoundNetworksProperty) {
55 const base::ListValue* list = nullptr;
56 if (!value.GetAsList(&list))
57 return false;
58 CellularScanResults parsed_results;
59 if (!network_util::ParseCellularScanResults(*list, &parsed_results))
60 return false;
61 scan_results_.swap(parsed_results);
62 return true;
63 } else if (key == shill::kSIMLockStatusProperty) {
64 const base::DictionaryValue* dict = nullptr;
65 if (!value.GetAsDictionary(&dict))
66 return false;
68 // Set default values for SIM properties.
69 sim_lock_type_.erase();
70 sim_retries_left_ = 0;
72 const base::Value* out_value = nullptr;
73 if (dict->GetWithoutPathExpansion(shill::kSIMLockTypeProperty,
74 &out_value)) {
75 GetStringValue(shill::kSIMLockTypeProperty, *out_value, &sim_lock_type_);
77 if (dict->GetWithoutPathExpansion(shill::kSIMLockRetriesLeftProperty,
78 &out_value)) {
79 GetUInt32Value(shill::kSIMLockRetriesLeftProperty, *out_value,
80 &sim_retries_left_);
82 return true;
83 } else if (key == shill::kMeidProperty) {
84 return GetStringValue(key, value, &meid_);
85 } else if (key == shill::kImeiProperty) {
86 return GetStringValue(key, value, &imei_);
87 } else if (key == shill::kIccidProperty) {
88 return GetStringValue(key, value, &iccid_);
89 } else if (key == shill::kMdnProperty) {
90 return GetStringValue(key, value, &mdn_);
91 } else if (key == shill::kSIMPresentProperty) {
92 return GetBooleanValue(key, value, &sim_present_);
93 } else if (key == shill::kEapAuthenticationCompletedProperty) {
94 return GetBooleanValue(key, value, &eap_authentication_completed_);
95 } else if (key == shill::kIPConfigsProperty) {
96 // If kIPConfigsProperty changes, clear any previous ip_configs_.
97 // ShillPropertyhandler will request the IPConfig objects which will trigger
98 // calls to IPConfigPropertiesChanged.
99 ip_configs_.Clear();
100 return false; // No actual state change.
102 return false;
105 bool DeviceState::InitialPropertiesReceived(
106 const base::DictionaryValue& properties) {
107 // Update UMA stats.
108 if (sim_present_) {
109 bool locked = !sim_lock_type_.empty();
110 UMA_HISTOGRAM_BOOLEAN("Cellular.SIMLocked", locked);
112 return false;
115 void DeviceState::IPConfigPropertiesChanged(
116 const std::string& ip_config_path,
117 const base::DictionaryValue& properties) {
118 base::DictionaryValue* ip_config = nullptr;
119 if (ip_configs_.GetDictionaryWithoutPathExpansion(
120 ip_config_path, &ip_config)) {
121 NET_LOG_EVENT("IPConfig Updated: " + ip_config_path, path());
122 ip_config->Clear();
123 } else {
124 NET_LOG_EVENT("IPConfig Added: " + ip_config_path, path());
125 ip_config = new base::DictionaryValue;
126 ip_configs_.SetWithoutPathExpansion(ip_config_path, ip_config);
128 ip_config->MergeDictionary(&properties);
131 bool DeviceState::IsSimAbsent() const {
132 return technology_family_ == shill::kTechnologyFamilyGsm && !sim_present_;
135 } // namespace chromeos