Fixed incorrect call of updateContextMenuActionItems.
[chromium-blink-merge.git] / chromeos / network / managed_network_configuration_handler_impl.h
blob433987ce7d5566f641f22199ca9334d0ad6e163a
1 // Copyright 2013 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.
5 #ifndef CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_IMPL_H_
6 #define CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_IMPL_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/linked_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chromeos/chromeos_export.h"
17 #include "chromeos/network/managed_network_configuration_handler.h"
18 #include "chromeos/network/network_handler_callbacks.h"
19 #include "chromeos/network/network_profile_observer.h"
20 #include "chromeos/network/policy_applicator.h"
22 namespace base {
23 class DictionaryValue;
26 namespace chromeos {
28 class NetworkConfigurationHandler;
29 struct NetworkProfile;
30 class NetworkProfileHandler;
31 class NetworkStateHandler;
33 class CHROMEOS_EXPORT ManagedNetworkConfigurationHandlerImpl
34 : public ManagedNetworkConfigurationHandler,
35 public NetworkProfileObserver,
36 public PolicyApplicator::ConfigurationHandler {
37 public:
38 ~ManagedNetworkConfigurationHandlerImpl() override;
40 // ManagedNetworkConfigurationHandler overrides
41 void AddObserver(NetworkPolicyObserver* observer) override;
42 void RemoveObserver(NetworkPolicyObserver* observer) override;
44 void GetProperties(
45 const std::string& service_path,
46 const network_handler::DictionaryResultCallback& callback,
47 const network_handler::ErrorCallback& error_callback) override;
49 void GetManagedProperties(
50 const std::string& userhash,
51 const std::string& service_path,
52 const network_handler::DictionaryResultCallback& callback,
53 const network_handler::ErrorCallback& error_callback) override;
55 void SetProperties(
56 const std::string& service_path,
57 const base::DictionaryValue& user_settings,
58 const base::Closure& callback,
59 const network_handler::ErrorCallback& error_callback) const override;
61 void CreateConfiguration(
62 const std::string& userhash,
63 const base::DictionaryValue& properties,
64 const network_handler::StringResultCallback& callback,
65 const network_handler::ErrorCallback& error_callback) const override;
67 void RemoveConfiguration(
68 const std::string& service_path,
69 const base::Closure& callback,
70 const network_handler::ErrorCallback& error_callback) const override;
72 void SetPolicy(onc::ONCSource onc_source,
73 const std::string& userhash,
74 const base::ListValue& network_configs_onc,
75 const base::DictionaryValue& global_network_config) override;
77 bool IsAnyPolicyApplicationRunning() const override;
79 const base::DictionaryValue* FindPolicyByGUID(
80 const std::string userhash,
81 const std::string& guid,
82 onc::ONCSource* onc_source) const override;
84 const GuidToPolicyMap* GetNetworkConfigsFromPolicy(
85 const std::string& userhash) const override;
87 const base::DictionaryValue* GetGlobalConfigFromPolicy(
88 const std::string& userhash) const override;
90 const base::DictionaryValue* FindPolicyByGuidAndProfile(
91 const std::string& guid,
92 const std::string& profile_path) const override;
94 // NetworkProfileObserver overrides
95 void OnProfileAdded(const NetworkProfile& profile) override;
96 void OnProfileRemoved(const NetworkProfile& profile) override;
98 // PolicyApplicator::ConfigurationHandler overrides
99 void CreateConfigurationFromPolicy(
100 const base::DictionaryValue& shill_properties) override;
102 void UpdateExistingConfigurationWithPropertiesFromPolicy(
103 const base::DictionaryValue& existing_properties,
104 const base::DictionaryValue& new_properties) override;
106 void OnPoliciesApplied(const NetworkProfile& profile) override;
108 private:
109 friend class AutoConnectHandlerTest;
110 friend class ClientCertResolverTest;
111 friend class ManagedNetworkConfigurationHandlerTest;
112 friend class NetworkConnectionHandlerTest;
113 friend class NetworkHandler;
115 struct Policies;
116 typedef base::Callback<void(const std::string& service_path,
117 scoped_ptr<base::DictionaryValue> properties)>
118 GetDevicePropertiesCallback;
119 typedef std::map<std::string, linked_ptr<Policies> > UserToPoliciesMap;
120 typedef std::map<std::string, linked_ptr<PolicyApplicator>>
121 UserToPolicyApplicatorMap;
122 typedef std::map<std::string, std::set<std::string>>
123 UserToModifiedPoliciesMap;
125 ManagedNetworkConfigurationHandlerImpl();
127 // Handlers may be NULL in tests so long as they do not execute any paths
128 // that require the handlers.
129 void Init(NetworkStateHandler* network_state_handler,
130 NetworkProfileHandler* network_profile_handler,
131 NetworkConfigurationHandler* network_configuration_handler,
132 NetworkDeviceHandler* network_device_handler);
134 // Sends the response to the caller of GetManagedProperties.
135 void SendManagedProperties(
136 const std::string& userhash,
137 const network_handler::DictionaryResultCallback& callback,
138 const network_handler::ErrorCallback& error_callback,
139 const std::string& service_path,
140 scoped_ptr<base::DictionaryValue> shill_properties);
142 // Sends the response to the caller of GetProperties.
143 void SendProperties(
144 const network_handler::DictionaryResultCallback& callback,
145 const network_handler::ErrorCallback& error_callback,
146 const std::string& service_path,
147 scoped_ptr<base::DictionaryValue> shill_properties);
149 const Policies* GetPoliciesForUser(const std::string& userhash) const;
150 const Policies* GetPoliciesForProfile(const NetworkProfile& profile) const;
152 void OnPolicyAppliedToNetwork(const std::string& service_path);
154 // Helper method to append associated Device properties to |properties|.
155 void GetDeviceStateProperties(const std::string& service_path,
156 base::DictionaryValue* properties);
158 // Callback for NetworkConfigurationHandler::GetProperties requests from
159 // Get{Managed}Properties. This callback fills in properties from
160 // DeviceState and may request additional Device properties.
161 // Note: Requesting Device properties requires an additional fetch and
162 // additional copying of data, so we only do it for Cellular networks which
163 // contain a lot of necessary state in the associated Device object.
164 void GetPropertiesCallback(
165 GetDevicePropertiesCallback send_callback,
166 const std::string& service_path,
167 const base::DictionaryValue& shill_properties);
169 void GetDevicePropertiesSuccess(
170 const std::string& service_path,
171 scoped_ptr<base::DictionaryValue> network_properties,
172 GetDevicePropertiesCallback send_callback,
173 const std::string& device_path,
174 const base::DictionaryValue& device_properties);
175 void GetDevicePropertiesFailure(
176 const std::string& service_path,
177 scoped_ptr<base::DictionaryValue> network_properties,
178 GetDevicePropertiesCallback send_callback,
179 const std::string& error_name,
180 scoped_ptr<base::DictionaryValue> error_data);
182 // Applies policies for |userhash|. |modified_policies| must be not null and
183 // contain the GUIDs of the network configurations that changed since the last
184 // policy application. Returns true if policy application was started and
185 // false if it was queued or delayed.
186 bool ApplyOrQueuePolicies(const std::string& userhash,
187 std::set<std::string>* modified_policies);
189 // If present, the empty string maps to the device policy.
190 UserToPoliciesMap policies_by_user_;
192 // Local references to the associated handler instances.
193 NetworkStateHandler* network_state_handler_;
194 NetworkProfileHandler* network_profile_handler_;
195 NetworkConfigurationHandler* network_configuration_handler_;
196 NetworkDeviceHandler* network_device_handler_;
198 // Owns the currently running PolicyApplicators.
199 UserToPolicyApplicatorMap policy_applicators_;
201 // Per userhash (or empty string for device policy), contains the GUIDs of the
202 // policies that were modified.
203 // If this map contains a userhash as key, it means that a policy application
204 // for this userhash is pending even if no policies were modified and the
205 // associated set of GUIDs is empty.
206 UserToModifiedPoliciesMap queued_modified_policies_;
208 ObserverList<NetworkPolicyObserver> observers_;
210 // For Shill client callbacks
211 base::WeakPtrFactory<ManagedNetworkConfigurationHandlerImpl>
212 weak_ptr_factory_;
214 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerImpl);
217 } // namespace chromeos
219 #endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_IMPL_H_