Chromium Code Reviews| Index: chrome/browser/chromeos/cros/network_ui_data.h |
| diff --git a/chrome/browser/chromeos/cros/network_ui_data.h b/chrome/browser/chromeos/cros/network_ui_data.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4ef663f8fad14078d861654246ae57279dd7c95f |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/cros/network_ui_data.h |
| @@ -0,0 +1,146 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ |
| +#define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/values.h" |
| + |
| +namespace chromeos { |
| + |
| +class Network; |
| +class NetworkPropertyUIData; |
| + |
| +// Helper for accessing and setting values in the network's UI data dictionary. |
| +// Accessing values is done via static members that take the network as an |
| +// argument. In order to fill a UI data dictionary, construct an instance, set |
| +// 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
|
| +class NetworkUIData { |
| + public: |
| + // Indicates from which source an ONC blob comes from. |
| + enum ONCSource { |
| + ONC_SOURCE_NONE, |
| + ONC_SOURCE_USER_IMPORT, |
| + ONC_SOURCE_DEVICE_POLICY, |
| + ONC_SOURCE_USER_POLICY, |
| + }; |
| + |
| + // Constructs a new dictionary builder. |
| + NetworkUIData(); |
| + |
| + // Sets the ONC source. |
| + 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.
|
| + |
| + // Fills in metadata for a property. |
| + 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.
|
| + const NetworkPropertyUIData& ui_data); |
| + |
| + // Fills in a network-level UI data dictionary with the currently configured |
| + // 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.
|
| + void FillDictionary(DictionaryValue* dict) const; |
| + |
| + // Get the ONC source for a network. |
| + static ONCSource GetONCSource(const Network* network); |
| + |
| + // Check whether a network is managed by policy. |
| + static bool IsManaged(const Network* network); |
| + |
| + // Source of the ONC network. This is an integer according to enum ONCSource. |
| + static const char kKeyONCSource[]; |
| + |
| + // Per-property meta data. This is handled by NetworkPropertyUIData. |
| + static const char kKeyProperties[]; |
| + |
| + // Property names for per-property dat |
| + static const char kPropertyAutoConnect[]; |
| + static const char kPropertyPreferred[]; |
| + static const char kPropertyPassphrase[]; |
| + static const char kPropertySaveCredentials[]; |
| + |
| + static const char kPropertyVPNCaCertNss[]; |
| + static const char kPropertyVPNPskPassphrase[]; |
| + static const char kPropertyVPNClientCertId[]; |
| + static const char kPropertyVPNUsername[]; |
| + static const char kPropertyVPNUserPassphrase[]; |
| + static const char kPropertyVPNGroupName[]; |
| + |
| + static const char kPropertyEAPMethod[]; |
| + static const char kPropertyEAPPhase2Auth[]; |
| + static const char kPropertyEAPServerCaCertNssNickname[]; |
| + static const char kPropertyEAPClientCertPkcs11Id[]; |
| + static const char kPropertyEAPUseSystemCAs[]; |
| + static const char kPropertyEAPIdentity[]; |
| + static const char kPropertyEAPAnonymousIdentity[]; |
| + static const char kPropertyEAPPassphrase[]; |
| + |
| + private: |
| + // Helpers for encoding and decoding ONCSource to strings. |
| + static std::string EncodeONCSource(ONCSource source); |
| + static ONCSource DecodeONCSource(const std::string& source); |
| + |
| + ONCSource source_; |
| + DictionaryValue properties_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NetworkUIData); |
| +}; |
| + |
| +// Holds meta information for a network property: Whether the property is under |
| +// policy control, if it is user-editable, and whether the policy-provided |
| +// default value, if applicable. |
| +class NetworkPropertyUIData { |
| + public: |
| + // Enum values indicating the entity controlling the property. |
| + enum Controller { |
| + // Property is managed by policy. |
| + CONTROLLER_POLICY, |
| + // The user controls the policy. |
| + CONTROLLER_USER, |
| + }; |
| + |
| + // Initializes the object with CONTROLLER_USER and no default value. |
| + NetworkPropertyUIData(); |
| + |
| + // Initializes the object with the given values. |default_value| may be NULL |
| + // to specify no default value is present. Takes ownership of |default_value|. |
| + NetworkPropertyUIData(Controller controller, base::Value* default_value); |
| + |
| + // Initializes the object and calls UpdateFromNetwork. |
| + NetworkPropertyUIData(const Network* network, const char* property_key); |
| + |
| + // 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.
|
| + // |property_key| may be null, in which case the there'll be no default value |
| + // and |controller| will be set to CONTROLLER_POLICY iff the network is |
| + // managed. |
| + void UpdateFromNetwork(const Network* network, const char* property_key); |
| + |
| + // Builds a dictionary for storing in the network-level UI data dictionary. |
| + // Ownership is transferred to the caller. |
| + DictionaryValue* BuildDictionary() const; |
| + |
| + Controller controller() const { return controller_; } |
| + const base::Value* default_value() const { return default_value_.get(); } |
| + 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
|
| + |
| + private: |
| + // Helpers for encoding and decoding the controller enum. |
| + static std::string EncodeController(Controller controller); |
| + static Controller DecodeController(const std::string& controller); |
| + |
| + Controller controller_; |
| + scoped_ptr<base::Value> default_value_; |
| + |
| + static const char kKeyController[]; |
| + static const char kKeyDefaultValue[]; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NetworkPropertyUIData); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_UI_DATA_H_ |