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.h" | 5 #include "chromeos/network/network_state.h" |
6 | 6 |
7 #include "base/i18n/icu_encoding_detection.h" | 7 #include "base/i18n/icu_encoding_detection.h" |
8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversion_utils.h" | 12 #include "base/strings/utf_string_conversion_utils.h" |
13 #include "chromeos/network/network_event_log.h" | 13 #include "chromeos/network/network_event_log.h" |
| 14 #include "chromeos/network/network_ui_data.h" |
14 #include "chromeos/network/onc/onc_utils.h" | 15 #include "chromeos/network/onc/onc_utils.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 20 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
20 std::vector<std::string>* result) { | 21 std::vector<std::string>* result) { |
21 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 22 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
22 std::string str; | 23 std::string str; |
23 if (!string_list.GetString(i, &str)) | 24 if (!string_list.GetString(i, &str)) |
(...skipping 25 matching lines...) Expand all Loading... |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 namespace chromeos { | 53 namespace chromeos { |
53 | 54 |
54 NetworkState::NetworkState(const std::string& path) | 55 NetworkState::NetworkState(const std::string& path) |
55 : ManagedState(MANAGED_TYPE_NETWORK, path), | 56 : ManagedState(MANAGED_TYPE_NETWORK, path), |
56 auto_connect_(false), | 57 auto_connect_(false), |
57 favorite_(false), | 58 favorite_(false), |
58 priority_(0), | 59 priority_(0), |
| 60 onc_source_(onc::ONC_SOURCE_NONE), |
59 signal_strength_(0), | 61 signal_strength_(0), |
60 connectable_(false), | 62 connectable_(false), |
61 passphrase_required_(false), | 63 passphrase_required_(false), |
62 activate_over_non_cellular_networks_(false), | 64 activate_over_non_cellular_networks_(false), |
63 cellular_out_of_credits_(false) { | 65 cellular_out_of_credits_(false) { |
64 } | 66 } |
65 | 67 |
66 NetworkState::~NetworkState() { | 68 NetworkState::~NetworkState() { |
67 } | 69 } |
68 | 70 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 return false; | 112 return false; |
111 } | 113 } |
112 | 114 |
113 proxy_config_.Clear(); | 115 proxy_config_.Clear(); |
114 if (proxy_config_str.empty()) | 116 if (proxy_config_str.empty()) |
115 return true; | 117 return true; |
116 | 118 |
117 scoped_ptr<base::DictionaryValue> proxy_config_dict( | 119 scoped_ptr<base::DictionaryValue> proxy_config_dict( |
118 onc::ReadDictionaryFromJson(proxy_config_str)); | 120 onc::ReadDictionaryFromJson(proxy_config_str)); |
119 if (proxy_config_dict) { | 121 if (proxy_config_dict) { |
120 // Warning: The DictionaryValue return from | 122 // Warning: The DictionaryValue returned from |
121 // ReadDictionaryFromJson/JSONParser is an optimized derived class that | 123 // ReadDictionaryFromJson/JSONParser is an optimized derived class that |
122 // doesn't allow releasing ownership of nested values. A Swap in the wrong | 124 // doesn't allow releasing ownership of nested values. A Swap in the wrong |
123 // order leads to memory access errors. | 125 // order leads to memory access errors. |
124 proxy_config_.MergeDictionary(proxy_config_dict.get()); | 126 proxy_config_.MergeDictionary(proxy_config_dict.get()); |
125 } else { | 127 } else { |
126 LOG(WARNING) << "Failed to parse dictionary value for: " << key; | 128 LOG(WARNING) << "Failed to parse dictionary value for: " << key; |
127 } | 129 } |
128 return true; | 130 return true; |
| 131 } else if (key == flimflam::kUIDataProperty) { |
| 132 std::string ui_data_str; |
| 133 if (!value.GetAsString(&ui_data_str)) { |
| 134 LOG(WARNING) << "Failed to parse string value for:" << key; |
| 135 return false; |
| 136 } |
| 137 |
| 138 onc_source_ = onc::ONC_SOURCE_NONE; |
| 139 if (ui_data_str.empty()) |
| 140 return true; |
| 141 |
| 142 scoped_ptr<base::DictionaryValue> ui_data_dict( |
| 143 onc::ReadDictionaryFromJson(ui_data_str)); |
| 144 if (ui_data_dict) |
| 145 onc_source_ = NetworkUIData(*ui_data_dict).onc_source(); |
| 146 else |
| 147 LOG(WARNING) << "Failed to parse dictionary value for: " << key; |
| 148 return true; |
129 } else if (key == flimflam::kNetworkTechnologyProperty) { | 149 } else if (key == flimflam::kNetworkTechnologyProperty) { |
130 return GetStringValue(key, value, &technology_); | 150 return GetStringValue(key, value, &technology_); |
131 } else if (key == flimflam::kDeviceProperty) { | 151 } else if (key == flimflam::kDeviceProperty) { |
132 return GetStringValue(key, value, &device_path_); | 152 return GetStringValue(key, value, &device_path_); |
133 } else if (key == flimflam::kGuidProperty) { | 153 } else if (key == flimflam::kGuidProperty) { |
134 return GetStringValue(key, value, &guid_); | 154 return GetStringValue(key, value, &guid_); |
135 } else if (key == flimflam::kProfileProperty) { | 155 } else if (key == flimflam::kProfileProperty) { |
136 return GetStringValue(key, value, &profile_path_); | 156 return GetStringValue(key, value, &profile_path_); |
137 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 157 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
138 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 158 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 205 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
186 roaming_); | 206 roaming_); |
187 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 207 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
188 security_); | 208 security_); |
189 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, | 209 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, |
190 auto_connect_); | 210 auto_connect_); |
191 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, | 211 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, |
192 favorite_); | 212 favorite_); |
193 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, | 213 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, |
194 priority_); | 214 priority_); |
195 // Proxy config is intentionally omitted: This property is | 215 // Proxy config and ONC source are intentionally omitted: These properties are |
196 // placed in NetworkState to transition proxy configuration from | 216 // placed in NetworkState to transition ProxyConfigServiceImpl from |
197 // NetworkLibrary to the new network stack. The networking extension API | 217 // NetworkLibrary to the new network stack. The networking extension API |
198 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler | 218 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler |
199 // is used instead of NetworkLibrary, we can remove them again. | 219 // is used instead of NetworkLibrary, we can remove them again. |
200 dictionary->SetStringWithoutPathExpansion( | 220 dictionary->SetStringWithoutPathExpansion( |
201 flimflam::kNetworkTechnologyProperty, | 221 flimflam::kNetworkTechnologyProperty, |
202 technology_); | 222 technology_); |
203 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 223 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
204 device_path_); | 224 device_path_); |
205 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); | 225 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); |
206 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 226 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 connection_state == flimflam::kStateConfiguration || | 321 connection_state == flimflam::kStateConfiguration || |
302 connection_state == flimflam::kStateCarrier); | 322 connection_state == flimflam::kStateCarrier); |
303 } | 323 } |
304 | 324 |
305 // static | 325 // static |
306 std::string NetworkState::IPConfigProperty(const char* key) { | 326 std::string NetworkState::IPConfigProperty(const char* key) { |
307 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 327 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
308 } | 328 } |
309 | 329 |
310 } // namespace chromeos | 330 } // namespace chromeos |
OLD | NEW |