Service workers: Allow HTTPS pages arrived at via HTTP redirect to use SW
[chromium-blink-merge.git] / chromeos / network / managed_network_configuration_handler_impl.h
bloba204b0484964aa3f66228e3b3ffc89304252c785
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& userhash,
46 const std::string& service_path,
47 const network_handler::DictionaryResultCallback& callback,
48 const network_handler::ErrorCallback& error_callback) override;
50 void GetManagedProperties(
51 const std::string& userhash,
52 const std::string& service_path,
53 const network_handler::DictionaryResultCallback& callback,
54 const network_handler::ErrorCallback& error_callback) override;
56 void SetProperties(
57 const std::string& service_path,
58 const base::DictionaryValue& user_settings,
59 const base::Closure& callback,
60 const network_handler::ErrorCallback& error_callback) override;
62 void CreateConfiguration(
63 const std::string& userhash,
64 const base::DictionaryValue& properties,
65 const network_handler::StringResultCallback& callback,
66 const network_handler::ErrorCallback& error_callback) const override;
68 void RemoveConfiguration(
69 const std::string& service_path,
70 const base::Closure& callback,
71 const network_handler::ErrorCallback& error_callback) const override;
73 void SetPolicy(onc::ONCSource onc_source,
74 const std::string& userhash,
75 const base::ListValue& network_configs_onc,
76 const base::DictionaryValue& global_network_config) override;
78 bool IsAnyPolicyApplicationRunning() const override;
80 const base::DictionaryValue* FindPolicyByGUID(
81 const std::string userhash,
82 const std::string& guid,
83 onc::ONCSource* onc_source) const override;
85 const GuidToPolicyMap* GetNetworkConfigsFromPolicy(
86 const std::string& userhash) const override;
88 const base::DictionaryValue* GetGlobalConfigFromPolicy(
89 const std::string& userhash) const override;
91 const base::DictionaryValue* FindPolicyByGuidAndProfile(
92 const std::string& guid,
93 const std::string& profile_path) const override;
95 // NetworkProfileObserver overrides
96 void OnProfileAdded(const NetworkProfile& profile) override;
97 void OnProfileRemoved(const NetworkProfile& profile) override;
99 // PolicyApplicator::ConfigurationHandler overrides
100 void CreateConfigurationFromPolicy(
101 const base::DictionaryValue& shill_properties) override;
103 void UpdateExistingConfigurationWithPropertiesFromPolicy(
104 const base::DictionaryValue& existing_properties,
105 const base::DictionaryValue& new_properties) override;
107 void OnPoliciesApplied(const NetworkProfile& profile) override;
109 private:
110 friend class AutoConnectHandlerTest;
111 friend class ClientCertResolverTest;
112 friend class ManagedNetworkConfigurationHandlerTest;
113 friend class NetworkConnectionHandlerTest;
114 friend class NetworkHandler;
116 struct Policies;
117 typedef base::Callback<void(const std::string& service_path,
118 scoped_ptr<base::DictionaryValue> properties)>
119 GetDevicePropertiesCallback;
120 typedef std::map<std::string, linked_ptr<Policies> > UserToPoliciesMap;
121 typedef std::map<std::string, linked_ptr<PolicyApplicator>>
122 UserToPolicyApplicatorMap;
123 typedef std::map<std::string, std::set<std::string>>
124 UserToModifiedPoliciesMap;
126 ManagedNetworkConfigurationHandlerImpl();
128 // Handlers may be NULL in tests so long as they do not execute any paths
129 // that require the handlers.
130 void Init(NetworkStateHandler* network_state_handler,
131 NetworkProfileHandler* network_profile_handler,
132 NetworkConfigurationHandler* network_configuration_handler,
133 NetworkDeviceHandler* network_device_handler);
135 // Sends the response to the caller of GetManagedProperties.
136 void SendManagedProperties(
137 const std::string& userhash,
138 const network_handler::DictionaryResultCallback& callback,
139 const network_handler::ErrorCallback& error_callback,
140 const std::string& service_path,
141 scoped_ptr<base::DictionaryValue> shill_properties);
143 // Sends the response to the caller of GetProperties.
144 void SendProperties(const std::string& userhash,
145 const network_handler::DictionaryResultCallback& callback,
146 const network_handler::ErrorCallback& error_callback,
147 const std::string& service_path,
148 scoped_ptr<base::DictionaryValue> shill_properties);
150 const Policies* GetPoliciesForUser(const std::string& userhash) const;
151 const Policies* GetPoliciesForProfile(const NetworkProfile& profile) const;
153 void OnPolicyAppliedToNetwork(const std::string& service_path);
155 // Helper method to append associated Device properties to |properties|.
156 void GetDeviceStateProperties(const std::string& service_path,
157 base::DictionaryValue* properties);
159 // Callback for NetworkConfigurationHandler::GetProperties requests from
160 // Get{Managed}Properties. This callback fills in properties from
161 // DeviceState and may request additional Device properties.
162 // Note: Requesting Device properties requires an additional fetch and
163 // additional copying of data, so we only do it for Cellular networks which
164 // contain a lot of necessary state in the associated Device object.
165 void GetPropertiesCallback(
166 GetDevicePropertiesCallback send_callback,
167 const std::string& service_path,
168 const base::DictionaryValue& shill_properties);
170 void GetDevicePropertiesSuccess(
171 const std::string& service_path,
172 scoped_ptr<base::DictionaryValue> network_properties,
173 GetDevicePropertiesCallback send_callback,
174 const std::string& device_path,
175 const base::DictionaryValue& device_properties);
176 void GetDevicePropertiesFailure(
177 const std::string& service_path,
178 scoped_ptr<base::DictionaryValue> network_properties,
179 GetDevicePropertiesCallback send_callback,
180 const std::string& error_name,
181 scoped_ptr<base::DictionaryValue> error_data);
183 // Called from SetProperties, calls NCH::SetShillProperties.
184 void SetShillProperties(const std::string& service_path,
185 scoped_ptr<base::DictionaryValue> shill_dictionary,
186 const base::Closure& callback,
187 const network_handler::ErrorCallback& error_callback);
189 // Applies policies for |userhash|. |modified_policies| must be not null and
190 // contain the GUIDs of the network configurations that changed since the last
191 // policy application. Returns true if policy application was started and
192 // false if it was queued or delayed.
193 bool ApplyOrQueuePolicies(const std::string& userhash,
194 std::set<std::string>* modified_policies);
196 // If present, the empty string maps to the device policy.
197 UserToPoliciesMap policies_by_user_;
199 // Local references to the associated handler instances.
200 NetworkStateHandler* network_state_handler_;
201 NetworkProfileHandler* network_profile_handler_;
202 NetworkConfigurationHandler* network_configuration_handler_;
203 NetworkDeviceHandler* network_device_handler_;
205 // Owns the currently running PolicyApplicators.
206 UserToPolicyApplicatorMap policy_applicators_;
208 // Per userhash (or empty string for device policy), contains the GUIDs of the
209 // policies that were modified.
210 // If this map contains a userhash as key, it means that a policy application
211 // for this userhash is pending even if no policies were modified and the
212 // associated set of GUIDs is empty.
213 UserToModifiedPoliciesMap queued_modified_policies_;
215 base::ObserverList<NetworkPolicyObserver> observers_;
217 // For Shill client callbacks
218 base::WeakPtrFactory<ManagedNetworkConfigurationHandlerImpl>
219 weak_ptr_factory_;
221 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerImpl);
224 } // namespace chromeos
226 #endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_IMPL_H_