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

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

Issue 14566009: Add NetworkConnectionHandler class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback, remove configuration. Created 7 years, 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/managed_network_configuration_handler.h" 5 #include "chromeos/network/managed_network_configuration_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const network_handler::ErrorCallback& error_callback) { 81 const network_handler::ErrorCallback& error_callback) {
82 network_event_log::AddEntry(kLogModule, error_name, error_message); 82 network_event_log::AddEntry(kLogModule, error_name, error_message);
83 error_callback.Run( 83 error_callback.Run(
84 error_name, 84 error_name,
85 make_scoped_ptr( 85 make_scoped_ptr(
86 network_handler::CreateErrorData(service_path, 86 network_handler::CreateErrorData(service_path,
87 error_name, 87 error_name,
88 error_message))); 88 error_message)));
89 } 89 }
90 90
91 // Returns the NetworkUIData parsed from the UIData property of
92 // |shill_dictionary|. If parsing fails or the field doesn't exist, returns
93 // NULL.
94 scoped_ptr<NetworkUIData> GetUIData(
95 const base::DictionaryValue& shill_dictionary) {
96 std::string ui_data_blob;
97 if (shill_dictionary.GetStringWithoutPathExpansion(
98 flimflam::kUIDataProperty,
99 &ui_data_blob) &&
100 !ui_data_blob.empty()) {
101 scoped_ptr<base::DictionaryValue> ui_data_dict =
102 onc::ReadDictionaryFromJson(ui_data_blob);
103 if (ui_data_dict)
104 return make_scoped_ptr(new NetworkUIData(*ui_data_dict));
105 else
106 LOG(ERROR) << "UIData is not a valid JSON dictionary.";
107 }
108 return scoped_ptr<NetworkUIData>();
109 }
110
111 // Sets the UIData property in |shill_dictionary| to the serialization of 91 // Sets the UIData property in |shill_dictionary| to the serialization of
112 // |ui_data|. 92 // |ui_data|.
113 void SetUIData(const NetworkUIData& ui_data, 93 void SetUIData(const NetworkUIData& ui_data,
114 base::DictionaryValue* shill_dictionary) { 94 base::DictionaryValue* shill_dictionary) {
115 base::DictionaryValue ui_data_dict; 95 base::DictionaryValue ui_data_dict;
116 ui_data.FillDictionary(&ui_data_dict); 96 ui_data.FillDictionary(&ui_data_dict);
117 std::string ui_data_blob; 97 std::string ui_data_blob;
118 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); 98 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob);
119 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, 99 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty,
120 ui_data_blob); 100 ui_data_blob);
121 } 101 }
122 102
123 // A dummy callback to ignore the result of Shill calls. 103 // A dummy callback to ignore the result of Shill calls.
124 void IgnoreString(const std::string& str) { 104 void IgnoreString(const std::string& str) {
125 } 105 }
126 106
127 void LogErrorWithDict(const tracked_objects::Location& from_where, 107 void LogErrorWithDict(const tracked_objects::Location& from_where,
128 const std::string& error_name, 108 const std::string& error_name,
129 const scoped_ptr<base::DictionaryValue> error_data) { 109 scoped_ptr<base::DictionaryValue> error_data) {
130 LOG(ERROR) << from_where.ToString() << ": " << error_name; 110 LOG(ERROR) << from_where.ToString() << ": " << error_name;
131 } 111 }
132 112
133 void LogErrorMessage(const tracked_objects::Location& from_where, 113 void LogErrorMessage(const tracked_objects::Location& from_where,
134 const std::string& error_name, 114 const std::string& error_name,
135 const std::string& error_message) { 115 const std::string& error_message) {
136 LOG(ERROR) << from_where.ToString() << ": " << error_message; 116 LOG(ERROR) << from_where.ToString() << ": " << error_message;
137 } 117 }
138 118
139 // Removes all kFakeCredential values from sensitive fields (determined by 119 // Removes all kFakeCredential values from sensitive fields (determined by
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 201
222 scoped_ptr<base::DictionaryValue> shill_dictionary( 202 scoped_ptr<base::DictionaryValue> shill_dictionary(
223 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, 203 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature,
224 *effective)); 204 *effective));
225 205
226 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, 206 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty,
227 profile_path); 207 profile_path);
228 208
229 scoped_ptr<NetworkUIData> ui_data; 209 scoped_ptr<NetworkUIData> ui_data;
230 if (policy) 210 if (policy)
231 ui_data = CreateUIDataFromONC(onc_source, *policy); 211 ui_data = NetworkUIData::CreateUIDataFromONC(onc_source, *policy);
232 else 212 else
233 ui_data.reset(new NetworkUIData()); 213 ui_data.reset(new NetworkUIData());
234 214
235 if (settings) { 215 if (settings) {
236 // Shill doesn't know that sensitive data is contained in the UIData 216 // Shill doesn't know that sensitive data is contained in the UIData
237 // property and might write it into logs or other insecure places. Thus, we 217 // property and might write it into logs or other insecure places. Thus, we
238 // have to remove or mask credentials. 218 // have to remove or mask credentials.
239 // 219 //
240 // Shill's GetProperties doesn't return credentials. Masking credentials 220 // Shill's GetProperties doesn't return credentials. Masking credentials
241 // instead of just removing them, allows remembering if a credential is set 221 // instead of just removing them, allows remembering if a credential is set
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 delete g_configuration_handler_instance; 303 delete g_configuration_handler_instance;
324 g_configuration_handler_instance = NULL; 304 g_configuration_handler_instance = NULL;
325 } 305 }
326 306
327 // static 307 // static
328 ManagedNetworkConfigurationHandler* ManagedNetworkConfigurationHandler::Get() { 308 ManagedNetworkConfigurationHandler* ManagedNetworkConfigurationHandler::Get() {
329 CHECK(g_configuration_handler_instance); 309 CHECK(g_configuration_handler_instance);
330 return g_configuration_handler_instance; 310 return g_configuration_handler_instance;
331 } 311 }
332 312
313 // static
314 scoped_ptr<NetworkUIData> ManagedNetworkConfigurationHandler::GetUIData(
315 const base::DictionaryValue& shill_dictionary) {
316 std::string ui_data_blob;
317 if (shill_dictionary.GetStringWithoutPathExpansion(
318 flimflam::kUIDataProperty,
319 &ui_data_blob) &&
320 !ui_data_blob.empty()) {
321 scoped_ptr<base::DictionaryValue> ui_data_dict =
322 onc::ReadDictionaryFromJson(ui_data_blob);
323 if (ui_data_dict)
324 return make_scoped_ptr(new NetworkUIData(*ui_data_dict));
325 else
326 LOG(ERROR) << "UIData is not a valid JSON dictionary.";
327 }
328 LOG(ERROR) << "JSON dictionary has no UIData blob: " << shill_dictionary;
329 return scoped_ptr<NetworkUIData>();
330 }
331
333 void ManagedNetworkConfigurationHandler::GetManagedProperties( 332 void ManagedNetworkConfigurationHandler::GetManagedProperties(
334 const std::string& service_path, 333 const std::string& service_path,
335 const network_handler::DictionaryResultCallback& callback, 334 const network_handler::DictionaryResultCallback& callback,
336 const network_handler::ErrorCallback& error_callback) { 335 const network_handler::ErrorCallback& error_callback) {
337 if (!user_policies_initialized_ || !device_policies_initialized_) { 336 if (!user_policies_initialized_ || !device_policies_initialized_) {
338 RunErrorCallback(service_path, 337 RunErrorCallback(service_path,
339 kPoliciesNotInitialized, 338 kPoliciesNotInitialized,
340 kPoliciesNotInitializedMessage, 339 kPoliciesNotInitializedMessage,
341 error_callback); 340 error_callback);
342 return; 341 return;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 scoped_ptr<base::DictionaryValue> shill_dictionary( 504 scoped_ptr<base::DictionaryValue> shill_dictionary(
506 CreateShillConfiguration(state->profile_path(), guid, policy, 505 CreateShillConfiguration(state->profile_path(), guid, policy,
507 &user_settings)); 506 &user_settings));
508 507
509 NetworkConfigurationHandler::Get()->SetProperties(service_path, 508 NetworkConfigurationHandler::Get()->SetProperties(service_path,
510 *shill_dictionary, 509 *shill_dictionary,
511 callback, 510 callback,
512 error_callback); 511 error_callback);
513 } 512 }
514 513
515 void ManagedNetworkConfigurationHandler::Connect(
516 const std::string& service_path,
517 const base::Closure& callback,
518 const network_handler::ErrorCallback& error_callback) const {
519 NetworkConfigurationHandler::Get()->Connect(service_path,
520 callback,
521 error_callback);
522 }
523
524 void ManagedNetworkConfigurationHandler::Disconnect(
525 const std::string& service_path,
526 const base::Closure& callback,
527 const network_handler::ErrorCallback& error_callback) const {
528 NetworkConfigurationHandler::Get()->Disconnect(service_path,
529 callback,
530 error_callback);
531 }
532
533 void ManagedNetworkConfigurationHandler::CreateConfiguration( 514 void ManagedNetworkConfigurationHandler::CreateConfiguration(
534 const base::DictionaryValue& properties, 515 const base::DictionaryValue& properties,
535 const network_handler::StringResultCallback& callback, 516 const network_handler::StringResultCallback& callback,
536 const network_handler::ErrorCallback& error_callback) const { 517 const network_handler::ErrorCallback& error_callback) const {
537 std::string profile_path = kUserProfilePath; 518 std::string profile_path = kUserProfilePath;
538 const PolicyMap* policies_by_guid = GetPoliciesForProfile(profile_path); 519 const PolicyMap* policies_by_guid = GetPoliciesForProfile(profile_path);
539 520
540 if (!policies_by_guid) { 521 if (!policies_by_guid) {
541 RunErrorCallback("", 522 RunErrorCallback("",
542 kPoliciesNotInitialized, 523 kPoliciesNotInitialized,
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 device_policies_initialized_(false), 852 device_policies_initialized_(false),
872 weak_ptr_factory_(this) { 853 weak_ptr_factory_(this) {
873 } 854 }
874 855
875 ManagedNetworkConfigurationHandler::~ManagedNetworkConfigurationHandler() { 856 ManagedNetworkConfigurationHandler::~ManagedNetworkConfigurationHandler() {
876 STLDeleteValues(&user_policies_by_guid_); 857 STLDeleteValues(&user_policies_by_guid_);
877 STLDeleteValues(&device_policies_by_guid_); 858 STLDeleteValues(&device_policies_by_guid_);
878 } 859 }
879 860
880 } // namespace chromeos 861 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698