Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chromeos/network/network_state.cc

Issue 21046008: Convert all connect code to use NetworkHandler instead of NetworkLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/network/network_state.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 bool IsCaCertNssSet(const base::DictionaryValue& properties) { 53 bool IsCaCertNssSet(const base::DictionaryValue& properties) {
72 std::string ca_cert_nss; 54 std::string ca_cert_nss;
73 if (properties.GetStringWithoutPathExpansion(flimflam::kEapCaCertNssProperty, 55 if (properties.GetStringWithoutPathExpansion(flimflam::kEapCaCertNssProperty,
74 &ca_cert_nss) && 56 &ca_cert_nss) &&
75 !ca_cert_nss.empty()) { 57 !ca_cert_nss.empty()) {
76 return true; 58 return true;
77 } 59 }
78 60
79 const base::DictionaryValue* provider = NULL; 61 const base::DictionaryValue* provider = NULL;
80 properties.GetDictionaryWithoutPathExpansion(flimflam::kProviderProperty, 62 properties.GetDictionaryWithoutPathExpansion(flimflam::kProviderProperty,
(...skipping 16 matching lines...) Expand all
97 79
98 } // namespace 80 } // namespace
99 81
100 namespace chromeos { 82 namespace chromeos {
101 83
102 NetworkState::NetworkState(const std::string& path) 84 NetworkState::NetworkState(const std::string& path)
103 : ManagedState(MANAGED_TYPE_NETWORK, path), 85 : ManagedState(MANAGED_TYPE_NETWORK, path),
104 auto_connect_(false), 86 auto_connect_(false),
105 favorite_(false), 87 favorite_(false),
106 priority_(0), 88 priority_(0),
107 onc_source_(onc::ONC_SOURCE_NONE),
108 prefix_length_(0), 89 prefix_length_(0),
109 signal_strength_(0), 90 signal_strength_(0),
110 connectable_(false), 91 connectable_(false),
111 activate_over_non_cellular_networks_(false), 92 activate_over_non_cellular_networks_(false),
112 cellular_out_of_credits_(false), 93 cellular_out_of_credits_(false),
113 has_ca_cert_nss_(false) { 94 has_ca_cert_nss_(false) {
114 } 95 }
115 96
116 NetworkState::~NetworkState() { 97 NetworkState::~NetworkState() {
117 } 98 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Warning: The DictionaryValue returned from 154 // Warning: The DictionaryValue returned from
174 // ReadDictionaryFromJson/JSONParser is an optimized derived class that 155 // ReadDictionaryFromJson/JSONParser is an optimized derived class that
175 // doesn't allow releasing ownership of nested values. A Swap in the wrong 156 // doesn't allow releasing ownership of nested values. A Swap in the wrong
176 // order leads to memory access errors. 157 // order leads to memory access errors.
177 proxy_config_.MergeDictionary(proxy_config_dict.get()); 158 proxy_config_.MergeDictionary(proxy_config_dict.get());
178 } else { 159 } else {
179 NET_LOG_ERROR("Failed to parse " + key, path()); 160 NET_LOG_ERROR("Failed to parse " + key, path());
180 } 161 }
181 return true; 162 return true;
182 } else if (key == flimflam::kUIDataProperty) { 163 } else if (key == flimflam::kUIDataProperty) {
183 if (!GetOncSource(value, &onc_source_)) { 164 if (!GetUIDataFromValue(value, &ui_data_)) {
184 NET_LOG_ERROR("Failed to parse " + key, path()); 165 NET_LOG_ERROR("Failed to parse " + key, path());
185 return false; 166 return false;
186 } 167 }
187 return true; 168 return true;
188 } else if (key == flimflam::kNetworkTechnologyProperty) { 169 } else if (key == flimflam::kNetworkTechnologyProperty) {
189 return GetStringValue(key, value, &network_technology_); 170 return GetStringValue(key, value, &network_technology_);
190 } else if (key == flimflam::kDeviceProperty) { 171 } else if (key == flimflam::kDeviceProperty) {
191 return GetStringValue(key, value, &device_path_); 172 return GetStringValue(key, value, &device_path_);
192 } else if (key == flimflam::kGuidProperty) { 173 } else if (key == flimflam::kGuidProperty) {
193 return GetStringValue(key, value, &guid_); 174 return GetStringValue(key, value, &guid_);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 284
304 bool NetworkState::IsConnectedState() const { 285 bool NetworkState::IsConnectedState() const {
305 return StateIsConnected(connection_state_); 286 return StateIsConnected(connection_state_);
306 } 287 }
307 288
308 bool NetworkState::IsConnectingState() const { 289 bool NetworkState::IsConnectingState() const {
309 return StateIsConnecting(connection_state_); 290 return StateIsConnecting(connection_state_);
310 } 291 }
311 292
312 bool NetworkState::IsManaged() const { 293 bool NetworkState::IsManaged() const {
313 return onc_source_ == onc::ONC_SOURCE_DEVICE_POLICY || 294 return ui_data_.onc_source() == onc::ONC_SOURCE_DEVICE_POLICY ||
314 onc_source_ == onc::ONC_SOURCE_USER_POLICY; 295 ui_data_.onc_source() == onc::ONC_SOURCE_USER_POLICY;
315 } 296 }
316 297
317 bool NetworkState::IsPrivate() const { 298 bool NetworkState::IsPrivate() const {
318 return !profile_path_.empty() && 299 return !profile_path_.empty() &&
319 profile_path_ != NetworkProfileHandler::kSharedProfilePath; 300 profile_path_ != NetworkProfileHandler::kSharedProfilePath;
320 } 301 }
321 302
322 std::string NetworkState::GetDnsServersAsString() const { 303 std::string NetworkState::GetDnsServersAsString() const {
323 std::string result; 304 std::string result;
324 for (size_t i = 0; i < dns_servers_.size(); ++i) { 305 for (size_t i = 0; i < dns_servers_.size(); ++i) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 connection_state == flimflam::kStateConfiguration || 406 connection_state == flimflam::kStateConfiguration ||
426 connection_state == flimflam::kStateCarrier); 407 connection_state == flimflam::kStateCarrier);
427 } 408 }
428 409
429 // static 410 // static
430 std::string NetworkState::IPConfigProperty(const char* key) { 411 std::string NetworkState::IPConfigProperty(const char* key) {
431 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); 412 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key);
432 } 413 }
433 414
434 // static 415 // static
435 bool NetworkState::GetOncSource(const base::Value& ui_data_value, 416 bool NetworkState::GetUIDataFromValue(const base::Value& ui_data_value,
436 onc::ONCSource* out) { 417 NetworkUIData* out) {
437 scoped_ptr<NetworkUIData> ui_data(CreateUIDataFromValue(ui_data_value)); 418 std::string ui_data_str;
438 if (!ui_data) 419 if (!ui_data_value.GetAsString(&ui_data_str))
439 return false; 420 return false;
440 *out = ui_data->onc_source(); 421 if (ui_data_str.empty()) {
422 *out = NetworkUIData();
423 return true;
424 }
425 scoped_ptr<base::DictionaryValue> ui_data_dict(
426 chromeos::onc::ReadDictionaryFromJson(ui_data_str));
427 if (!ui_data_dict)
428 return false;
429 *out = NetworkUIData(*ui_data_dict);
441 return true; 430 return true;
442 } 431 }
443 432
444 } // namespace chromeos 433 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698