| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 49 Enum StringToEnum(const StringEnumEntry<Enum>(& table)[N], | 50 Enum StringToEnum(const StringEnumEntry<Enum>(& table)[N], |
| 50 const std::string& str, | 51 const std::string& str, |
| 51 Enum fallback) { | 52 Enum fallback) { |
| 52 for (int i = 0; i < N; ++i) { | 53 for (int i = 0; i < N; ++i) { |
| 53 if (table[i].string == str) | 54 if (table[i].string == str) |
| 54 return table[i].enum_value; | 55 return table[i].enum_value; |
| 55 } | 56 } |
| 56 return fallback; | 57 return fallback; |
| 57 } | 58 } |
| 58 | 59 |
| 59 } | 60 } // namespace |
| 60 | 61 |
| 61 NetworkUIData::NetworkUIData() | 62 NetworkUIData::NetworkUIData() |
| 62 : onc_source_(onc::ONC_SOURCE_NONE), | 63 : onc_source_(onc::ONC_SOURCE_NONE), |
| 63 certificate_type_(CLIENT_CERT_TYPE_NONE) { | 64 certificate_type_(CLIENT_CERT_TYPE_NONE) { |
| 64 } | 65 } |
| 65 | 66 |
| 67 NetworkUIData::NetworkUIData(const NetworkUIData& other) { |
| 68 *this = other; |
| 69 } |
| 70 |
| 71 NetworkUIData& NetworkUIData::operator=(const NetworkUIData& other) { |
| 72 certificate_pattern_ = other.certificate_pattern_; |
| 73 onc_source_ = other.onc_source_; |
| 74 certificate_type_ = other.certificate_type_; |
| 75 if (other.user_settings_) |
| 76 user_settings_.reset(other.user_settings_->DeepCopy()); |
| 77 policy_guid_ = other.policy_guid_; |
| 78 return *this; |
| 79 } |
| 80 |
| 66 NetworkUIData::NetworkUIData(const DictionaryValue& dict) { | 81 NetworkUIData::NetworkUIData(const DictionaryValue& dict) { |
| 67 std::string source; | 82 std::string source; |
| 68 if (dict.GetString(kKeyONCSource, &source)) { | 83 if (dict.GetString(kKeyONCSource, &source)) { |
| 69 onc_source_ = | 84 onc_source_ = |
| 70 StringToEnum(kONCSourceTable, source, onc::ONC_SOURCE_NONE); | 85 StringToEnum(kONCSourceTable, source, onc::ONC_SOURCE_NONE); |
| 71 } else { | 86 } else { |
| 72 onc_source_ = onc::ONC_SOURCE_NONE; | 87 onc_source_ = onc::ONC_SOURCE_NONE; |
| 73 } | 88 } |
| 74 const DictionaryValue* cert_dict = NULL; | 89 const DictionaryValue* cert_dict = NULL; |
| 75 if (dict.GetDictionary(kKeyCertificatePattern, &cert_dict) && cert_dict) | 90 if (dict.GetDictionary(kKeyCertificatePattern, &cert_dict) && cert_dict) |
| 76 certificate_pattern_.CopyFromDictionary(*cert_dict); | 91 certificate_pattern_.CopyFromDictionary(*cert_dict); |
| 77 std::string type_string; | 92 std::string type_string; |
| 78 if (dict.GetString(kKeyCertificateType, &type_string)) { | 93 if (dict.GetString(kKeyCertificateType, &type_string)) { |
| 79 certificate_type_ = | 94 certificate_type_ = |
| 80 StringToEnum(kClientCertTable, type_string, CLIENT_CERT_TYPE_NONE); | 95 StringToEnum(kClientCertTable, type_string, CLIENT_CERT_TYPE_NONE); |
| 81 } else { | 96 } else { |
| 82 certificate_type_ = CLIENT_CERT_TYPE_NONE; | 97 certificate_type_ = CLIENT_CERT_TYPE_NONE; |
| 83 } | 98 } |
| 84 DCHECK(certificate_type_ != CLIENT_CERT_TYPE_PATTERN || | 99 DCHECK(certificate_type_ != CLIENT_CERT_TYPE_PATTERN || |
| 85 (certificate_type_ == CLIENT_CERT_TYPE_PATTERN && | 100 (certificate_type_ == CLIENT_CERT_TYPE_PATTERN && |
| 86 !certificate_pattern_.Empty())); | 101 !certificate_pattern_.Empty())); |
| 102 const DictionaryValue* user_settings = NULL; |
| 103 if (dict.GetDictionary(kKeyUserSettings, &user_settings)) |
| 104 user_settings_.reset(user_settings->DeepCopy()); |
| 87 } | 105 } |
| 88 | 106 |
| 89 NetworkUIData::~NetworkUIData() { | 107 NetworkUIData::~NetworkUIData() { |
| 90 } | 108 } |
| 91 | 109 |
| 92 void NetworkUIData::FillDictionary(base::DictionaryValue* dict) const { | 110 void NetworkUIData::FillDictionary(base::DictionaryValue* dict) const { |
| 93 dict->Clear(); | 111 dict->Clear(); |
| 94 | 112 |
| 95 std::string source_string = EnumToString(kONCSourceTable, onc_source_); | 113 std::string source_string = EnumToString(kONCSourceTable, onc_source_); |
| 96 if (!source_string.empty()) | 114 if (!source_string.empty()) |
| 97 dict->SetString(kKeyONCSource, source_string); | 115 dict->SetString(kKeyONCSource, source_string); |
| 98 | 116 |
| 99 if (certificate_type_ != CLIENT_CERT_TYPE_NONE) { | 117 if (certificate_type_ != CLIENT_CERT_TYPE_NONE) { |
| 100 std::string type_string = EnumToString(kClientCertTable, certificate_type_); | 118 std::string type_string = EnumToString(kClientCertTable, certificate_type_); |
| 101 dict->SetString(kKeyCertificateType, type_string); | 119 dict->SetString(kKeyCertificateType, type_string); |
| 102 | 120 |
| 103 if (certificate_type_ == CLIENT_CERT_TYPE_PATTERN && | 121 if (certificate_type_ == CLIENT_CERT_TYPE_PATTERN && |
| 104 !certificate_pattern_.Empty()) { | 122 !certificate_pattern_.Empty()) { |
| 105 dict->Set(kKeyCertificatePattern, | 123 dict->Set(kKeyCertificatePattern, |
| 106 certificate_pattern_.CreateAsDictionary()); | 124 certificate_pattern_.CreateAsDictionary()); |
| 107 } | 125 } |
| 108 } | 126 } |
| 127 if (user_settings_) |
| 128 dict->SetWithoutPathExpansion(kKeyUserSettings, |
| 129 user_settings_->DeepCopy()); |
| 109 } | 130 } |
| 110 | 131 |
| 111 namespace { | 132 namespace { |
| 112 | 133 |
| 113 void TranslateClientCertType(const std::string& client_cert_type, | 134 void TranslateClientCertType(const std::string& client_cert_type, |
| 114 NetworkUIData* ui_data) { | 135 NetworkUIData* ui_data) { |
| 115 using namespace onc::certificate; | 136 using namespace onc::certificate; |
| 116 ClientCertType type; | 137 ClientCertType type; |
| 117 if (client_cert_type == kNone) { | 138 if (client_cert_type == kNone) { |
| 118 type = CLIENT_CERT_TYPE_NONE; | 139 type = CLIENT_CERT_TYPE_NONE; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 scoped_ptr<NetworkUIData> ui_data(new NetworkUIData()); | 219 scoped_ptr<NetworkUIData> ui_data(new NetworkUIData()); |
| 199 TranslateONCHierarchy(onc::kNetworkConfigurationSignature, onc_network, | 220 TranslateONCHierarchy(onc::kNetworkConfigurationSignature, onc_network, |
| 200 ui_data.get()); | 221 ui_data.get()); |
| 201 | 222 |
| 202 ui_data->set_onc_source(onc_source); | 223 ui_data->set_onc_source(onc_source); |
| 203 | 224 |
| 204 return ui_data.Pass(); | 225 return ui_data.Pass(); |
| 205 } | 226 } |
| 206 | 227 |
| 207 } // namespace chromeos | 228 } // namespace chromeos |
| OLD | NEW |