managed_network_configuration_handler.h revision 3551c9c881056c480085172ff9840cab31610854
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 3// found in the LICENSE file. 4 5#ifndef CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ 6#define CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/callback.h" 12#include "base/compiler_specific.h" 13#include "base/memory/scoped_ptr.h" 14#include "base/observer_list.h" 15#include "chromeos/chromeos_export.h" 16#include "chromeos/network/network_handler.h" 17#include "chromeos/network/network_handler_callbacks.h" 18#include "chromeos/network/onc/onc_constants.h" 19 20namespace base { 21class DictionaryValue; 22class ListValue; 23} 24 25namespace chromeos { 26 27class NetworkPolicyObserver; 28class NetworkUIData; 29 30// The ManagedNetworkConfigurationHandler class is used to create and configure 31// networks in ChromeOS using ONC and takes care of network policies. 32// 33// Its interface exposes only ONC and should decouple users from Shill. 34// Internally it translates ONC to Shill dictionaries and calls through to the 35// NetworkConfigurationHandler. 36// 37// For accessing lists of visible networks, and other state information, see the 38// class NetworkStateHandler. 39// 40// This is a singleton and its lifetime is managed by the Chrome startup code. 41// 42// Network configurations are referred to by Shill's service path. These 43// identifiers should at most be used to also access network state using the 44// NetworkStateHandler, but dependencies to Shill should be avoided. In the 45// future, we may switch to other identifiers. 46// 47// Note on callbacks: Because all the functions here are meant to be 48// asynchronous, they all take a |callback| of some type, and an 49// |error_callback|. When the operation succeeds, |callback| will be called, and 50// when it doesn't, |error_callback| will be called with information about the 51// error, including a symbolic name for the error and often some error message 52// that is suitable for logging. None of the error message text is meant for 53// user consumption. 54class CHROMEOS_EXPORT ManagedNetworkConfigurationHandler { 55 public: 56 virtual ~ManagedNetworkConfigurationHandler(); 57 58 // Returns the NetworkUIData parsed from the UIData property of 59 // |shill_dictionary|. If parsing fails or the field doesn't exist, returns 60 // NULL. 61 static scoped_ptr<NetworkUIData> GetUIData( 62 const base::DictionaryValue& shill_dictionary); 63 64 virtual void AddObserver(NetworkPolicyObserver* observer) = 0; 65 virtual void RemoveObserver(NetworkPolicyObserver* observer) = 0; 66 67 // Provides the properties of the network with |service_path| to |callback|. 68 virtual void GetProperties( 69 const std::string& service_path, 70 const network_handler::DictionaryResultCallback& callback, 71 const network_handler::ErrorCallback& error_callback) const = 0; 72 73 // Provides the managed properties of the network with |service_path| to 74 // |callback|. |userhash| is only used to ensure that the user's policy is 75 // already applied. 76 virtual void GetManagedProperties( 77 const std::string& userhash, 78 const std::string& service_path, 79 const network_handler::DictionaryResultCallback& callback, 80 const network_handler::ErrorCallback& error_callback) = 0; 81 82 // Sets the user's settings of an already configured network with 83 // |service_path|. A network can be initially configured by calling 84 // CreateConfiguration or if it is managed by a policy. The given properties 85 // will be merged with the existing settings, and it won't clear any existing 86 // properties. 87 virtual void SetProperties( 88 const std::string& service_path, 89 const base::DictionaryValue& user_settings, 90 const base::Closure& callback, 91 const network_handler::ErrorCallback& error_callback) const = 0; 92 93 // Initially configures an unconfigured network with the given user settings 94 // and returns the new identifier to |callback| if successful. Fails if the 95 // network was already configured by a call to this function or because of a 96 // policy. The new configuration will be owned by user |userhash|. If 97 // |userhash| is empty, the new configuration will be shared. 98 virtual void CreateConfiguration( 99 const std::string& userhash, 100 const base::DictionaryValue& properties, 101 const network_handler::StringResultCallback& callback, 102 const network_handler::ErrorCallback& error_callback) const = 0; 103 104 // Removes the user's configuration from the network with |service_path|. The 105 // network may still show up in the visible networks after this, but no user 106 // configuration will remain. If it was managed, it will still be configured. 107 virtual void RemoveConfiguration( 108 const std::string& service_path, 109 const base::Closure& callback, 110 const network_handler::ErrorCallback& error_callback) const = 0; 111 112 // Only to be called by NetworkConfigurationUpdater or from tests. Sets 113 // |network_configs_onc| as the current policy of |onc_source|. The network 114 // configurations of the policy will be applied (not necessarily immediately) 115 // to Shill's profiles and enforced in future configurations until the policy 116 // associated with |onc_source| is changed again with this function. For 117 // device policies, |userhash| must be empty. 118 virtual void SetPolicy(onc::ONCSource onc_source, 119 const std::string& userhash, 120 const base::ListValue& network_configs_onc) = 0; 121 122 // Returns the user policy for user |userhash| or device policy, which has 123 // |guid|. If |userhash| is empty, only looks for a device policy. If such 124 // doesn't exist, returns NULL. Sets |onc_source| accordingly. 125 virtual const base::DictionaryValue* FindPolicyByGUID( 126 const std::string userhash, 127 const std::string& guid, 128 onc::ONCSource* onc_source) const = 0; 129 130 // Returns the policy with |guid| for profile |profile_path|. If such 131 // doesn't exist, returns NULL. 132 virtual const base::DictionaryValue* FindPolicyByGuidAndProfile( 133 const std::string& guid, 134 const std::string& profile_path) const = 0; 135 136 private: 137 DISALLOW_ASSIGN(ManagedNetworkConfigurationHandler); 138}; 139 140} // namespace chromeos 141 142#endif // CHROMEOS_NETWORK_MANAGED_NETWORK_CONFIGURATION_HANDLER_H_ 143