network_configuration_handler.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
1// Copyright (c) 2012 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_NETWORK_CONFIGURATION_HANDLER_H_ 6#define CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ 7 8#include <map> 9#include <set> 10#include <string> 11#include <vector> 12 13#include "base/basictypes.h" 14#include "base/callback.h" 15#include "base/gtest_prod_util.h" 16#include "base/memory/weak_ptr.h" 17#include "chromeos/chromeos_export.h" 18#include "chromeos/dbus/dbus_method_call_status.h" 19#include "chromeos/network/network_handler.h" 20#include "chromeos/network/network_handler_callbacks.h" 21 22namespace base { 23class DictionaryValue; 24} 25 26namespace dbus { 27class ObjectPath; 28} 29 30namespace chromeos { 31 32// The NetworkConfigurationHandler class is used to create and configure 33// networks in ChromeOS. It mostly calls through to the Shill service API, and 34// most calls are asynchronous for that reason. No calls will block on DBus 35// calls. 36// 37// This is owned and it's lifetime managed by the Chrome startup code. It's 38// basically a singleton, but with explicit lifetime management. 39// 40// For accessing lists of remembered networks, and other state information, see 41// the class NetworkStateHandler. 42// 43// Note on callbacks: Because all the functions here are meant to be 44// asynchronous, they all take a |callback| of some type, and an 45// |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 47// 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 49// user consumption. 50 51class CHROMEOS_EXPORT NetworkConfigurationHandler 52 : public base::SupportsWeakPtr<NetworkConfigurationHandler> { 53 public: 54 ~NetworkConfigurationHandler(); 55 56 // Gets the properties of the network with id |service_path|. See note on 57 // |callback| and |error_callback|, in class description above. 58 void GetProperties( 59 const std::string& service_path, 60 const network_handler::DictionaryResultCallback& callback, 61 const network_handler::ErrorCallback& error_callback) const; 62 63 // Sets the properties of the network with id |service_path|. This means the 64 // given properties will be merged with the existing settings, and it won't 65 // clear any existing properties. See note on |callback| and |error_callback|, 66 // in class description above. 67 void SetProperties( 68 const std::string& service_path, 69 const base::DictionaryValue& properties, 70 const base::Closure& callback, 71 const network_handler::ErrorCallback& error_callback); 72 73 // Removes the properties with the given property paths. If any of them are 74 // unable to be cleared, the |error_callback| will only be run once with 75 // accumulated information about all of the errors as a list attached to the 76 // "errors" key of the error data, and the |callback| will not be run, even 77 // though some of the properties may have been cleared. If there are no 78 // errors, |callback| will be run. 79 void ClearProperties(const std::string& service_path, 80 const std::vector<std::string>& property_paths, 81 const base::Closure& callback, 82 const network_handler::ErrorCallback& error_callback); 83 84 // Creates a network with the given properties in the active Shill profile, 85 // and returns the new service_path to |callback| if successful. See note on 86 // |callback| and |error_callback|, in class description above. 87 // This may also be used to update an existing matching configuration, see 88 // Shill documentation for Manager.ConfigureService and Manger.GetService. 89 void CreateConfiguration( 90 const base::DictionaryValue& properties, 91 const network_handler::StringResultCallback& callback, 92 const network_handler::ErrorCallback& error_callback); 93 94 // Removes the network |service_path| from any profiles that include it. 95 // See note on |callback| and |error_callback| in class description above. 96 void RemoveConfiguration( 97 const std::string& service_path, 98 const base::Closure& callback, 99 const network_handler::ErrorCallback& error_callback); 100 101 // Construct and initialize an instance for testing. 102 static NetworkConfigurationHandler* InitializeForTest( 103 NetworkStateHandler* network_state_handler); 104 105 protected: 106 friend class NetworkHandler; 107 friend class NetworkConfigurationHandlerTest; 108 class ProfileEntryDeleter; 109 110 NetworkConfigurationHandler(); 111 void Init(NetworkStateHandler* network_state_handler); 112 113 void RunCreateNetworkCallback( 114 const network_handler::StringResultCallback& callback, 115 const dbus::ObjectPath& service_path); 116 117 // Called from ProfileEntryDeleter instances when they complete causing 118 // this class to delete the instance. 119 void ProfileEntryDeleterCompleted(const std::string& service_path); 120 bool PendingProfileEntryDeleterForTest(const std::string& service_path) { 121 return profile_entry_deleters_.count(service_path); 122 } 123 124 // Invoke the callback and inform NetworkStateHandler to request an update 125 // for the service. 126 void SetPropertiesSuccessCallback(const std::string& service_path, 127 const base::Closure& callback); 128 void SetPropertiesErrorCallback( 129 const std::string& service_path, 130 const network_handler::ErrorCallback& error_callback, 131 const std::string& dbus_error_name, 132 const std::string& dbus_error_message); 133 134 // Unowned associated NetworkStateHandler* (global or test instance). 135 NetworkStateHandler* network_state_handler_; 136 137 // Map of in-progress deleter instances. Owned by this class. 138 std::map<std::string, ProfileEntryDeleter*> profile_entry_deleters_; 139 140 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationHandler); 141}; 142 143} // namespace chromeos 144 145#endif // CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ 146