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

Side by Side Diff: chromeos/network/managed_network_configuration_handler.h

Issue 13957012: Adding a NetworkProfileHandler used by ManagedNetworkConfigurationHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial patch. Created 7 years, 7 months 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ 5 #ifndef CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_
6 #define CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ 6 #define CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "chromeos/chromeos_export.h" 15 #include "chromeos/chromeos_export.h"
16 #include "chromeos/network/network_handler_callbacks.h" 16 #include "chromeos/network/network_handler_callbacks.h"
17 #include "chromeos/network/network_profile_observer.h"
17 #include "chromeos/network/onc/onc_constants.h" 18 #include "chromeos/network/onc/onc_constants.h"
18 19
19 namespace base { 20 namespace base {
20 class DictionaryValue; 21 class DictionaryValue;
21 class ListValue; 22 class ListValue;
22 } 23 }
23 24
24 namespace chromeos { 25 namespace chromeos {
25 26
27 class NetworkProfileHandler;
28
26 // The ManagedNetworkConfigurationHandler class is used to create and configure 29 // The ManagedNetworkConfigurationHandler class is used to create and configure
27 // networks in ChromeOS using ONC and takes care of network policies. 30 // networks in ChromeOS using ONC and takes care of network policies.
28 // 31 //
29 // Its interface exposes only ONC and should decouple users from Shill. 32 // Its interface exposes only ONC and should decouple users from Shill.
30 // Internally it translates ONC to Shill dictionaries and calls through to the 33 // Internally it translates ONC to Shill dictionaries and calls through to the
31 // NetworkConfigurationHandler. 34 // NetworkConfigurationHandler.
32 // 35 //
33 // For accessing lists of visible networks, and other state information, see the 36 // For accessing lists of visible networks, and other state information, see the
34 // class NetworkStateHandler. 37 // class NetworkStateHandler.
35 // 38 //
36 // This is a singleton and its lifetime is managed by the Chrome startup code. 39 // This is a singleton and its lifetime is managed by the Chrome startup code.
37 // 40 //
38 // Network configurations are referred to by Shill's service path. These 41 // Network configurations are referred to by Shill's service path. These
39 // identifiers should at most be used to also access network state using the 42 // identifiers should at most be used to also access network state using the
40 // NetworkStateHandler, but dependencies to Shill should be avoided. In the 43 // NetworkStateHandler, but dependencies to Shill should be avoided. In the
41 // future, we may switch to other identifiers. 44 // future, we may switch to other identifiers.
42 // 45 //
43 // Note on callbacks: Because all the functions here are meant to be 46 // Note on callbacks: Because all the functions here are meant to be
44 // asynchronous, they all take a |callback| of some type, and an 47 // asynchronous, they all take a |callback| of some type, and an
45 // |error_callback|. When the operation succeeds, |callback| will be called, and 48 // |error_callback|. When the operation succeeds, |callback| will be called, and
46 // when it doesn't, |error_callback| will be called with information about the 49 // when it doesn't, |error_callback| will be called with information about the
47 // error, including a symbolic name for the error and often some error message 50 // error, including a symbolic name for the error and often some error message
48 // that is suitable for logging. None of the error message text is meant for 51 // that is suitable for logging. None of the error message text is meant for
49 // user consumption. 52 // user consumption.
50 53
51 class CHROMEOS_EXPORT ManagedNetworkConfigurationHandler { 54 class CHROMEOS_EXPORT ManagedNetworkConfigurationHandler
55 : public NetworkProfileObserver {
52 public: 56 public:
53 typedef std::map<std::string, const base::DictionaryValue*> PolicyMap; 57 struct Policies;
58 typedef std::map<std::string, Policies*> UserToPolicies;
54 59
55 // Initializes the singleton. 60 // Initializes the singleton.
56 static void Initialize(); 61 static void Initialize(NetworkProfileHandler* profile_handler);
stevenjb 2013/04/26 21:00:49 Again, I dislike passing singletons as constructio
pneubeck (no reviews) 2013/04/29 18:05:51 My reasons/ideas were: The unit test of ManangedN
stevenjb 2013/04/30 17:42:47 I agree that we might want to create a single clas
pneubeck (no reviews) 2013/05/03 17:32:55 It is a step to prevent cyclic dependencies and to
57 62
58 // Returns if the singleton is initialized. 63 // Returns if the singleton is initialized.
59 static bool IsInitialized(); 64 static bool IsInitialized();
60 65
61 // Destroys the singleton. 66 // Destroys the singleton.
62 static void Shutdown(); 67 static void Shutdown();
63 68
64 // Initialize() must be called before this. 69 // Initialize() must be called before this.
65 static ManagedNetworkConfigurationHandler* Get(); 70 static ManagedNetworkConfigurationHandler* Get();
66 71
67 // Provides the properties of the network with |service_path| to |callback|. 72 // Provides the properties of the network with |service_path| to |callback|.
68 void GetProperties( 73 void GetProperties(
69 const std::string& service_path, 74 const std::string& service_path,
70 const network_handler::DictionaryResultCallback& callback, 75 const network_handler::DictionaryResultCallback& callback,
71 const network_handler::ErrorCallback& error_callback) const; 76 const network_handler::ErrorCallback& error_callback) const;
72 77
73 // Provides the managed properties of the network with |service_path| to 78 // Provides the managed properties of the network with |service_path| to
74 // |callback|. 79 // |callback|. |userhash| is only used to ensure that the user's policy is
80 // already applied.
75 void GetManagedProperties( 81 void GetManagedProperties(
82 const std::string& userhash,
76 const std::string& service_path, 83 const std::string& service_path,
77 const network_handler::DictionaryResultCallback& callback, 84 const network_handler::DictionaryResultCallback& callback,
78 const network_handler::ErrorCallback& error_callback); 85 const network_handler::ErrorCallback& error_callback);
79 86
80 // Sets the user's settings of an already configured network with 87 // Sets the user's settings of an already configured network with
81 // |service_path|. A network can be initially configured by calling 88 // |service_path|. A network can be initially configured by calling
82 // CreateConfiguration or if it is managed by a policy. The given properties 89 // CreateConfiguration or if it is managed by a policy. The given properties
83 // will be merged with the existing settings, and it won't clear any existing 90 // will be merged with the existing settings, and it won't clear any existing
84 // properties. 91 // properties.
85 void SetProperties( 92 void SetProperties(
(...skipping 12 matching lines...) Expand all
98 // Initiates a disconnect with the network at |service_path|. |callback| is 105 // Initiates a disconnect with the network at |service_path|. |callback| is
99 // called if the diconnect request was successfully handled. That doesn't mean 106 // called if the diconnect request was successfully handled. That doesn't mean
100 // that the network is already diconnected. 107 // that the network is already diconnected.
101 void Disconnect(const std::string& service_path, 108 void Disconnect(const std::string& service_path,
102 const base::Closure& callback, 109 const base::Closure& callback,
103 const network_handler::ErrorCallback& error_callback) const; 110 const network_handler::ErrorCallback& error_callback) const;
104 111
105 // Initially configures an unconfigured network with the given user settings 112 // Initially configures an unconfigured network with the given user settings
106 // and returns the new identifier to |callback| if successful. Fails if the 113 // and returns the new identifier to |callback| if successful. Fails if the
107 // network was already configured by a call to this function or because of a 114 // network was already configured by a call to this function or because of a
108 // policy. 115 // policy. The new configuration will be owned by user |userhash|. If
116 // |userhash| is empty, the new configuration will be shared.
109 void CreateConfiguration( 117 void CreateConfiguration(
118 const std::string& userhash,
110 const base::DictionaryValue& properties, 119 const base::DictionaryValue& properties,
111 const network_handler::StringResultCallback& callback, 120 const network_handler::StringResultCallback& callback,
112 const network_handler::ErrorCallback& error_callback) const; 121 const network_handler::ErrorCallback& error_callback) const;
113 122
114 // Removes the user's configuration from the network with |service_path|. The 123 // Removes the user's configuration from the network with |service_path|. The
115 // network may still show up in the visible networks after this, but no user 124 // network may still show up in the visible networks after this, but no user
116 // configuration will remain. If it was managed, it will still be configured. 125 // configuration will remain. If it was managed, it will still be configured.
117 void RemoveConfiguration( 126 void RemoveConfiguration(
118 const std::string& service_path, 127 const std::string& service_path,
119 const base::Closure& callback, 128 const base::Closure& callback,
120 const network_handler::ErrorCallback& error_callback) const; 129 const network_handler::ErrorCallback& error_callback) const;
121 130
122 // Only to be called by NetworkConfigurationUpdater or from tests. Sets 131 // Only to be called by NetworkConfigurationUpdater or from tests. Sets
123 // |network_configs_onc| as the current policy of |onc_source|. The network 132 // |network_configs_onc| as the current policy of |onc_source|. The network
124 // configurations of the policy will be applied (not necessarily immediately) 133 // configurations of the policy will be applied (not necessarily immediately)
125 // to Shill's profiles and enforced in future configurations until the policy 134 // to Shill's profiles and enforced in future configurations until the policy
126 // associated with |onc_source| is changed again with this function. 135 // associated with |onc_source| is changed again with this function. For
127 // This function doesn't validate the policy. The caller must ensure validity. 136 // device policies, |userhash| must be empty.
128 void SetPolicy(onc::ONCSource onc_source, 137 void SetPolicy(onc::ONCSource onc_source,
138 const std::string& userhash,
129 const base::ListValue& network_configs_onc); 139 const base::ListValue& network_configs_onc);
130 140
141 // NetworkProfileObserver overrides
142 virtual void OnProfileAdded(const NetworkProfile& profile) OVERRIDE;
143 virtual void OnProfileRemoved(const NetworkProfile& profile) OVERRIDE;
144
131 private: 145 private:
132 class PolicyApplicator; 146 class PolicyApplicator;
133 147
134 ManagedNetworkConfigurationHandler(); 148 explicit ManagedNetworkConfigurationHandler(
135 ~ManagedNetworkConfigurationHandler(); 149 NetworkProfileHandler* profile_handler);
150 virtual ~ManagedNetworkConfigurationHandler();
136 151
137 void GetManagedPropertiesCallback( 152 void GetManagedPropertiesCallback(
138 const network_handler::DictionaryResultCallback& callback, 153 const network_handler::DictionaryResultCallback& callback,
139 const network_handler::ErrorCallback& error_callback, 154 const network_handler::ErrorCallback& error_callback,
140 const std::string& service_path, 155 const std::string& service_path,
141 const base::DictionaryValue& shill_properties); 156 const base::DictionaryValue& shill_properties);
142 157
143 const PolicyMap* GetPoliciesForProfile(const std::string& profile) const; 158 const Policies *GetPoliciesForUser(const std::string& userhash) const;
159 const Policies *GetPoliciesForProfile(const NetworkProfile& profile) const;
144 160
145 // The entries of these maps are owned by this class and are explicitly 161 // The entries of these maps are owned by this class and are explicitly
146 // deleted where necessary. 162 // deleted where necessary.
147 PolicyMap user_policies_by_guid_; 163 // Empty string maps to device policy.
148 PolicyMap device_policies_by_guid_; 164 UserToPolicies policies_by_user_;
149 bool user_policies_initialized_; 165
150 bool device_policies_initialized_; 166 // A local reference to the policy handler singleton.
167 NetworkProfileHandler* profile_handler_;
151 168
152 // For Shill client callbacks 169 // For Shill client callbacks
153 base::WeakPtrFactory<ManagedNetworkConfigurationHandler> weak_ptr_factory_; 170 base::WeakPtrFactory<ManagedNetworkConfigurationHandler> weak_ptr_factory_;
154 171
155 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandler); 172 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandler);
156 }; 173 };
157 174
158 } // namespace chromeos 175 } // namespace chromeos
159 176
160 #endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ 177 #endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698