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

Unified Diff: chromeos/network/network_ui_data.cc

Issue 13454006: Moving ManagedNetworkConfigurationHandler to chromeos/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up parsing of NetworkUIData. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/network/network_ui_data.h ('k') | chromeos/network/network_ui_data_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/network_ui_data.cc
diff --git a/chrome/browser/chromeos/net/onc_utils.cc b/chromeos/network/network_ui_data.cc
similarity index 34%
copy from chrome/browser/chromeos/net/onc_utils.cc
copy to chromeos/network/network_ui_data.cc
index e9464b1138451adbaf5644daac0bf8c445f515c7..334589520eafb9eb458bffe0006c9e0410a880c7 100644
--- a/chrome/browser/chromeos/net/onc_utils.cc
+++ b/chromeos/network/network_ui_data.cc
@@ -2,139 +2,127 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/chromeos/net/onc_utils.h"
+#include "chromeos/network/network_ui_data.h"
+#include "base/logging.h"
#include "base/values.h"
-#include "chrome/browser/chromeos/cros/network_ui_data.h"
-#include "chrome/browser/chromeos/proxy_config_service_impl.h"
-#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chromeos/network/onc/onc_signature.h"
-#include "chromeos/network/onc/onc_utils.h"
-#include "googleurl/src/gurl.h"
-#include "net/proxy/proxy_server.h"
namespace chromeos {
-namespace onc {
-namespace {
+// Top-level UI data dictionary keys.
+const char NetworkUIData::kKeyONCSource[] = "onc_source";
+const char NetworkUIData::kKeyCertificatePattern[] = "certificate_pattern";
+const char NetworkUIData::kKeyCertificateType[] = "certificate_type";
-net::ProxyServer ConvertOncProxyLocationToHostPort(
- net::ProxyServer::Scheme default_proxy_scheme,
- const base::DictionaryValue& onc_proxy_location) {
- std::string host;
- onc_proxy_location.GetStringWithoutPathExpansion(onc::proxy::kHost, &host);
- // Parse |host| according to the format [<scheme>"://"]<server>[":"<port>].
- net::ProxyServer proxy_server =
- net::ProxyServer::FromURI(host, default_proxy_scheme);
- int port = 0;
- onc_proxy_location.GetIntegerWithoutPathExpansion(onc::proxy::kPort, &port);
-
- // Replace the port parsed from |host| by the provided |port|.
- return net::ProxyServer(
- proxy_server.scheme(),
- net::HostPortPair(proxy_server.host_port_pair().host(),
- static_cast<uint16>(port)));
-}
+namespace {
-void AppendProxyServerForScheme(
- const base::DictionaryValue& onc_manual,
- const std::string& onc_scheme,
- std::string* spec) {
- const base::DictionaryValue* onc_proxy_location = NULL;
- if (!onc_manual.GetDictionaryWithoutPathExpansion(onc_scheme,
- &onc_proxy_location)) {
- return;
+template <typename Enum>
+struct StringEnumEntry {
+ const char* string;
+ Enum enum_value;
+};
+
+const StringEnumEntry<onc::ONCSource> kONCSourceTable[] = {
+ { "user_import", onc::ONC_SOURCE_USER_IMPORT },
+ { "device_policy", onc::ONC_SOURCE_DEVICE_POLICY },
+ { "user_policy", onc::ONC_SOURCE_USER_POLICY }
+};
+
+const StringEnumEntry<ClientCertType> kClientCertTable[] = {
+ { "none", CLIENT_CERT_TYPE_NONE },
+ { "pattern", CLIENT_CERT_TYPE_PATTERN },
+ { "ref", CLIENT_CERT_TYPE_REF }
+};
+
+// Converts |enum_value| to the corresponding string according to |table|. If no
+// enum value of the table matches (which can only occur if incorrect casting
+// was used to obtain |enum_value|), returns an empty string instead.
+template <typename Enum, int N>
+std::string EnumToString(const StringEnumEntry<Enum>(& table)[N],
+ Enum enum_value) {
+ for (int i = 0; i < N; ++i) {
+ if (table[i].enum_value == enum_value)
+ return table[i].string;
}
+ return std::string();
+}
- net::ProxyServer::Scheme default_proxy_scheme = net::ProxyServer::SCHEME_HTTP;
- std::string url_scheme;
- if (onc_scheme == proxy::kFtp) {
- url_scheme = "ftp";
- } else if (onc_scheme == proxy::kHttp) {
- url_scheme = "http";
- } else if (onc_scheme == proxy::kHttps) {
- url_scheme = "https";
- } else if (onc_scheme == proxy::kSocks) {
- default_proxy_scheme = net::ProxyServer::SCHEME_SOCKS4;
- url_scheme = "socks";
- } else {
- NOTREACHED();
+// Converts |str| to the corresponding enum value according to |table|. If no
+// string of the table matches, returns |fallback| instead.
+template<typename Enum, int N>
+Enum StringToEnum(const StringEnumEntry<Enum>(& table)[N],
+ const std::string& str,
+ Enum fallback) {
+ for (int i = 0; i < N; ++i) {
+ if (table[i].string == str)
+ return table[i].enum_value;
}
+ return fallback;
+}
- net::ProxyServer proxy_server = ConvertOncProxyLocationToHostPort(
- default_proxy_scheme, *onc_proxy_location);
+}
- ProxyConfigServiceImpl::ProxyConfig::EncodeAndAppendProxyServer(
- url_scheme, proxy_server, spec);
+NetworkUIData::NetworkUIData()
+ : onc_source_(onc::ONC_SOURCE_NONE),
+ certificate_type_(CLIENT_CERT_TYPE_NONE) {
}
-net::ProxyBypassRules ConvertOncExcludeDomainsToBypassRules(
- const base::ListValue& onc_exclude_domains) {
- net::ProxyBypassRules rules;
- for (base::ListValue::const_iterator it = onc_exclude_domains.begin();
- it != onc_exclude_domains.end(); ++it) {
- std::string rule;
- (*it)->GetAsString(&rule);
- rules.AddRuleFromString(rule);
+NetworkUIData::NetworkUIData(const DictionaryValue& dict) {
+ std::string source;
+ dict.GetString(kKeyONCSource, &source);
+ onc_source_ = StringToEnum(kONCSourceTable, source, onc::ONC_SOURCE_NONE);
+
+ std::string type_string;
+ dict.GetString(kKeyCertificateType, &type_string);
+ certificate_type_ =
+ StringToEnum(kClientCertTable, type_string, CLIENT_CERT_TYPE_NONE);
+
+ if (certificate_type_ == CLIENT_CERT_TYPE_PATTERN) {
+ const DictionaryValue* cert_dict = NULL;
+ dict.GetDictionary(kKeyCertificatePattern, &cert_dict);
+ if (cert_dict)
+ certificate_pattern_.CopyFromDictionary(*cert_dict);
+ if (certificate_pattern_.Empty()) {
+ LOG(ERROR) << "Couldn't parse a valid certificate pattern.";
+ certificate_type_ = CLIENT_CERT_TYPE_NONE;
+ }
}
- return rules;
}
-} // namespace
+NetworkUIData::~NetworkUIData() {
+}
+
+void NetworkUIData::FillDictionary(base::DictionaryValue* dict) const {
+ dict->Clear();
-scoped_ptr<base::DictionaryValue> ConvertOncProxySettingsToProxyConfig(
- const base::DictionaryValue& onc_proxy_settings) {
- std::string type;
- onc_proxy_settings.GetStringWithoutPathExpansion(proxy::kType, &type);
- scoped_ptr<DictionaryValue> proxy_dict;
-
- if (type == proxy::kDirect) {
- proxy_dict.reset(ProxyConfigDictionary::CreateDirect());
- } else if (type == proxy::kWPAD) {
- proxy_dict.reset(ProxyConfigDictionary::CreateAutoDetect());
- } else if (type == proxy::kPAC) {
- std::string pac_url;
- onc_proxy_settings.GetStringWithoutPathExpansion(proxy::kPAC, &pac_url);
- GURL url(pac_url);
- DCHECK(url.is_valid())
- << "PAC field is invalid for this ProxySettings.Type";
- proxy_dict.reset(ProxyConfigDictionary::CreatePacScript(url.spec(),
- false));
- } else if (type == proxy::kManual) {
- const base::DictionaryValue* manual_dict = NULL;
- onc_proxy_settings.GetDictionaryWithoutPathExpansion(proxy::kManual,
- &manual_dict);
- std::string manual_spec;
- AppendProxyServerForScheme(*manual_dict, proxy::kFtp, &manual_spec);
- AppendProxyServerForScheme(*manual_dict, proxy::kHttp, &manual_spec);
- AppendProxyServerForScheme(*manual_dict, proxy::kSocks, &manual_spec);
- AppendProxyServerForScheme(*manual_dict, proxy::kHttps, &manual_spec);
-
- const base::ListValue* exclude_domains = NULL;
- net::ProxyBypassRules bypass_rules;
- if (onc_proxy_settings.GetListWithoutPathExpansion(proxy::kExcludeDomains,
- &exclude_domains)) {
- bypass_rules.AssignFrom(
- ConvertOncExcludeDomainsToBypassRules(*exclude_domains));
+ std::string source_string = EnumToString(kONCSourceTable, onc_source_);
+ if (!source_string.empty())
+ dict->SetString(kKeyONCSource, source_string);
+
+ if (certificate_type_ != CLIENT_CERT_TYPE_NONE) {
+ std::string type_string = EnumToString(kClientCertTable, certificate_type_);
+ dict->SetString(kKeyCertificateType, type_string);
+
+ if (certificate_type_ == CLIENT_CERT_TYPE_PATTERN &&
+ !certificate_pattern_.Empty()) {
+ dict->Set(kKeyCertificatePattern,
+ certificate_pattern_.CreateAsDictionary());
}
- proxy_dict.reset(ProxyConfigDictionary::CreateFixedServers(
- manual_spec, bypass_rules.ToString()));
- } else {
- NOTREACHED();
}
- return proxy_dict.Pass();
}
namespace {
void TranslateClientCertType(const std::string& client_cert_type,
NetworkUIData* ui_data) {
+ using namespace onc::certificate;
ClientCertType type;
- if (client_cert_type == certificate::kNone) {
+ if (client_cert_type == kNone) {
type = CLIENT_CERT_TYPE_NONE;
- } else if (client_cert_type == certificate::kRef) {
+ } else if (client_cert_type == kRef) {
type = CLIENT_CERT_TYPE_REF;
- } else if (client_cert_type == certificate::kPattern) {
+ } else if (client_cert_type == kPattern) {
type = CLIENT_CERT_TYPE_PATTERN;
} else {
type = CLIENT_CERT_TYPE_NONE;
@@ -155,7 +143,7 @@ void TranslateCertificatePattern(const base::DictionaryValue& onc_object,
void TranslateEAP(const base::DictionaryValue& eap,
NetworkUIData* ui_data) {
std::string client_cert_type;
- if (eap.GetStringWithoutPathExpansion(eap::kClientCertType,
+ if (eap.GetStringWithoutPathExpansion(onc::eap::kClientCertType,
&client_cert_type)) {
TranslateClientCertType(client_cert_type, ui_data);
}
@@ -164,7 +152,7 @@ void TranslateEAP(const base::DictionaryValue& eap,
void TranslateIPsec(const base::DictionaryValue& ipsec,
NetworkUIData* ui_data) {
std::string client_cert_type;
- if (ipsec.GetStringWithoutPathExpansion(vpn::kClientCertType,
+ if (ipsec.GetStringWithoutPathExpansion(onc::vpn::kClientCertType,
&client_cert_type)) {
TranslateClientCertType(client_cert_type, ui_data);
}
@@ -173,22 +161,22 @@ void TranslateIPsec(const base::DictionaryValue& ipsec,
void TranslateOpenVPN(const base::DictionaryValue& openvpn,
NetworkUIData* ui_data) {
std::string client_cert_type;
- if (openvpn.GetStringWithoutPathExpansion(vpn::kClientCertType,
+ if (openvpn.GetStringWithoutPathExpansion(onc::vpn::kClientCertType,
&client_cert_type)) {
TranslateClientCertType(client_cert_type, ui_data);
}
}
-void TranslateONCHierarchy(const OncValueSignature& signature,
+void TranslateONCHierarchy(const onc::OncValueSignature& signature,
const base::DictionaryValue& onc_object,
NetworkUIData* ui_data) {
- if (&signature == &kCertificatePatternSignature)
+ if (&signature == &onc::kCertificatePatternSignature)
TranslateCertificatePattern(onc_object, ui_data);
- else if (&signature == &kEAPSignature)
+ else if (&signature == &onc::kEAPSignature)
TranslateEAP(onc_object, ui_data);
- else if (&signature == &kIPsecSignature)
+ else if (&signature == &onc::kIPsecSignature)
TranslateIPsec(onc_object, ui_data);
- else if (&signature == &kOpenVPNSignature)
+ else if (&signature == &onc::kOpenVPNSignature)
TranslateOpenVPN(onc_object, ui_data);
// Recurse into nested objects.
@@ -198,7 +186,7 @@ void TranslateONCHierarchy(const OncValueSignature& signature,
if (!it.value().GetAsDictionary(&inner_object))
continue;
- const OncFieldSignature* field_signature =
+ const onc::OncFieldSignature* field_signature =
GetFieldSignature(signature, it.key());
TranslateONCHierarchy(*field_signature->value_signature, *inner_object,
@@ -208,11 +196,11 @@ void TranslateONCHierarchy(const OncValueSignature& signature,
} // namespace
-scoped_ptr<NetworkUIData> CreateUIData(
- ONCSource onc_source,
+scoped_ptr<NetworkUIData> CreateUIDataFromONC(
+ onc::ONCSource onc_source,
const base::DictionaryValue& onc_network) {
scoped_ptr<NetworkUIData> ui_data(new NetworkUIData());
- TranslateONCHierarchy(kNetworkConfigurationSignature, onc_network,
+ TranslateONCHierarchy(onc::kNetworkConfigurationSignature, onc_network,
ui_data.get());
ui_data->set_onc_source(onc_source);
@@ -220,5 +208,4 @@ scoped_ptr<NetworkUIData> CreateUIData(
return ui_data.Pass();
}
-} // namespace onc
} // namespace chromeos
« no previous file with comments | « chromeos/network/network_ui_data.h ('k') | chromeos/network/network_ui_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698