network_configuration_handler.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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 <string> 9#include <vector> 10 11#include "base/basictypes.h" 12#include "base/callback.h" 13#include "base/gtest_prod_util.h" 14#include "base/memory/weak_ptr.h" 15#include "chromeos/chromeos_export.h" 16#include "chromeos/network/network_handler.h" 17#include "chromeos/network/network_handler_callbacks.h" 18 19namespace base { 20class DictionaryValue; 21} 22 23namespace dbus { 24class ObjectPath; 25} 26 27namespace chromeos { 28 29// The NetworkConfigurationHandler class is used to create and configure 30// networks in ChromeOS. It mostly calls through to the Shill service API, and 31// most calls are asynchronous for that reason. No calls will block on DBus 32// calls. 33// 34// This is owned and it's lifetime managed by the Chrome startup code. It's 35// basically a singleton, but with explicit lifetime management. 36// 37// For accessing lists of remembered networks, and other state information, see 38// the class NetworkStateHandler. 39// 40// Note on callbacks: Because all the functions here are meant to be 41// asynchronous, they all take a |callback| of some type, and an 42// |error_callback|. When the operation succeeds, |callback| will be called, and 43// when it doesn't, |error_callback| will be called with information about the 44// error, including a symbolic name for the error and often some error message 45// that is suitable for logging. None of the error message text is meant for 46// user consumption. 47 48class CHROMEOS_EXPORT NetworkConfigurationHandler 49 : public base::SupportsWeakPtr<NetworkConfigurationHandler> { 50 public: 51 ~NetworkConfigurationHandler(); 52 53 // Gets the properties of the network with id |service_path|. See note on 54 // |callback| and |error_callback|, in class description above. 55 void GetProperties( 56 const std::string& service_path, 57 const network_handler::DictionaryResultCallback& callback, 58 const network_handler::ErrorCallback& error_callback) const; 59 60 // Sets the properties of the network with id |service_path|. This means the 61 // given properties will be merged with the existing settings, and it won't 62 // clear any existing properties. See note on |callback| and |error_callback|, 63 // in class description above. 64 void SetProperties( 65 const std::string& service_path, 66 const base::DictionaryValue& properties, 67 const base::Closure& callback, 68 const network_handler::ErrorCallback& error_callback) const; 69 70 // Removes the properties with the given property paths. If any of them are 71 // unable to be cleared, the |error_callback| will only be run once with 72 // accumulated information about all of the errors as a list attached to the 73 // "errors" key of the error data, and the |callback| will not be run, even 74 // though some of the properties may have been cleared. If there are no 75 // errors, |callback| will be run. 76 void ClearProperties(const std::string& service_path, 77 const std::vector<std::string>& property_paths, 78 const base::Closure& callback, 79 const network_handler::ErrorCallback& error_callback); 80 81 // Creates a network with the given properties in the active Shill profile, 82 // and returns the new service_path to |callback| if successful. See note on 83 // |callback| and |error_callback|, in class description above. 84 // This may also be used to update an existing matching configuration, see 85 // Shill documentation for Manager.ConfigureService and Manger.GetService. 86 void CreateConfiguration( 87 const base::DictionaryValue& properties, 88 const network_handler::StringResultCallback& callback, 89 const network_handler::ErrorCallback& error_callback); 90 91 // Removes the network |service_path| from the remembered network list in the 92 // active Shill profile. The network may still show up in the visible networks 93 // after this, but no profile configuration will remain. See note on 94 // |callback| and |error_callback|, in class description above. 95 void RemoveConfiguration( 96 const std::string& service_path, 97 const base::Closure& callback, 98 const network_handler::ErrorCallback& error_callback) const; 99 100 // Construct and initialize an instance for testing. 101 static NetworkConfigurationHandler* InitializeForTest( 102 NetworkStateHandler* network_state_handler); 103 104 protected: 105 friend class NetworkHandler; 106 friend class NetworkConfigurationHandlerTest; 107 108 NetworkConfigurationHandler(); 109 void Init(NetworkStateHandler* network_state_handler); 110 111 void RunCreateNetworkCallback( 112 const network_handler::StringResultCallback& callback, 113 const dbus::ObjectPath& service_path); 114 115 NetworkStateHandler* network_state_handler_; 116 117 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationHandler); 118}; 119 120} // namespace chromeos 121 122#endif // CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_ 123