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/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/strings/utf_string_conversion_utils.h" | 13 #include "base/strings/utf_string_conversion_utils.h" |
14 #include "chromeos/network/network_event_log.h" | 14 #include "chromeos/network/network_event_log.h" |
15 #include "chromeos/network/network_profile_handler.h" | 15 #include "chromeos/network/network_profile_handler.h" |
16 #include "chromeos/network/network_ui_data.h" | |
17 #include "chromeos/network/network_util.h" | 16 #include "chromeos/network/network_util.h" |
18 #include "chromeos/network/onc/onc_utils.h" | 17 #include "chromeos/network/onc/onc_utils.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 22 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
24 std::vector<std::string>* result) { | 23 std::vector<std::string>* result) { |
25 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 24 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
26 std::string str; | 25 std::string str; |
(...skipping 17 matching lines...) Expand all Loading... |
44 } else { | 43 } else { |
45 const uint32 kReplacementChar = 0xFFFD; | 44 const uint32 kReplacementChar = 0xFFFD; |
46 // Puts kReplacementChar if character is a control character [0,0x20) | 45 // Puts kReplacementChar if character is a control character [0,0x20) |
47 // or is not readable UTF8. | 46 // or is not readable UTF8. |
48 base::WriteUnicodeCharacter(kReplacementChar, &result); | 47 base::WriteUnicodeCharacter(kReplacementChar, &result); |
49 } | 48 } |
50 } | 49 } |
51 return result; | 50 return result; |
52 } | 51 } |
53 | 52 |
54 // Returns a new NetworkUIData* if |ui_data_value| is a valid NetworkUIData | |
55 // dictionary string, otherwise returns NULL. | |
56 chromeos::NetworkUIData* CreateUIDataFromValue( | |
57 const base::Value& ui_data_value) { | |
58 std::string ui_data_str; | |
59 if (!ui_data_value.GetAsString(&ui_data_str)) | |
60 return NULL; | |
61 if (ui_data_str.empty()) | |
62 return new chromeos::NetworkUIData(); | |
63 | |
64 scoped_ptr<base::DictionaryValue> ui_data_dict( | |
65 chromeos::onc::ReadDictionaryFromJson(ui_data_str)); | |
66 if (!ui_data_dict) | |
67 return NULL; | |
68 return new chromeos::NetworkUIData(*ui_data_dict); | |
69 } | |
70 | |
71 } // namespace | 53 } // namespace |
72 | 54 |
73 namespace chromeos { | 55 namespace chromeos { |
74 | 56 |
75 NetworkState::NetworkState(const std::string& path) | 57 NetworkState::NetworkState(const std::string& path) |
76 : ManagedState(MANAGED_TYPE_NETWORK, path), | 58 : ManagedState(MANAGED_TYPE_NETWORK, path), |
77 auto_connect_(false), | 59 auto_connect_(false), |
78 favorite_(false), | 60 favorite_(false), |
79 priority_(0), | 61 priority_(0), |
80 onc_source_(onc::ONC_SOURCE_NONE), | |
81 prefix_length_(0), | 62 prefix_length_(0), |
82 signal_strength_(0), | 63 signal_strength_(0), |
83 connectable_(false), | 64 connectable_(false), |
84 activate_over_non_cellular_networks_(false), | 65 activate_over_non_cellular_networks_(false), |
85 cellular_out_of_credits_(false) { | 66 cellular_out_of_credits_(false) { |
86 } | 67 } |
87 | 68 |
88 NetworkState::~NetworkState() { | 69 NetworkState::~NetworkState() { |
89 } | 70 } |
90 | 71 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Warning: The DictionaryValue returned from | 126 // Warning: The DictionaryValue returned from |
146 // ReadDictionaryFromJson/JSONParser is an optimized derived class that | 127 // ReadDictionaryFromJson/JSONParser is an optimized derived class that |
147 // doesn't allow releasing ownership of nested values. A Swap in the wrong | 128 // doesn't allow releasing ownership of nested values. A Swap in the wrong |
148 // order leads to memory access errors. | 129 // order leads to memory access errors. |
149 proxy_config_.MergeDictionary(proxy_config_dict.get()); | 130 proxy_config_.MergeDictionary(proxy_config_dict.get()); |
150 } else { | 131 } else { |
151 NET_LOG_ERROR("Failed to parse " + key, path()); | 132 NET_LOG_ERROR("Failed to parse " + key, path()); |
152 } | 133 } |
153 return true; | 134 return true; |
154 } else if (key == flimflam::kUIDataProperty) { | 135 } else if (key == flimflam::kUIDataProperty) { |
155 if (!GetOncSource(value, &onc_source_)) { | 136 if (!GetUIDataFromValue(value, &ui_data_)) { |
156 NET_LOG_ERROR("Failed to parse " + key, path()); | 137 NET_LOG_ERROR("Failed to parse " + key, path()); |
157 return false; | 138 return false; |
158 } | 139 } |
159 return true; | 140 return true; |
160 } else if (key == flimflam::kNetworkTechnologyProperty) { | 141 } else if (key == flimflam::kNetworkTechnologyProperty) { |
161 return GetStringValue(key, value, &network_technology_); | 142 return GetStringValue(key, value, &network_technology_); |
162 } else if (key == flimflam::kDeviceProperty) { | 143 } else if (key == flimflam::kDeviceProperty) { |
163 return GetStringValue(key, value, &device_path_); | 144 return GetStringValue(key, value, &device_path_); |
164 } else if (key == flimflam::kGuidProperty) { | 145 } else if (key == flimflam::kGuidProperty) { |
165 return GetStringValue(key, value, &guid_); | 146 return GetStringValue(key, value, &guid_); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 253 |
273 bool NetworkState::IsConnectedState() const { | 254 bool NetworkState::IsConnectedState() const { |
274 return StateIsConnected(connection_state_); | 255 return StateIsConnected(connection_state_); |
275 } | 256 } |
276 | 257 |
277 bool NetworkState::IsConnectingState() const { | 258 bool NetworkState::IsConnectingState() const { |
278 return StateIsConnecting(connection_state_); | 259 return StateIsConnecting(connection_state_); |
279 } | 260 } |
280 | 261 |
281 bool NetworkState::IsManaged() const { | 262 bool NetworkState::IsManaged() const { |
282 return onc_source_ == onc::ONC_SOURCE_DEVICE_POLICY || | 263 return ui_data_.onc_source() == onc::ONC_SOURCE_DEVICE_POLICY || |
283 onc_source_ == onc::ONC_SOURCE_USER_POLICY; | 264 ui_data_.onc_source() == onc::ONC_SOURCE_USER_POLICY; |
284 } | 265 } |
285 | 266 |
286 bool NetworkState::IsPrivate() const { | 267 bool NetworkState::IsPrivate() const { |
287 return !profile_path_.empty() && | 268 return !profile_path_.empty() && |
288 profile_path_ != NetworkProfileHandler::kSharedProfilePath; | 269 profile_path_ != NetworkProfileHandler::kSharedProfilePath; |
289 } | 270 } |
290 | 271 |
291 std::string NetworkState::GetDnsServersAsString() const { | 272 std::string NetworkState::GetDnsServersAsString() const { |
292 std::string result; | 273 std::string result; |
293 for (size_t i = 0; i < dns_servers_.size(); ++i) { | 274 for (size_t i = 0; i < dns_servers_.size(); ++i) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 connection_state == flimflam::kStateConfiguration || | 369 connection_state == flimflam::kStateConfiguration || |
389 connection_state == flimflam::kStateCarrier); | 370 connection_state == flimflam::kStateCarrier); |
390 } | 371 } |
391 | 372 |
392 // static | 373 // static |
393 std::string NetworkState::IPConfigProperty(const char* key) { | 374 std::string NetworkState::IPConfigProperty(const char* key) { |
394 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 375 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
395 } | 376 } |
396 | 377 |
397 // static | 378 // static |
398 bool NetworkState::GetOncSource(const base::Value& ui_data_value, | 379 bool NetworkState::GetUIDataFromValue(const base::Value& ui_data_value, |
399 onc::ONCSource* out) { | 380 NetworkUIData* out) { |
400 scoped_ptr<NetworkUIData> ui_data(CreateUIDataFromValue(ui_data_value)); | 381 std::string ui_data_str; |
401 if (!ui_data) | 382 if (!ui_data_value.GetAsString(&ui_data_str)) |
402 return false; | 383 return false; |
403 *out = ui_data->onc_source(); | 384 if (ui_data_str.empty()) { |
| 385 *out = NetworkUIData(); |
| 386 return true; |
| 387 } |
| 388 scoped_ptr<base::DictionaryValue> ui_data_dict( |
| 389 chromeos::onc::ReadDictionaryFromJson(ui_data_str)); |
| 390 if (!ui_data_dict) |
| 391 return false; |
| 392 *out = NetworkUIData(*ui_data_dict); |
404 return true; | 393 return true; |
405 } | 394 } |
406 | 395 |
407 } // namespace chromeos | 396 } // namespace chromeos |
OLD | NEW |