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