| 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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_UI_DATA_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ | 6 #define CHROMEOS_NETWORK_NETWORK_UI_DATA_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/values.h" | 12 #include "chromeos/chromeos_export.h" |
| 13 #include "chrome/browser/chromeos/cros/certificate_pattern.h" | 13 #include "chromeos/network/certificate_pattern.h" |
| 14 #include "chrome/browser/chromeos/cros/enum_mapper.h" | |
| 15 #include "chrome/browser/chromeos/cros/network_constants.h" | |
| 16 #include "chromeos/network/onc/onc_constants.h" | 14 #include "chromeos/network/onc/onc_constants.h" |
| 17 | 15 |
| 16 namespace base { |
| 17 class DictionaryValue; |
| 18 } |
| 19 |
| 18 namespace chromeos { | 20 namespace chromeos { |
| 19 | 21 |
| 22 enum ClientCertType { |
| 23 CLIENT_CERT_TYPE_NONE = 0, |
| 24 CLIENT_CERT_TYPE_REF = 1, |
| 25 CLIENT_CERT_TYPE_PATTERN = 2 |
| 26 }; |
| 27 |
| 20 class NetworkPropertyUIData; | 28 class NetworkPropertyUIData; |
| 21 | 29 |
| 22 // Helper for accessing and setting values in the network's UI data dictionary. | 30 // Helper for accessing and setting values in the network's UI data dictionary. |
| 23 // Accessing values is done via static members that take the network as an | 31 // Accessing values is done via static members that take the network as an |
| 24 // argument. In order to fill a UI data dictionary, construct an instance, set | 32 // argument. In order to fill a UI data dictionary, construct an instance, set |
| 25 // up your data members, and call FillDictionary(). For example, if you have a | 33 // up your data members, and call FillDictionary(). For example, if you have a |
| 26 // |network|: | 34 // |network|: |
| 27 // | 35 // |
| 28 // NetworkUIData ui_data; | 36 // NetworkUIData ui_data; |
| 29 // ui_data.set_onc_source(onc::ONC_SOURCE_USER_IMPORT); | 37 // ui_data.set_onc_source(onc::ONC_SOURCE_USER_IMPORT); |
| 30 // ui_data.FillDictionary(network->ui_data()); | 38 // ui_data.FillDictionary(network->ui_data()); |
| 31 class NetworkUIData { | 39 class CHROMEOS_EXPORT NetworkUIData { |
| 32 public: | 40 public: |
| 33 NetworkUIData(); | 41 NetworkUIData(); |
| 34 explicit NetworkUIData(const base::DictionaryValue& dict); | 42 explicit NetworkUIData(const base::DictionaryValue& dict); |
| 35 ~NetworkUIData(); | 43 ~NetworkUIData(); |
| 36 | 44 |
| 37 void set_onc_source(onc::ONCSource onc_source) { onc_source_ = onc_source; } | 45 void set_onc_source(onc::ONCSource onc_source) { onc_source_ = onc_source; } |
| 38 onc::ONCSource onc_source() const { return onc_source_; } | 46 onc::ONCSource onc_source() const { return onc_source_; } |
| 39 | 47 |
| 40 void set_certificate_pattern(const CertificatePattern& pattern) { | 48 void set_certificate_pattern(const CertificatePattern& pattern) { |
| 41 certificate_pattern_ = pattern; | 49 certificate_pattern_ = pattern; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 63 static const char kKeyONCSource[]; | 71 static const char kKeyONCSource[]; |
| 64 | 72 |
| 65 // Key for storing certificate pattern for this network (if any). | 73 // Key for storing certificate pattern for this network (if any). |
| 66 static const char kKeyCertificatePattern[]; | 74 static const char kKeyCertificatePattern[]; |
| 67 | 75 |
| 68 // Key for storing certificate type for this network (if any), which is one of | 76 // Key for storing certificate type for this network (if any), which is one of |
| 69 // "pattern", "ref", or "none", according to ClientCertType. | 77 // "pattern", "ref", or "none", according to ClientCertType. |
| 70 static const char kKeyCertificateType[]; | 78 static const char kKeyCertificateType[]; |
| 71 | 79 |
| 72 private: | 80 private: |
| 73 static EnumMapper<onc::ONCSource>& GetONCSourceMapper(); | |
| 74 static EnumMapper<ClientCertType>& GetClientCertMapper(); | |
| 75 | |
| 76 CertificatePattern certificate_pattern_; | 81 CertificatePattern certificate_pattern_; |
| 77 onc::ONCSource onc_source_; | 82 onc::ONCSource onc_source_; |
| 78 ClientCertType certificate_type_; | 83 ClientCertType certificate_type_; |
| 79 | |
| 80 static const EnumMapper<onc::ONCSource>::Pair kONCSourceTable[]; | |
| 81 static const EnumMapper<ClientCertType>::Pair kClientCertTable[]; | |
| 82 }; | 84 }; |
| 83 | 85 |
| 84 // Holds meta information for a network property: Whether the property is under | 86 // Creates a NetworkUIData object from |onc_network|, which has to be a valid |
| 85 // policy control, if it is user-editable, and whether the policy-provided | 87 // ONC NetworkConfiguration dictionary. |
| 86 // default value, if applicable. | 88 // |
| 87 class NetworkPropertyUIData { | 89 // This function is used to create the "UIData" field of the Shill |
| 88 public: | 90 // configuration. |
| 89 // Enum values indicating the entity controlling the property. | 91 CHROMEOS_EXPORT scoped_ptr<NetworkUIData> CreateUIDataFromONC( |
| 90 enum Controller { | 92 onc::ONCSource onc_source, |
| 91 // Property is managed by policy. | 93 const base::DictionaryValue& onc_network); |
| 92 CONTROLLER_POLICY, | |
| 93 // The user controls the policy. | |
| 94 CONTROLLER_USER, | |
| 95 }; | |
| 96 | |
| 97 // Initializes the object with CONTROLLER_USER and no default value. | |
| 98 NetworkPropertyUIData(); | |
| 99 ~NetworkPropertyUIData(); | |
| 100 | |
| 101 // Initializes the object by calling Reset() with the provided ui_data. | |
| 102 explicit NetworkPropertyUIData(const NetworkUIData& ui_data); | |
| 103 | |
| 104 // Resets the property to the controller specified by the given |ui_data| and | |
| 105 // clears the default value. | |
| 106 void Reset(const NetworkUIData& ui_data); | |
| 107 | |
| 108 // Update the property object from dictionary, reading the key given by | |
| 109 // |property_key|. | |
| 110 void ParseOncProperty(const NetworkUIData& ui_data, | |
| 111 const base::DictionaryValue* onc, | |
| 112 const std::string& property_key); | |
| 113 | |
| 114 const base::Value* default_value() const { return default_value_.get(); } | |
| 115 bool managed() const { return controller_ == CONTROLLER_POLICY; } | |
| 116 bool recommended() const { | |
| 117 return controller_ == CONTROLLER_USER && default_value_.get(); | |
| 118 } | |
| 119 bool editable() const { return controller_ == CONTROLLER_USER; } | |
| 120 | |
| 121 private: | |
| 122 Controller controller_; | |
| 123 scoped_ptr<base::Value> default_value_; | |
| 124 | |
| 125 static const char kKeyController[]; | |
| 126 static const char kKeyDefaultValue[]; | |
| 127 | |
| 128 // So it can access the kKeyXYZ constants. | |
| 129 friend class NetworkUIDataTest; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(NetworkPropertyUIData); | |
| 132 }; | |
| 133 | 94 |
| 134 } // namespace chromeos | 95 } // namespace chromeos |
| 135 | 96 |
| 136 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ | 97 #endif // CHROMEOS_NETWORK_NETWORK_UI_DATA_H_ |
| OLD | NEW |