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

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

Issue 12676017: Adding policy support to the new network configuration stack. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed clang errors. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/network/network_ui_data.h ('k') | chromeos/network/onc/onc_constants.h » ('j') | 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_ui_data.h" 5 #include "chromeos/network/network_ui_data.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chromeos/network/onc/onc_signature.h" 9 #include "chromeos/network/onc/onc_signature.h"
10 10
11 namespace chromeos { 11 namespace chromeos {
12 12
13 // Top-level UI data dictionary keys. 13 // Top-level UI data dictionary keys.
14 const char NetworkUIData::kKeyONCSource[] = "onc_source"; 14 const char NetworkUIData::kKeyONCSource[] = "onc_source";
15 const char NetworkUIData::kKeyCertificatePattern[] = "certificate_pattern"; 15 const char NetworkUIData::kKeyCertificatePattern[] = "certificate_pattern";
16 const char NetworkUIData::kKeyCertificateType[] = "certificate_type"; 16 const char NetworkUIData::kKeyCertificateType[] = "certificate_type";
17 const char NetworkUIData::kKeyUserSettings[] = "user_settings";
17 18
18 namespace { 19 namespace {
19 20
20 template <typename Enum> 21 template <typename Enum>
21 struct StringEnumEntry { 22 struct StringEnumEntry {
22 const char* string; 23 const char* string;
23 Enum enum_value; 24 Enum enum_value;
24 }; 25 };
25 26
26 const StringEnumEntry<onc::ONCSource> kONCSourceTable[] = { 27 const StringEnumEntry<onc::ONCSource> kONCSourceTable[] = {
(...skipping 27 matching lines...) Expand all
54 Enum StringToEnum(const StringEnumEntry<Enum>(& table)[N], 55 Enum StringToEnum(const StringEnumEntry<Enum>(& table)[N],
55 const std::string& str, 56 const std::string& str,
56 Enum fallback) { 57 Enum fallback) {
57 for (int i = 0; i < N; ++i) { 58 for (int i = 0; i < N; ++i) {
58 if (table[i].string == str) 59 if (table[i].string == str)
59 return table[i].enum_value; 60 return table[i].enum_value;
60 } 61 }
61 return fallback; 62 return fallback;
62 } 63 }
63 64
64 } 65 } // namespace
65 66
66 NetworkUIData::NetworkUIData() 67 NetworkUIData::NetworkUIData()
67 : onc_source_(onc::ONC_SOURCE_NONE), 68 : onc_source_(onc::ONC_SOURCE_NONE),
68 certificate_type_(CLIENT_CERT_TYPE_NONE) { 69 certificate_type_(CLIENT_CERT_TYPE_NONE) {
69 } 70 }
70 71
72 NetworkUIData::NetworkUIData(const NetworkUIData& other) {
73 *this = other;
74 }
75
76 NetworkUIData& NetworkUIData::operator=(const NetworkUIData& other) {
77 certificate_pattern_ = other.certificate_pattern_;
78 onc_source_ = other.onc_source_;
79 certificate_type_ = other.certificate_type_;
80 if (other.user_settings_)
81 user_settings_.reset(other.user_settings_->DeepCopy());
82 policy_guid_ = other.policy_guid_;
83 return *this;
84 }
85
71 NetworkUIData::NetworkUIData(const DictionaryValue& dict) { 86 NetworkUIData::NetworkUIData(const DictionaryValue& dict) {
72 std::string source; 87 std::string source;
73 dict.GetString(kKeyONCSource, &source); 88 dict.GetString(kKeyONCSource, &source);
74 onc_source_ = StringToEnum(kONCSourceTable, source, onc::ONC_SOURCE_NONE); 89 onc_source_ = StringToEnum(kONCSourceTable, source, onc::ONC_SOURCE_NONE);
75 90
76 std::string type_string; 91 std::string type_string;
77 dict.GetString(kKeyCertificateType, &type_string); 92 dict.GetString(kKeyCertificateType, &type_string);
78 certificate_type_ = 93 certificate_type_ =
79 StringToEnum(kClientCertTable, type_string, CLIENT_CERT_TYPE_NONE); 94 StringToEnum(kClientCertTable, type_string, CLIENT_CERT_TYPE_NONE);
80 95
81 if (certificate_type_ == CLIENT_CERT_TYPE_PATTERN) { 96 if (certificate_type_ == CLIENT_CERT_TYPE_PATTERN) {
82 const DictionaryValue* cert_dict = NULL; 97 const DictionaryValue* cert_dict = NULL;
83 dict.GetDictionary(kKeyCertificatePattern, &cert_dict); 98 dict.GetDictionary(kKeyCertificatePattern, &cert_dict);
84 if (cert_dict) 99 if (cert_dict)
85 certificate_pattern_.CopyFromDictionary(*cert_dict); 100 certificate_pattern_.CopyFromDictionary(*cert_dict);
86 if (certificate_pattern_.Empty()) { 101 if (certificate_pattern_.Empty()) {
87 LOG(ERROR) << "Couldn't parse a valid certificate pattern."; 102 LOG(ERROR) << "Couldn't parse a valid certificate pattern.";
88 certificate_type_ = CLIENT_CERT_TYPE_NONE; 103 certificate_type_ = CLIENT_CERT_TYPE_NONE;
89 } 104 }
90 } 105 }
106
107 const DictionaryValue* user_settings = NULL;
108 if (dict.GetDictionary(kKeyUserSettings, &user_settings))
109 user_settings_.reset(user_settings->DeepCopy());
91 } 110 }
92 111
93 NetworkUIData::~NetworkUIData() { 112 NetworkUIData::~NetworkUIData() {
94 } 113 }
95 114
96 void NetworkUIData::FillDictionary(base::DictionaryValue* dict) const { 115 void NetworkUIData::FillDictionary(base::DictionaryValue* dict) const {
97 dict->Clear(); 116 dict->Clear();
98 117
99 std::string source_string = EnumToString(kONCSourceTable, onc_source_); 118 std::string source_string = EnumToString(kONCSourceTable, onc_source_);
100 if (!source_string.empty()) 119 if (!source_string.empty())
101 dict->SetString(kKeyONCSource, source_string); 120 dict->SetString(kKeyONCSource, source_string);
102 121
103 if (certificate_type_ != CLIENT_CERT_TYPE_NONE) { 122 if (certificate_type_ != CLIENT_CERT_TYPE_NONE) {
104 std::string type_string = EnumToString(kClientCertTable, certificate_type_); 123 std::string type_string = EnumToString(kClientCertTable, certificate_type_);
105 dict->SetString(kKeyCertificateType, type_string); 124 dict->SetString(kKeyCertificateType, type_string);
106 125
107 if (certificate_type_ == CLIENT_CERT_TYPE_PATTERN && 126 if (certificate_type_ == CLIENT_CERT_TYPE_PATTERN &&
108 !certificate_pattern_.Empty()) { 127 !certificate_pattern_.Empty()) {
109 dict->Set(kKeyCertificatePattern, 128 dict->Set(kKeyCertificatePattern,
110 certificate_pattern_.CreateAsDictionary()); 129 certificate_pattern_.CreateAsDictionary());
111 } 130 }
112 } 131 }
132 if (user_settings_)
133 dict->SetWithoutPathExpansion(kKeyUserSettings,
134 user_settings_->DeepCopy());
113 } 135 }
114 136
115 namespace { 137 namespace {
116 138
117 void TranslateClientCertType(const std::string& client_cert_type, 139 void TranslateClientCertType(const std::string& client_cert_type,
118 NetworkUIData* ui_data) { 140 NetworkUIData* ui_data) {
119 using namespace onc::certificate; 141 using namespace onc::certificate;
120 ClientCertType type; 142 ClientCertType type;
121 if (client_cert_type == kNone) { 143 if (client_cert_type == kNone) {
122 type = CLIENT_CERT_TYPE_NONE; 144 type = CLIENT_CERT_TYPE_NONE;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 scoped_ptr<NetworkUIData> ui_data(new NetworkUIData()); 224 scoped_ptr<NetworkUIData> ui_data(new NetworkUIData());
203 TranslateONCHierarchy(onc::kNetworkConfigurationSignature, onc_network, 225 TranslateONCHierarchy(onc::kNetworkConfigurationSignature, onc_network,
204 ui_data.get()); 226 ui_data.get());
205 227
206 ui_data->set_onc_source(onc_source); 228 ui_data->set_onc_source(onc_source);
207 229
208 return ui_data.Pass(); 230 return ui_data.Pass();
209 } 231 }
210 232
211 } // namespace chromeos 233 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_ui_data.h ('k') | chromeos/network/onc/onc_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698