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

Side by Side Diff: chrome/browser/chromeos/cros/onc_network_parser.cc

Issue 8804020: Set onc_source UI data parameter when importing ONC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, remove ONC data from ui data. Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/cros/onc_network_parser.h" 5 #include "chrome/browser/chromeos/cros/onc_network_parser.h"
6 6
7 #include <keyhi.h>
7 #include <pk11pub.h> 8 #include <pk11pub.h>
8 #include <keyhi.h>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/json/json_value_serializer.h" 11 #include "base/json/json_value_serializer.h"
12 #include "base/json/json_writer.h" // for debug output only. 12 #include "base/json/json_writer.h" // for debug output only.
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chromeos/cros/native_network_constants.h" 15 #include "chrome/browser/chromeos/cros/native_network_constants.h"
16 #include "chrome/browser/chromeos/cros/native_network_parser.h" 16 #include "chrome/browser/chromeos/cros/native_network_parser.h"
17 #include "chrome/browser/chromeos/cros/network_library.h" 17 #include "chrome/browser/chromeos/cros/network_library.h"
18 #include "net/base/cert_database.h" 18 #include "net/base/cert_database.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 std::string ConvertValueToString(const base::Value& value) { 176 std::string ConvertValueToString(const base::Value& value) {
177 std::string value_json; 177 std::string value_json;
178 base::JSONWriter::Write(&value, false, &value_json); 178 base::JSONWriter::Write(&value, false, &value_json);
179 return value_json; 179 return value_json;
180 } 180 }
181 181
182 } // namespace 182 } // namespace
183 183
184 // -------------------- OncNetworkParser -------------------- 184 // -------------------- OncNetworkParser --------------------
185 185
186 OncNetworkParser::OncNetworkParser(const std::string& onc_blob) 186 OncNetworkParser::OncNetworkParser(const std::string& onc_blob,
187 NetworkUIData::ONCSource onc_source)
187 : NetworkParser(get_onc_mapper()), 188 : NetworkParser(get_onc_mapper()),
189 onc_source_(onc_source),
188 network_configs_(NULL), 190 network_configs_(NULL),
189 certificates_(NULL) { 191 certificates_(NULL) {
190 VLOG(2) << __func__ << ": OncNetworkParser called on " << onc_blob; 192 VLOG(2) << __func__ << ": OncNetworkParser called on " << onc_blob;
191 JSONStringValueSerializer deserializer(onc_blob); 193 JSONStringValueSerializer deserializer(onc_blob);
192 deserializer.set_allow_trailing_comma(true); 194 deserializer.set_allow_trailing_comma(true);
193 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &parse_error_)); 195 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &parse_error_));
194 196
195 if (!root.get() || root->GetType() != base::Value::TYPE_DICTIONARY) { 197 if (!root.get() || root->GetType() != base::Value::TYPE_DICTIONARY) {
196 LOG(WARNING) << "OncNetworkParser received bad ONC file: " << parse_error_; 198 LOG(WARNING) << "OncNetworkParser received bad ONC file: " << parse_error_;
197 } else { 199 } else {
(...skipping 25 matching lines...) Expand all
223 } 225 }
224 226
225 int OncNetworkParser::GetNetworkConfigsSize() const { 227 int OncNetworkParser::GetNetworkConfigsSize() const {
226 return network_configs_ ? network_configs_->GetSize() : 0; 228 return network_configs_ ? network_configs_->GetSize() : 0;
227 } 229 }
228 230
229 int OncNetworkParser::GetCertificatesSize() const { 231 int OncNetworkParser::GetCertificatesSize() const {
230 return certificates_ ? certificates_->GetSize() : 0; 232 return certificates_ ? certificates_->GetSize() : 0;
231 } 233 }
232 234
235 Network* OncNetworkParser::ParseNetwork(int n) {
kmixter1 2011/12/13 01:44:07 Why the reordering of ParseNetwork and ParseCertif
Mattias Nissler (ping if slow) 2011/12/13 13:52:19 This was in an effort to re-synchronize the orderi
236 if (!network_configs_)
237 return NULL;
238 DictionaryValue* info = NULL;
239 if (!network_configs_->GetDictionary(n, &info))
240 return NULL;
241 if (VLOG_IS_ON(2)) {
242 std::string network_json;
243 base::JSONWriter::Write(static_cast<base::Value*>(info),
244 true, &network_json);
245 VLOG(2) << "Parsing network at index " << n
246 << ": " << network_json;
247 }
248
249 return CreateNetworkFromInfo(std::string(), *info);
250 }
251
233 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseCertificate( 252 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseCertificate(
234 int cert_index) { 253 int cert_index) {
235 CHECK(certificates_); 254 CHECK(certificates_);
236 CHECK(static_cast<size_t>(cert_index) < certificates_->GetSize()); 255 CHECK(static_cast<size_t>(cert_index) < certificates_->GetSize());
237 CHECK(cert_index >= 0); 256 CHECK(cert_index >= 0);
238 base::DictionaryValue* certificate = NULL; 257 base::DictionaryValue* certificate = NULL;
239 certificates_->GetDictionary(cert_index, &certificate); 258 certificates_->GetDictionary(cert_index, &certificate);
240 CHECK(certificate); 259 CHECK(certificate);
241 260
242 if (VLOG_IS_ON(2)) { 261 if (VLOG_IS_ON(2)) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 294 }
276 if (cert_type == "Client") { 295 if (cert_type == "Client") {
277 return ParseClientCertificate(cert_index, guid, certificate); 296 return ParseClientCertificate(cert_index, guid, certificate);
278 } 297 }
279 298
280 LOG(WARNING) << "ONC File: certificate of unknown type: " << cert_type 299 LOG(WARNING) << "ONC File: certificate of unknown type: " << cert_type
281 << " at index " << cert_index; 300 << " at index " << cert_index;
282 return NULL; 301 return NULL;
283 } 302 }
284 303
285 Network* OncNetworkParser::ParseNetwork(int n) {
286 if (!network_configs_)
287 return NULL;
288 DictionaryValue* info = NULL;
289 if (!network_configs_->GetDictionary(n, &info))
290 return NULL;
291 if (VLOG_IS_ON(2)) {
292 std::string network_json;
293 base::JSONWriter::Write(static_cast<base::Value*>(info),
294 true, &network_json);
295 VLOG(2) << "Parsing network at index " << n
296 << ": " << network_json;
297 }
298
299 return CreateNetworkFromInfo(std::string(), *info);
300 }
301
302 Network* OncNetworkParser::CreateNetworkFromInfo( 304 Network* OncNetworkParser::CreateNetworkFromInfo(
303 const std::string& service_path, 305 const std::string& service_path,
304 const DictionaryValue& info) { 306 const DictionaryValue& info) {
305 ConnectionType type = ParseTypeFromDictionary(info); 307 ConnectionType type = ParseTypeFromDictionary(info);
306 if (type == TYPE_UNKNOWN) // Return NULL if cannot parse network type. 308 if (type == TYPE_UNKNOWN) // Return NULL if cannot parse network type.
307 return NULL; 309 return NULL;
308 scoped_ptr<Network> network(CreateNewNetwork(type, service_path)); 310 scoped_ptr<Network> network(CreateNewNetwork(type, service_path));
311
312 // Initialize UI data.
313 NetworkUIData ui_data;
314 ui_data.set_onc_source(onc_source_);
315 ui_data.FillDictionary(network->ui_data());
kmixter1 2011/12/13 01:44:07 This name could be more descriptive.
Mattias Nissler (ping if slow) 2011/12/13 13:52:19 What name? FillDictionary? ui_data()? I'm not foll
kmixter1 2011/12/13 19:21:03 FillDictionary. I think I didn't understand how t
Mattias Nissler (ping if slow) 2011/12/14 20:46:37 Put in the Clear() call.
316
317 // Copy ONC to the network object.
318 network->onc()->MergeDictionary(&info);
kmixter1 2011/12/13 01:44:07 Seems like merging isn't what you want. Don't you
Mattias Nissler (ping if slow) 2011/12/13 13:52:19 We created a new network in line 310, so merging i
kmixter1 2011/12/13 19:21:03 Agreed - Didn't look far enough up. Could you men
Mattias Nissler (ping if slow) 2011/12/14 20:46:37 Done.
319
320 // Parse all properties recursively.
309 if (!ParseNestedObject(network.get(), 321 if (!ParseNestedObject(network.get(),
310 "NetworkConfiguration", 322 "NetworkConfiguration",
311 static_cast<const base::Value&>(info), 323 static_cast<const base::Value&>(info),
312 network_configuration_signature, 324 network_configuration_signature,
313 ParseNetworkConfigurationValue)) { 325 ParseNetworkConfigurationValue)) {
314 LOG(WARNING) << "Network " << network->name() << " failed to parse."; 326 LOG(WARNING) << "Network " << network->name() << " failed to parse.";
315 return NULL; 327 return NULL;
316 } 328 }
329
330 // Update the UI data property.
331 std::string ui_data_json;
332 base::JSONWriter::Write(network->ui_data(), false, &ui_data_json);
333 base::StringValue ui_data_string_value(ui_data_json);
334 network->UpdatePropertyMap(PROPERTY_INDEX_UI_DATA, ui_data_string_value);
kmixter1 2011/12/13 01:44:07 What things are still stored in ui_data?
Mattias Nissler (ping if slow) 2011/12/13 13:52:19 Only the ONC source, which must go to ui_data, sin
335
317 if (VLOG_IS_ON(2)) { 336 if (VLOG_IS_ON(2)) {
318 VLOG(2) << "Created Network '" << network->name() 337 VLOG(2) << "Created Network '" << network->name()
319 << "' from info. Path:" << service_path 338 << "' from info. Path:" << service_path
320 << " Type:" << ConnectionTypeToString(type); 339 << " Type:" << ConnectionTypeToString(type);
321 } 340 }
341
322 return network.release(); 342 return network.release();
323 } 343 }
324 344
325 Network* OncNetworkParser::CreateNewNetwork( 345 Network* OncNetworkParser::CreateNewNetwork(
326 ConnectionType type, const std::string& service_path) { 346 ConnectionType type, const std::string& service_path) {
327 Network* network = NetworkParser::CreateNewNetwork(type, service_path); 347 Network* network = NetworkParser::CreateNewNetwork(type, service_path);
328 if (network) { 348 if (network) {
329 if (type == TYPE_WIFI) 349 if (type == TYPE_WIFI)
330 network->SetNetworkParser(new OncWifiNetworkParser()); 350 network->SetNetworkParser(new OncWifiNetworkParser());
331 else if (type == TYPE_VPN) 351 else if (type == TYPE_VPN)
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 if (!value.IsType(base::Value::TYPE_DICTIONARY)) { 535 if (!value.IsType(base::Value::TYPE_DICTIONARY)) {
516 VLOG(1) << network->name() << ": expected object of type " << onc_type; 536 VLOG(1) << network->name() << ": expected object of type " << onc_type;
517 return false; 537 return false;
518 } 538 }
519 VLOG(2) << "Parsing nested object of type " << onc_type; 539 VLOG(2) << "Parsing nested object of type " << onc_type;
520 const DictionaryValue* dict = NULL; 540 const DictionaryValue* dict = NULL;
521 value.GetAsDictionary(&dict); 541 value.GetAsDictionary(&dict);
522 for (DictionaryValue::key_iterator iter = dict->begin_keys(); 542 for (DictionaryValue::key_iterator iter = dict->begin_keys();
523 iter != dict->end_keys(); ++iter) { 543 iter != dict->end_keys(); ++iter) {
524 const std::string& key = *iter; 544 const std::string& key = *iter;
545 if (key == "Recommended")
kmixter1 2011/12/13 01:44:07 Maybe a comment of where this key is handled?
Mattias Nissler (ping if slow) 2011/12/13 13:52:19 Done.
546 continue;
547
525 base::Value* inner_value = NULL; 548 base::Value* inner_value = NULL;
526 dict->GetWithoutPathExpansion(key, &inner_value); 549 dict->GetWithoutPathExpansion(key, &inner_value);
527 CHECK(inner_value != NULL); 550 CHECK(inner_value != NULL);
528 int field_index; 551 int field_index;
529 for (field_index = 0; signature[field_index].field != NULL; ++field_index) { 552 for (field_index = 0; signature[field_index].field != NULL; ++field_index) {
530 if (key == signature[field_index].field) 553 if (key == signature[field_index].field)
531 break; 554 break;
532 } 555 }
533 if (signature[field_index].field == NULL) { 556 if (signature[field_index].field == NULL) {
534 VLOG(1) << network->name() << ": unexpected field: " 557 VLOG(1) << network->name() << ": unexpected field: "
(...skipping 10 matching lines...) Expand all
545 } 568 }
546 PropertyIndex index = signature[field_index].index; 569 PropertyIndex index = signature[field_index].index;
547 // We need to UpdatePropertyMap now since parser might want to 570 // We need to UpdatePropertyMap now since parser might want to
548 // change the mapped value. 571 // change the mapped value.
549 network->UpdatePropertyMap(index, *inner_value); 572 network->UpdatePropertyMap(index, *inner_value);
550 if (!parser(this, index, *inner_value, network)) { 573 if (!parser(this, index, *inner_value, network)) {
551 VLOG(1) << network->name() << ": field not parsed: " << key; 574 VLOG(1) << network->name() << ": field not parsed: " << key;
552 any_errors = true; 575 any_errors = true;
553 continue; 576 continue;
554 } 577 }
578
555 if (VLOG_IS_ON(2)) { 579 if (VLOG_IS_ON(2)) {
556 std::string value_json; 580 std::string value_json;
557 base::JSONWriter::Write(inner_value, true, &value_json); 581 base::JSONWriter::Write(inner_value, true, &value_json);
558 VLOG(2) << network->name() << ": Successfully parsed [" << key 582 VLOG(2) << network->name() << ": Successfully parsed [" << key
559 << "(" << index << ")] = " << value_json; 583 << "(" << index << ")] = " << value_json;
560 } 584 }
561 } 585 }
562 return !any_errors; 586 return !any_errors;
563 } 587 }
564 588
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 // on the value of AuthenticationType. 1174 // on the value of AuthenticationType.
1151 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, 1175 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK },
1152 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, 1176 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN },
1153 }; 1177 };
1154 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, 1178 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser,
1155 (table, arraysize(table), PROVIDER_TYPE_MAX)); 1179 (table, arraysize(table), PROVIDER_TYPE_MAX));
1156 return parser.Get(type); 1180 return parser.Get(type);
1157 } 1181 }
1158 1182
1159 } // namespace chromeos 1183 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698