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

Unified Diff: chrome/browser/chromeos/cros/network_ui_data.cc

Issue 8728030: Infrastructure for accessing and manipulating network UI data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile problem. Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/cros/network_ui_data.cc
diff --git a/chrome/browser/chromeos/cros/network_ui_data.cc b/chrome/browser/chromeos/cros/network_ui_data.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f1d880bc5c216f9f70616223fa895406d3a72197
--- /dev/null
+++ b/chrome/browser/chromeos/cros/network_ui_data.cc
@@ -0,0 +1,179 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/cros/network_ui_data.h"
+
+#include "base/logging.h"
+#include "chrome/browser/chromeos/cros/network_library.h"
+#include "chrome/browser/chromeos/cros/network_parser.h"
+
+namespace chromeos {
+
+namespace {
+
+const EnumMapper<NetworkUIData::ONCSource>::Pair kONCSourceTable[] = {
+ { "user_import", NetworkUIData::ONC_SOURCE_USER_IMPORT },
+ { "device_policy", NetworkUIData::ONC_SOURCE_DEVICE_POLICY },
+ { "user_policy", NetworkUIData::ONC_SOURCE_USER_POLICY },
+};
+
+const EnumMapper<NetworkPropertyUIData::Controller>::Pair
+ kControllerTable[] = {
+ { "user", NetworkPropertyUIData::CONTROLLER_USER },
+ { "policy", NetworkPropertyUIData::CONTROLLER_POLICY },
+};
+
+}
+
+const char NetworkUIData::kKeyONCSource[] = "onc_source";
+const char NetworkUIData::kKeyProperties[] = "properties";
+
+// Property names for per-property data stored under |kKeyProperties|.
+const char NetworkUIData::kPropertyAutoConnect[] = "auto_connect";
+const char NetworkUIData::kPropertyPreferred[] = "preferred";
+const char NetworkUIData::kPropertyPassphrase[] = "passphrase";
+const char NetworkUIData::kPropertySaveCredentials[] = "save_credentials";
+
+const char NetworkUIData::kPropertyVPNCaCertNss[] = "VPN.ca_cert_nss";
+const char NetworkUIData::kPropertyVPNPskPassphrase[] = "VPN.psk_passphrase";
+const char NetworkUIData::kPropertyVPNClientCertId[] = "VPN.client_cert_id";
+const char NetworkUIData::kPropertyVPNUsername[] = "VPN.username";
+const char NetworkUIData::kPropertyVPNUserPassphrase[] = "VPN.user_passphrase";
+const char NetworkUIData::kPropertyVPNGroupName[] = "VPN.group_name";
+
+const char NetworkUIData::kPropertyEAPMethod[] = "EAP.method";
+const char NetworkUIData::kPropertyEAPPhase2Auth[] = "EAP.phase_2_auth";
+const char NetworkUIData::kPropertyEAPServerCaCertNssNickname[] =
+ "EAP.server_ca_cert_nss_nickname";
+const char NetworkUIData::kPropertyEAPClientCertPkcs11Id[] =
+ "EAP.client_cert_pkcs11_id";
+const char NetworkUIData::kPropertyEAPUseSystemCAs[] = "EAP.use_system_cas";
+const char NetworkUIData::kPropertyEAPIdentity[] = "EAP.identity";
+const char NetworkUIData::kPropertyEAPAnonymousIdentity[] =
+ "EAP.anonymous_identity";
+const char NetworkUIData::kPropertyEAPPassphrase[] = "EAP.passphrase";
+
+// Property names for the per-property dictionary.
+const char NetworkPropertyUIData::kKeyController[] = "controller";
+const char NetworkPropertyUIData::kKeyDefaultValue[] = "default_value";
+
+NetworkUIData::NetworkUIData()
+ : source_(ONC_SOURCE_NONE) {}
+
+void NetworkUIData::SetProperty(const char* property_key,
+ const NetworkPropertyUIData& ui_data) {
+ properties_.Set(property_key, ui_data.BuildDictionary());
+}
+
+void NetworkUIData::FillDictionary(base::DictionaryValue* dict) const {
+ std::string source_string = EncodeONCSource(source_);
+ if (!source_string.empty())
+ dict->SetString(kKeyONCSource, source_string);
+ dict->Set(kKeyProperties, properties_.DeepCopy());
+}
+
+// static
+NetworkUIData::ONCSource NetworkUIData::GetONCSource(const Network* network) {
+ std::string source;
+ if (network->ui_data()->GetString(kKeyONCSource, &source))
+ return DecodeONCSource(source);
+ return ONC_SOURCE_NONE;
+}
+
+// static
+bool NetworkUIData::IsManaged(const Network* network) {
+ ONCSource source = GetONCSource(network);
+ return source == ONC_SOURCE_DEVICE_POLICY || source == ONC_SOURCE_USER_POLICY;
+}
+
+// static
+std::string NetworkUIData::EncodeONCSource(ONCSource source) {
+ EnumMapper<ONCSource> mapper(kONCSourceTable, arraysize(kONCSourceTable),
+ ONC_SOURCE_NONE);
stevenjb 2011/11/29 17:35:16 Use CR_DEFINE_STATIC_LOCAL to make this static so
Mattias Nissler (ping if slow) 2011/11/29 20:48:47 Done.
+ std::string source_string;
+ if (!mapper.GetKey(source, &source_string))
+ NOTREACHED() << "Invalid ONC source value " << source;
+ return source_string;
+}
+
+// static
+NetworkUIData::ONCSource NetworkUIData::DecodeONCSource(
+ const std::string& source) {
+ EnumMapper<ONCSource> mapper(kONCSourceTable, arraysize(kONCSourceTable),
+ ONC_SOURCE_NONE);
+ return mapper.Get(source);
+}
+
+NetworkPropertyUIData::NetworkPropertyUIData()
+ : controller_(CONTROLLER_USER) {}
stevenjb 2011/11/29 17:35:16 nit: } on a separate line is easier to read outsid
Mattias Nissler (ping if slow) 2011/11/29 20:48:47 Some people prefer one style, some people the othe
+
+NetworkPropertyUIData::NetworkPropertyUIData(Controller controller,
+ base::Value* default_value)
+ : controller_(controller),
+ default_value_(default_value) {}
+
+NetworkPropertyUIData::NetworkPropertyUIData(const Network* network,
+ const char* property_key) {
+ UpdateFromNetwork(network, property_key);
+}
+
+void NetworkPropertyUIData::UpdateFromNetwork(const Network* network,
+ const char* property_key) {
+ // If there is no per-property information available, the property inherits
+ // the controlled state of the network.
+ controller_ =
+ NetworkUIData::IsManaged(network) ? CONTROLLER_POLICY : CONTROLLER_USER;
+
+ if (!property_key)
+ return;
+
+ const base::DictionaryValue* ui_data = network->ui_data();
+ if (!ui_data)
+ return;
+
+ base::DictionaryValue* property_map = NULL;
+ if (!ui_data->GetDictionary(NetworkUIData::kKeyProperties, &property_map))
+ return;
+
+ base::DictionaryValue* property = NULL;
+ if (!property_map->GetDictionary(property_key, &property))
+ return;
+
+ std::string controller;
+ if (property->GetString(kKeyController, &controller))
+ controller_ = DecodeController(controller);
+
+ base::Value* default_value = NULL;
+ property->Get(kKeyDefaultValue, &default_value);
+ default_value_.reset(default_value);
stevenjb 2011/11/29 17:35:16 Do we always want to reset default_value, even if
Mattias Nissler (ping if slow) 2011/11/29 20:48:47 Done.
+}
+
+base::DictionaryValue* NetworkPropertyUIData::BuildDictionary() const {
+ base::DictionaryValue* dict = new base::DictionaryValue();
+ dict->SetString(kKeyController,
+ EncodeController(controller_));
+ if (default_value_.get())
+ dict->Set(kKeyDefaultValue, default_value_->DeepCopy());
+ return dict;
+}
+
+// static
+std::string NetworkPropertyUIData::EncodeController(Controller controller) {
stevenjb 2011/11/29 17:35:16 Are we likely to need these outside of this class?
Mattias Nissler (ping if slow) 2011/11/29 20:48:47 Done.
stevenjb 2011/11/29 23:39:05 What I meant to suggest was that, rather than expo
Mattias Nissler (ping if slow) 2011/11/30 10:16:47 Ah, the reason I decided to leave as is is that pr
+ EnumMapper<Controller> mapper(kControllerTable, arraysize(kControllerTable),
+ CONTROLLER_USER);
+ std::string controller_string;
+ if (!mapper.GetKey(controller, &controller_string))
+ NOTREACHED() << "Invalid property controller value " << controller;
+ return controller_string;
+}
+
+// static
+NetworkPropertyUIData::Controller NetworkPropertyUIData::DecodeController(
+ const std::string& controller) {
+ EnumMapper<Controller> mapper(kControllerTable, arraysize(kControllerTable),
+ CONTROLLER_USER);
+ return mapper.Get(controller);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698