Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: chrome/browser/chromeos/cros/network_ui_data.h

Issue 8728030: Infrastructure for accessing and manipulating network UI data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make clang happy. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "chrome/browser/chromeos/cros/network_parser.h"
15
16 namespace chromeos {
17
18 class Network;
19 class NetworkPropertyUIData;
20
21 // Helper for accessing and setting values in the network's UI data dictionary.
22 // Accessing values is done via static members that take the network as an
23 // argument. In order to fill a UI data dictionary, construct an instance, set
24 // up your data members, and call FillDictionary(). For example, if you have a
25 // |network|:
26 //
27 // NetworkUIData ui_data;
28 // ui_data.set_onc_source(NetworkUIData::ONC_SOURCE_USER_IMPORT);
29 // NetworkPropertyUIData auto_connect_property(
30 // NetworkPropertyUIData::CONTROLLER_USER,
31 // base::Value::CreateBooleanValue(true));
32 // ui_data.SetProperty(NetworkUIData::kPropertyAutoConnect,
33 // auto_connect_property);
34 // ui_data.FillDictionary(network->ui_data());
35 class NetworkUIData {
36 public:
37 // Indicates from which source an ONC blob comes from.
38 enum ONCSource {
39 ONC_SOURCE_NONE,
40 ONC_SOURCE_USER_IMPORT,
41 ONC_SOURCE_DEVICE_POLICY,
42 ONC_SOURCE_USER_POLICY,
43 };
44
45 // Constructs a new dictionary builder.
46 NetworkUIData();
47 ~NetworkUIData();
48
49 // Sets the ONC source.
50 void set_onc_source(ONCSource onc_source) { onc_source_ = onc_source; }
51
52 // Fills in metadata for a property.
53 void SetProperty(const char* property_key,
54 const NetworkPropertyUIData& ui_data);
55
56 // Fills in |dict| with the currently configured values. This will write the
57 // keys appropriate for Network::ui_data() as defined below (kKeyXXX).
58 void FillDictionary(DictionaryValue* dict) const;
59
60 // Get the ONC source for a network.
61 static ONCSource GetONCSource(const Network* network);
62
63 // Check whether a network is managed by policy.
64 static bool IsManaged(const Network* network);
65
66 // Source of the ONC network. This is an integer according to enum ONCSource.
67 static const char kKeyONCSource[];
68
69 // Per-property meta data. This is handled by NetworkPropertyUIData.
70 static const char kKeyProperties[];
71
72 // Property names for per-property dat
73 static const char kPropertyAutoConnect[];
74 static const char kPropertyPreferred[];
75 static const char kPropertyPassphrase[];
76 static const char kPropertySaveCredentials[];
77
78 static const char kPropertyVPNCaCertNss[];
79 static const char kPropertyVPNPskPassphrase[];
80 static const char kPropertyVPNClientCertId[];
81 static const char kPropertyVPNUsername[];
82 static const char kPropertyVPNUserPassphrase[];
83 static const char kPropertyVPNGroupName[];
84
85 static const char kPropertyEAPMethod[];
86 static const char kPropertyEAPPhase2Auth[];
87 static const char kPropertyEAPServerCaCertNssNickname[];
88 static const char kPropertyEAPClientCertPkcs11Id[];
89 static const char kPropertyEAPUseSystemCAs[];
90 static const char kPropertyEAPIdentity[];
91 static const char kPropertyEAPAnonymousIdentity[];
92 static const char kPropertyEAPPassphrase[];
93
94 private:
95 static EnumMapper<ONCSource>& GetONCSourceMapper();
96
97 ONCSource onc_source_;
98 DictionaryValue properties_;
99
100 static const EnumMapper<NetworkUIData::ONCSource>::Pair kONCSourceTable[];
101
102 DISALLOW_COPY_AND_ASSIGN(NetworkUIData);
103 };
104
105 // Holds meta information for a network property: Whether the property is under
106 // policy control, if it is user-editable, and whether the policy-provided
107 // default value, if applicable.
108 class NetworkPropertyUIData {
109 public:
110 // Enum values indicating the entity controlling the property.
111 enum Controller {
112 // Property is managed by policy.
113 CONTROLLER_POLICY,
114 // The user controls the policy.
115 CONTROLLER_USER,
116 };
117
118 // Initializes the object with CONTROLLER_USER and no default value.
119 NetworkPropertyUIData();
120 ~NetworkPropertyUIData();
121
122 // Initializes the object with the given values. |default_value| may be NULL
123 // to specify no default value is present. Takes ownership of |default_value|.
124 NetworkPropertyUIData(Controller controller, base::Value* default_value);
125
126 // Initializes the object and calls UpdateFromNetwork.
127 NetworkPropertyUIData(const Network* network, const char* property_key);
128
129 // Updates the object from the network-level UI data dictionary.
130 // |property_key| may be null, in which case the there'll be no default value
131 // and |controller| will be set to CONTROLLER_POLICY iff the network is
132 // managed.
133 void UpdateFromNetwork(const Network* network, const char* property_key);
134 // Builds a dictionary for storing in the network-level UI data dictionary.
135 // Ownership is transferred to the caller.
136 DictionaryValue* BuildDictionary() const;
137
138 const base::Value* default_value() const { return default_value_.get(); }
139 bool managed() const { return controller_ == CONTROLLER_POLICY; }
140 bool recommended() const {
141 return controller_ == CONTROLLER_USER && default_value_.get();
142 }
143 bool editable() const { return controller_ == CONTROLLER_USER; }
144
145 private:
146 static EnumMapper<Controller>& GetControllerMapper();
147
148 Controller controller_;
149 scoped_ptr<base::Value> default_value_;
150
151 static const char kKeyController[];
152 static const char kKeyDefaultValue[];
153
154 static const EnumMapper<NetworkPropertyUIData::Controller>::Pair
155 kControllerTable[];
156
157 // So it can access the kKeyXYZ constants.
158 friend class NetworkUIDataTest;
159
160 DISALLOW_COPY_AND_ASSIGN(NetworkPropertyUIData);
161 };
162
163 } // namespace chromeos
164
165 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.h ('k') | chrome/browser/chromeos/cros/network_ui_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698