| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/values.h" | |
| 13 #include "chrome/browser/chromeos/cros/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" | |
| 17 | |
| 18 namespace chromeos { | |
| 19 | |
| 20 class NetworkPropertyUIData; | |
| 21 | |
| 22 // 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 | |
| 24 // 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 | |
| 26 // |network|: | |
| 27 // | |
| 28 // NetworkUIData ui_data; | |
| 29 // ui_data.set_onc_source(onc::ONC_SOURCE_USER_IMPORT); | |
| 30 // ui_data.FillDictionary(network->ui_data()); | |
| 31 class NetworkUIData { | |
| 32 public: | |
| 33 NetworkUIData(); | |
| 34 explicit NetworkUIData(const base::DictionaryValue& dict); | |
| 35 ~NetworkUIData(); | |
| 36 | |
| 37 void set_onc_source(onc::ONCSource onc_source) { onc_source_ = onc_source; } | |
| 38 onc::ONCSource onc_source() const { return onc_source_; } | |
| 39 | |
| 40 void set_certificate_pattern(const CertificatePattern& pattern) { | |
| 41 certificate_pattern_ = pattern; | |
| 42 } | |
| 43 const CertificatePattern& certificate_pattern() const { | |
| 44 return certificate_pattern_; | |
| 45 } | |
| 46 void set_certificate_type(ClientCertType type) { | |
| 47 certificate_type_ = type; | |
| 48 } | |
| 49 ClientCertType certificate_type() const { | |
| 50 return certificate_type_; | |
| 51 } | |
| 52 bool is_managed() const { | |
| 53 return onc_source_ == onc::ONC_SOURCE_DEVICE_POLICY || | |
| 54 onc_source_ == onc::ONC_SOURCE_USER_POLICY; | |
| 55 } | |
| 56 | |
| 57 // Fills in |dict| with the currently configured values. This will write the | |
| 58 // keys appropriate for Network::ui_data() as defined below (kKeyXXX). | |
| 59 void FillDictionary(base::DictionaryValue* dict) const; | |
| 60 | |
| 61 // Key for storing source of the ONC network, which is an integer according to | |
| 62 // enum ONCSource. | |
| 63 static const char kKeyONCSource[]; | |
| 64 | |
| 65 // Key for storing certificate pattern for this network (if any). | |
| 66 static const char kKeyCertificatePattern[]; | |
| 67 | |
| 68 // Key for storing certificate type for this network (if any), which is one of | |
| 69 // "pattern", "ref", or "none", according to ClientCertType. | |
| 70 static const char kKeyCertificateType[]; | |
| 71 | |
| 72 private: | |
| 73 static EnumMapper<onc::ONCSource>& GetONCSourceMapper(); | |
| 74 static EnumMapper<ClientCertType>& GetClientCertMapper(); | |
| 75 | |
| 76 CertificatePattern certificate_pattern_; | |
| 77 onc::ONCSource onc_source_; | |
| 78 ClientCertType certificate_type_; | |
| 79 | |
| 80 static const EnumMapper<onc::ONCSource>::Pair kONCSourceTable[]; | |
| 81 static const EnumMapper<ClientCertType>::Pair kClientCertTable[]; | |
| 82 }; | |
| 83 | |
| 84 // Holds meta information for a network property: Whether the property is under | |
| 85 // policy control, if it is user-editable, and whether the policy-provided | |
| 86 // default value, if applicable. | |
| 87 class NetworkPropertyUIData { | |
| 88 public: | |
| 89 // Enum values indicating the entity controlling the property. | |
| 90 enum Controller { | |
| 91 // Property is managed by policy. | |
| 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 | |
| 134 } // namespace chromeos | |
| 135 | |
| 136 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ | |
| OLD | NEW |