OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/values.h" | |
14 | |
15 namespace chromeos { | |
16 | |
17 class Network; | |
18 class NetworkPropertyUIData; | |
19 | |
20 // Helper for accessing and setting values in the network's UI data dictionary. | |
21 // Accessing values is done via static members that take the network as an | |
22 // argument. In order to fill a UI data dictionary, construct an instance, set | |
23 // up your data members, and call BuildDictionary(). | |
stevenjb
2011/11/29 17:35:16
This is a bit confusing - BuildDictionary is a mem
Mattias Nissler (ping if slow)
2011/11/29 20:48:47
Ah, so the FillDictionary was originally also call
| |
24 class NetworkUIData { | |
25 public: | |
26 // Indicates from which source an ONC blob comes from. | |
27 enum ONCSource { | |
28 ONC_SOURCE_NONE, | |
29 ONC_SOURCE_USER_IMPORT, | |
30 ONC_SOURCE_DEVICE_POLICY, | |
31 ONC_SOURCE_USER_POLICY, | |
32 }; | |
33 | |
34 // Constructs a new dictionary builder. | |
35 NetworkUIData(); | |
36 | |
37 // Sets the ONC source. | |
38 void set_onc_source(ONCSource source) { source_ = source; } | |
stevenjb
2011/11/29 17:35:16
nit: should be set_source, or data member should b
Mattias Nissler (ping if slow)
2011/11/29 20:48:47
Done.
| |
39 | |
40 // Fills in metadata for a property. | |
41 void SetProperty(const char* property_key, | |
stevenjb
2011/11/29 17:35:16
Maybe rename this SetPropertyUIData?
Mattias Nissler (ping if slow)
2011/11/29 20:48:47
Since this is all UI data, I feel mentioning again
stevenjb
2011/11/29 23:39:05
Fair enough.
| |
42 const NetworkPropertyUIData& ui_data); | |
43 | |
44 // Fills in a network-level UI data dictionary with the currently configured | |
45 // values. | |
stevenjb
2011/11/29 17:35:16
nit: Make it clear in the comment that |dict| is w
Mattias Nissler (ping if slow)
2011/11/29 20:48:47
Done.
| |
46 void FillDictionary(DictionaryValue* dict) const; | |
47 | |
48 // Get the ONC source for a network. | |
49 static ONCSource GetONCSource(const Network* network); | |
50 | |
51 // Check whether a network is managed by policy. | |
52 static bool IsManaged(const Network* network); | |
53 | |
54 // Source of the ONC network. This is an integer according to enum ONCSource. | |
55 static const char kKeyONCSource[]; | |
56 | |
57 // Per-property meta data. This is handled by NetworkPropertyUIData. | |
58 static const char kKeyProperties[]; | |
59 | |
60 // Property names for per-property dat | |
61 static const char kPropertyAutoConnect[]; | |
62 static const char kPropertyPreferred[]; | |
63 static const char kPropertyPassphrase[]; | |
64 static const char kPropertySaveCredentials[]; | |
65 | |
66 static const char kPropertyVPNCaCertNss[]; | |
67 static const char kPropertyVPNPskPassphrase[]; | |
68 static const char kPropertyVPNClientCertId[]; | |
69 static const char kPropertyVPNUsername[]; | |
70 static const char kPropertyVPNUserPassphrase[]; | |
71 static const char kPropertyVPNGroupName[]; | |
72 | |
73 static const char kPropertyEAPMethod[]; | |
74 static const char kPropertyEAPPhase2Auth[]; | |
75 static const char kPropertyEAPServerCaCertNssNickname[]; | |
76 static const char kPropertyEAPClientCertPkcs11Id[]; | |
77 static const char kPropertyEAPUseSystemCAs[]; | |
78 static const char kPropertyEAPIdentity[]; | |
79 static const char kPropertyEAPAnonymousIdentity[]; | |
80 static const char kPropertyEAPPassphrase[]; | |
81 | |
82 private: | |
83 // Helpers for encoding and decoding ONCSource to strings. | |
84 static std::string EncodeONCSource(ONCSource source); | |
85 static ONCSource DecodeONCSource(const std::string& source); | |
86 | |
87 ONCSource source_; | |
88 DictionaryValue properties_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(NetworkUIData); | |
91 }; | |
92 | |
93 // Holds meta information for a network property: Whether the property is under | |
94 // policy control, if it is user-editable, and whether the policy-provided | |
95 // default value, if applicable. | |
96 class NetworkPropertyUIData { | |
97 public: | |
98 // Enum values indicating the entity controlling the property. | |
99 enum Controller { | |
100 // Property is managed by policy. | |
101 CONTROLLER_POLICY, | |
102 // The user controls the policy. | |
103 CONTROLLER_USER, | |
104 }; | |
105 | |
106 // Initializes the object with CONTROLLER_USER and no default value. | |
107 NetworkPropertyUIData(); | |
108 | |
109 // Initializes the object with the given values. |default_value| may be NULL | |
110 // to specify no default value is present. Takes ownership of |default_value|. | |
111 NetworkPropertyUIData(Controller controller, base::Value* default_value); | |
112 | |
113 // Initializes the object and calls UpdateFromNetwork. | |
114 NetworkPropertyUIData(const Network* network, const char* property_key); | |
115 | |
116 // Initializes the object from the network-level UI data dictionary. | |
stevenjb
2011/11/29 17:35:16
s/Initializes/Updates/ (otherwise looks like this
Mattias Nissler (ping if slow)
2011/11/29 20:48:47
Done.
| |
117 // |property_key| may be null, in which case the there'll be no default value | |
118 // and |controller| will be set to CONTROLLER_POLICY iff the network is | |
119 // managed. | |
120 void UpdateFromNetwork(const Network* network, const char* property_key); | |
121 | |
122 // Builds a dictionary for storing in the network-level UI data dictionary. | |
123 // Ownership is transferred to the caller. | |
124 DictionaryValue* BuildDictionary() const; | |
125 | |
126 Controller controller() const { return controller_; } | |
127 const base::Value* default_value() const { return default_value_.get(); } | |
128 bool editable() const { return controller() != CONTROLLER_POLICY; } | |
stevenjb
2011/11/29 17:45:48
I think we should probably either just expose Cont
Mattias Nissler (ping if slow)
2011/11/29 20:48:47
So, I switched it to accessors only. Still kept th
stevenjb
2011/11/29 23:39:05
Looks good. I think that technically since these a
Mattias Nissler (ping if slow)
2011/11/30 10:16:47
Our style rules actually suggest to use unix_hacke
| |
129 | |
130 private: | |
131 // Helpers for encoding and decoding the controller enum. | |
132 static std::string EncodeController(Controller controller); | |
133 static Controller DecodeController(const std::string& controller); | |
134 | |
135 Controller controller_; | |
136 scoped_ptr<base::Value> default_value_; | |
137 | |
138 static const char kKeyController[]; | |
139 static const char kKeyDefaultValue[]; | |
140 | |
141 DISALLOW_COPY_AND_ASSIGN(NetworkPropertyUIData); | |
142 }; | |
143 | |
144 } // namespace chromeos | |
145 | |
146 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ | |
OLD | NEW |