Chromium Code Reviews| 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_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 typedef std::map<std::string, const base::DictionaryValue*> GuidToPolicy; |
|
stevenjb
2013/04/30 17:42:47
nit: Even though the Map is implicit, I think that
pneubeck (no reviews)
2013/05/03 17:32:55
Done for both typenames.
| |
| 58 typedef std::map<std::string, GuidToPolicy> UserToPolicies; | |
| 54 | 59 |
| 55 // Initializes the singleton. | 60 // Initializes the singleton. |
| 56 static void Initialize(); | 61 static void Initialize(NetworkProfileHandler* profile_handler); |
| 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 Loading... | |
| 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 GuidToPolicy* GetPoliciesForUser(const std::string& userhash) const; |
| 159 const GuidToPolicy* GetPoliciesForProfile( | |
| 160 const NetworkProfile& profile) const; | |
| 144 | 161 |
| 145 // The entries of these maps are owned by this class and are explicitly | 162 // The DictionaryValues of the nested maps are owned by this class and are |
| 146 // deleted where necessary. | 163 // explicitly deleted where necessary. If present, the empty string maps to |
| 147 PolicyMap user_policies_by_guid_; | 164 // the device policy. |
| 148 PolicyMap device_policies_by_guid_; | 165 UserToPolicies policies_by_user_; |
| 149 bool user_policies_initialized_; | 166 |
| 150 bool device_policies_initialized_; | 167 // A local reference to the policy handler singleton. |
| 168 NetworkProfileHandler* profile_handler_; | |
| 151 | 169 |
| 152 // For Shill client callbacks | 170 // For Shill client callbacks |
| 153 base::WeakPtrFactory<ManagedNetworkConfigurationHandler> weak_ptr_factory_; | 171 base::WeakPtrFactory<ManagedNetworkConfigurationHandler> weak_ptr_factory_; |
| 154 | 172 |
| 155 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandler); | 173 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandler); |
| 156 }; | 174 }; |
| 157 | 175 |
| 158 } // namespace chromeos | 176 } // namespace chromeos |
| 159 | 177 |
| 160 #endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ | 178 #endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ |
| OLD | NEW |