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