| OLD | NEW |
| 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.h" |
| 16 #include "chromeos/network/network_handler_callbacks.h" | 17 #include "chromeos/network/network_handler_callbacks.h" |
| 17 #include "chromeos/network/network_profile_observer.h" | 18 #include "chromeos/network/network_profile_observer.h" |
| 18 #include "chromeos/network/onc/onc_constants.h" | 19 #include "chromeos/network/onc/onc_constants.h" |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class DictionaryValue; | 22 class DictionaryValue; |
| 22 class ListValue; | 23 class ListValue; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 | 27 |
| 27 class NetworkProfileHandler; | |
| 28 | |
| 29 // The ManagedNetworkConfigurationHandler class is used to create and configure | 28 // The ManagedNetworkConfigurationHandler class is used to create and configure |
| 30 // networks in ChromeOS using ONC and takes care of network policies. | 29 // networks in ChromeOS using ONC and takes care of network policies. |
| 31 // | 30 // |
| 32 // Its interface exposes only ONC and should decouple users from Shill. | 31 // Its interface exposes only ONC and should decouple users from Shill. |
| 33 // Internally it translates ONC to Shill dictionaries and calls through to the | 32 // Internally it translates ONC to Shill dictionaries and calls through to the |
| 34 // NetworkConfigurationHandler. | 33 // NetworkConfigurationHandler. |
| 35 // | 34 // |
| 36 // For accessing lists of visible networks, and other state information, see the | 35 // For accessing lists of visible networks, and other state information, see the |
| 37 // class NetworkStateHandler. | 36 // class NetworkStateHandler. |
| 38 // | 37 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 50 // error, including a symbolic name for the error and often some error message | 49 // error, including a symbolic name for the error and often some error message |
| 51 // that is suitable for logging. None of the error message text is meant for | 50 // that is suitable for logging. None of the error message text is meant for |
| 52 // user consumption. | 51 // user consumption. |
| 53 | 52 |
| 54 class CHROMEOS_EXPORT ManagedNetworkConfigurationHandler | 53 class CHROMEOS_EXPORT ManagedNetworkConfigurationHandler |
| 55 : public NetworkProfileObserver { | 54 : public NetworkProfileObserver { |
| 56 public: | 55 public: |
| 57 typedef std::map<std::string, const base::DictionaryValue*> GuidToPolicyMap; | 56 typedef std::map<std::string, const base::DictionaryValue*> GuidToPolicyMap; |
| 58 typedef std::map<std::string, GuidToPolicyMap> UserToPoliciesMap; | 57 typedef std::map<std::string, GuidToPolicyMap> UserToPoliciesMap; |
| 59 | 58 |
| 60 // Initializes the singleton. | 59 virtual ~ManagedNetworkConfigurationHandler(); |
| 61 static void Initialize(NetworkProfileHandler* profile_handler); | |
| 62 | |
| 63 // Returns if the singleton is initialized. | |
| 64 static bool IsInitialized(); | |
| 65 | |
| 66 // Destroys the singleton. | |
| 67 static void Shutdown(); | |
| 68 | |
| 69 // Initialize() must be called before this. | |
| 70 static ManagedNetworkConfigurationHandler* Get(); | |
| 71 | 60 |
| 72 // Provides the properties of the network with |service_path| to |callback|. | 61 // Provides the properties of the network with |service_path| to |callback|. |
| 73 void GetProperties( | 62 void GetProperties( |
| 74 const std::string& service_path, | 63 const std::string& service_path, |
| 75 const network_handler::DictionaryResultCallback& callback, | 64 const network_handler::DictionaryResultCallback& callback, |
| 76 const network_handler::ErrorCallback& error_callback) const; | 65 const network_handler::ErrorCallback& error_callback) const; |
| 77 | 66 |
| 78 // Provides the managed properties of the network with |service_path| to | 67 // Provides the managed properties of the network with |service_path| to |
| 79 // |callback|. |userhash| is only used to ensure that the user's policy is | 68 // |callback|. |userhash| is only used to ensure that the user's policy is |
| 80 // already applied. | 69 // already applied. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // device policies, |userhash| must be empty. | 125 // device policies, |userhash| must be empty. |
| 137 void SetPolicy(onc::ONCSource onc_source, | 126 void SetPolicy(onc::ONCSource onc_source, |
| 138 const std::string& userhash, | 127 const std::string& userhash, |
| 139 const base::ListValue& network_configs_onc); | 128 const base::ListValue& network_configs_onc); |
| 140 | 129 |
| 141 // NetworkProfileObserver overrides | 130 // NetworkProfileObserver overrides |
| 142 virtual void OnProfileAdded(const NetworkProfile& profile) OVERRIDE; | 131 virtual void OnProfileAdded(const NetworkProfile& profile) OVERRIDE; |
| 143 virtual void OnProfileRemoved(const NetworkProfile& profile) OVERRIDE; | 132 virtual void OnProfileRemoved(const NetworkProfile& profile) OVERRIDE; |
| 144 | 133 |
| 145 private: | 134 private: |
| 135 friend class NetworkHandler; |
| 146 class PolicyApplicator; | 136 class PolicyApplicator; |
| 147 | 137 |
| 148 explicit ManagedNetworkConfigurationHandler( | 138 ManagedNetworkConfigurationHandler(); |
| 149 NetworkProfileHandler* profile_handler); | 139 void Init(); |
| 150 virtual ~ManagedNetworkConfigurationHandler(); | |
| 151 | 140 |
| 152 void GetManagedPropertiesCallback( | 141 void GetManagedPropertiesCallback( |
| 153 const network_handler::DictionaryResultCallback& callback, | 142 const network_handler::DictionaryResultCallback& callback, |
| 154 const network_handler::ErrorCallback& error_callback, | 143 const network_handler::ErrorCallback& error_callback, |
| 155 const std::string& service_path, | 144 const std::string& service_path, |
| 156 const base::DictionaryValue& shill_properties); | 145 const base::DictionaryValue& shill_properties); |
| 157 | 146 |
| 158 const GuidToPolicyMap* GetPoliciesForUser(const std::string& userhash) const; | 147 const GuidToPolicyMap* GetPoliciesForUser(const std::string& userhash) const; |
| 159 const GuidToPolicyMap* GetPoliciesForProfile( | 148 const GuidToPolicyMap* GetPoliciesForProfile( |
| 160 const NetworkProfile& profile) const; | 149 const NetworkProfile& profile) const; |
| 161 | 150 |
| 162 // The DictionaryValues of the nested maps are owned by this class and are | 151 // The DictionaryValues of the nested maps are owned by this class and are |
| 163 // explicitly deleted where necessary. If present, the empty string maps to | 152 // explicitly deleted where necessary. If present, the empty string maps to |
| 164 // the device policy. | 153 // the device policy. |
| 165 UserToPoliciesMap policies_by_user_; | 154 UserToPoliciesMap policies_by_user_; |
| 166 | 155 |
| 167 // A local reference to the policy handler singleton. | |
| 168 NetworkProfileHandler* profile_handler_; | |
| 169 | |
| 170 // For Shill client callbacks | 156 // For Shill client callbacks |
| 171 base::WeakPtrFactory<ManagedNetworkConfigurationHandler> weak_ptr_factory_; | 157 base::WeakPtrFactory<ManagedNetworkConfigurationHandler> weak_ptr_factory_; |
| 172 | 158 |
| 173 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandler); | 159 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandler); |
| 174 }; | 160 }; |
| 175 | 161 |
| 176 } // namespace chromeos | 162 } // namespace chromeos |
| 177 | 163 |
| 178 #endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ | 164 #endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ |
| OLD | NEW |