| 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 CHROMEOS_NETWORK_NETWORK_UI_DATA_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_UI_DATA_H_ |
| 6 #define CHROMEOS_NETWORK_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 "chromeos/chromeos_export.h" | 12 #include "chromeos/chromeos_export.h" |
| 13 #include "chromeos/network/certificate_pattern.h" | |
| 14 #include "components/onc/onc_constants.h" | 13 #include "components/onc/onc_constants.h" |
| 15 | 14 |
| 16 namespace base { | 15 namespace base { |
| 17 class DictionaryValue; | 16 class DictionaryValue; |
| 18 } | 17 } |
| 19 | 18 |
| 20 namespace chromeos { | 19 namespace chromeos { |
| 21 | 20 |
| 22 enum ClientCertType { | |
| 23 CLIENT_CERT_TYPE_NONE = 0, | |
| 24 CLIENT_CERT_TYPE_REF = 1, | |
| 25 CLIENT_CERT_TYPE_PATTERN = 2 | |
| 26 }; | |
| 27 | |
| 28 // Helper for accessing and setting values in the network's UI data dictionary. | 21 // Helper for accessing and setting values in the network's UI data dictionary. |
| 29 // Accessing values is done via static members that take the network as an | 22 // Accessing values is done via static members that take the network as an |
| 30 // argument. In order to fill a UI data dictionary, construct an instance, set | 23 // argument. In order to fill a UI data dictionary, construct an instance, set |
| 31 // up your data members, and call FillDictionary(). For example, if you have a | 24 // up your data members, and call FillDictionary(). For example, if you have a |
| 32 // |network|: | 25 // |network|: |
| 33 // | 26 // |
| 34 // NetworkUIData ui_data; | 27 // NetworkUIData ui_data; |
| 35 // ui_data.set_onc_source(onc::ONC_SOURCE_USER_IMPORT); | |
| 36 // ui_data.FillDictionary(network->ui_data()); | 28 // ui_data.FillDictionary(network->ui_data()); |
| 37 class CHROMEOS_EXPORT NetworkUIData { | 29 class CHROMEOS_EXPORT NetworkUIData { |
| 38 public: | 30 public: |
| 39 NetworkUIData(); | 31 NetworkUIData(); |
| 40 NetworkUIData(const NetworkUIData& other); | 32 NetworkUIData(const NetworkUIData& other); |
| 41 NetworkUIData& operator=(const NetworkUIData& other); | 33 NetworkUIData& operator=(const NetworkUIData& other); |
| 42 explicit NetworkUIData(const base::DictionaryValue& dict); | 34 explicit NetworkUIData(const base::DictionaryValue& dict); |
| 43 ~NetworkUIData(); | 35 ~NetworkUIData(); |
| 44 | 36 |
| 45 void set_onc_source(::onc::ONCSource onc_source) { onc_source_ = onc_source; } | |
| 46 ::onc::ONCSource onc_source() const { return onc_source_; } | 37 ::onc::ONCSource onc_source() const { return onc_source_; } |
| 47 | 38 |
| 48 void set_certificate_pattern(const CertificatePattern& pattern) { | |
| 49 certificate_pattern_ = pattern; | |
| 50 } | |
| 51 const CertificatePattern& certificate_pattern() const { | |
| 52 return certificate_pattern_; | |
| 53 } | |
| 54 void set_certificate_type(ClientCertType type) { | |
| 55 certificate_type_ = type; | |
| 56 } | |
| 57 ClientCertType certificate_type() const { | |
| 58 return certificate_type_; | |
| 59 } | |
| 60 bool is_managed() const { | |
| 61 return onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY || | |
| 62 onc_source_ == ::onc::ONC_SOURCE_USER_POLICY; | |
| 63 } | |
| 64 const base::DictionaryValue* user_settings() const { | 39 const base::DictionaryValue* user_settings() const { |
| 65 return user_settings_.get(); | 40 return user_settings_.get(); |
| 66 } | 41 } |
| 67 void set_user_settings(scoped_ptr<base::DictionaryValue> dict); | 42 void set_user_settings(scoped_ptr<base::DictionaryValue> dict); |
| 68 const std::string& policy_guid() const { | |
| 69 return policy_guid_; | |
| 70 } | |
| 71 void set_policy_guid(const std::string& guid) { | |
| 72 policy_guid_ = guid; | |
| 73 } | |
| 74 | 43 |
| 75 // Returns |onc_source_| as a string, one of kONCSource*. | 44 // Returns |onc_source_| as a string, one of kONCSource*. |
| 76 std::string GetONCSourceAsString() const; | 45 std::string GetONCSourceAsString() const; |
| 77 | 46 |
| 78 // Fills in |dict| with the currently configured values. This will write the | 47 // Fills in |dict| with the currently configured values. This will write the |
| 79 // keys appropriate for Network::ui_data() as defined below (kKeyXXX). | 48 // keys appropriate for Network::ui_data() as defined below (kKeyXXX). |
| 80 void FillDictionary(base::DictionaryValue* dict) const; | 49 void FillDictionary(base::DictionaryValue* dict) const; |
| 81 | 50 |
| 82 // Creates a NetworkUIData object from |onc_network|, which has to be a valid | 51 // Creates a NetworkUIData object from |onc_source|. This function is used to |
| 83 // ONC NetworkConfiguration dictionary. | 52 // create the "UIData" property of the Shill configuration. |
| 84 // This function is used to create the "UIData" field of the Shill | 53 static scoped_ptr<NetworkUIData> CreateFromONC(::onc::ONCSource onc_source); |
| 85 // configuration. | |
| 86 static scoped_ptr<NetworkUIData> CreateFromONC( | |
| 87 ::onc::ONCSource onc_source, | |
| 88 const base::DictionaryValue& onc_network); | |
| 89 | 54 |
| 90 // Key for storing source of the ONC network. | 55 // Key for storing source of the ONC network. |
| 91 static const char kKeyONCSource[]; | 56 static const char kKeyONCSource[]; |
| 92 | 57 |
| 93 // Key for storing the certificate pattern. | |
| 94 static const char kKeyCertificatePattern[]; | |
| 95 | |
| 96 // Key for storing the certificate type. | |
| 97 static const char kKeyCertificateType[]; | |
| 98 | |
| 99 // Key for storing the user settings. | 58 // Key for storing the user settings. |
| 100 static const char kKeyUserSettings[]; | 59 static const char kKeyUserSettings[]; |
| 101 | 60 |
| 102 // Values for kKeyONCSource | 61 // Values for kKeyONCSource |
| 103 static const char kONCSourceUserImport[]; | 62 static const char kONCSourceUserImport[]; |
| 104 static const char kONCSourceDevicePolicy[]; | 63 static const char kONCSourceDevicePolicy[]; |
| 105 static const char kONCSourceUserPolicy[]; | 64 static const char kONCSourceUserPolicy[]; |
| 106 | 65 |
| 107 private: | 66 private: |
| 108 CertificatePattern certificate_pattern_; | |
| 109 ::onc::ONCSource onc_source_; | 67 ::onc::ONCSource onc_source_; |
| 110 ClientCertType certificate_type_; | |
| 111 scoped_ptr<base::DictionaryValue> user_settings_; | 68 scoped_ptr<base::DictionaryValue> user_settings_; |
| 112 std::string policy_guid_; | |
| 113 }; | 69 }; |
| 114 | 70 |
| 115 } // namespace chromeos | 71 } // namespace chromeos |
| 116 | 72 |
| 117 #endif // CHROMEOS_NETWORK_NETWORK_UI_DATA_H_ | 73 #endif // CHROMEOS_NETWORK_NETWORK_UI_DATA_H_ |
| OLD | NEW |