Disabling flaky test ChromeRenderProcessHostTestWithCommandLine.ProcessOverflow flaky...
[chromium-blink-merge.git] / chromeos / network / network_configuration_handler.h
blob4b404d8a9c42898229ebb505c3deb771950c538c
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.
5 #ifndef CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_
6 #define CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/callback.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/observer_list.h"
19 #include "chromeos/chromeos_export.h"
20 #include "chromeos/dbus/dbus_method_call_status.h"
21 #include "chromeos/network/network_configuration_observer.h"
22 #include "chromeos/network/network_handler.h"
23 #include "chromeos/network/network_handler_callbacks.h"
25 namespace base {
26 class DictionaryValue;
27 class ListValue;
30 namespace dbus {
31 class ObjectPath;
34 namespace chromeos {
36 // The NetworkConfigurationHandler class is used to create and configure
37 // networks in ChromeOS. It mostly calls through to the Shill service API, and
38 // most calls are asynchronous for that reason. No calls will block on DBus
39 // calls.
41 // This is owned and it's lifetime managed by the Chrome startup code. It's
42 // basically a singleton, but with explicit lifetime management.
44 // For accessing lists of remembered networks, and other state information, see
45 // the class NetworkStateHandler.
47 // |source| is provided to several of these methods so that it can be passed
48 // along to any observers. See notes in network_configuration_observer.h.
50 // Note on callbacks: Because all the functions here are meant to be
51 // asynchronous, they all take a |callback| of some type, and an
52 // |error_callback|. When the operation succeeds, |callback| will be called, and
53 // when it doesn't, |error_callback| will be called with information about the
54 // error, including a symbolic name for the error and often some error message
55 // that is suitable for logging. None of the error message text is meant for
56 // user consumption. Both |callback| and |error_callback| are permitted to be
57 // null callbacks.
58 class CHROMEOS_EXPORT NetworkConfigurationHandler
59 : public base::SupportsWeakPtr<NetworkConfigurationHandler> {
60 public:
61 ~NetworkConfigurationHandler();
63 // Manages the observer list.
64 void AddObserver(NetworkConfigurationObserver* observer);
65 void RemoveObserver(NetworkConfigurationObserver* observer);
67 // Gets the properties of the network with id |service_path|. See note on
68 // |callback| and |error_callback|, in class description above.
69 void GetProperties(
70 const std::string& service_path,
71 const network_handler::DictionaryResultCallback& callback,
72 const network_handler::ErrorCallback& error_callback) const;
74 // Sets the properties of the network with id |service_path|. This means the
75 // given properties will be merged with the existing settings, and it won't
76 // clear any existing properties. See notes on |source| and callbacks in class
77 // description above.
78 void SetProperties(const std::string& service_path,
79 const base::DictionaryValue& properties,
80 NetworkConfigurationObserver::Source source,
81 const base::Closure& callback,
82 const network_handler::ErrorCallback& error_callback);
84 // Removes the properties with the given property paths. If any of them are
85 // unable to be cleared, the |error_callback| will only be run once with
86 // accumulated information about all of the errors as a list attached to the
87 // "errors" key of the error data, and the |callback| will not be run, even
88 // though some of the properties may have been cleared. If there are no
89 // errors, |callback| will be run.
90 void ClearProperties(const std::string& service_path,
91 const std::vector<std::string>& property_paths,
92 const base::Closure& callback,
93 const network_handler::ErrorCallback& error_callback);
95 // Creates a network with the given |properties| in the specified Shill
96 // profile, and returns the new service_path to |callback| if successful.
97 // kProfileProperty must be set in |properties|. See notes on |source| and
98 // callbacks in class description above. This may also be used to update an
99 // existing matching configuration, see Shill documentation for
100 // Manager.ConfigureServiceForProfile.
101 void CreateConfiguration(
102 const base::DictionaryValue& properties,
103 NetworkConfigurationObserver::Source source,
104 const network_handler::StringResultCallback& callback,
105 const network_handler::ErrorCallback& error_callback);
107 // Removes the network |service_path| from any profiles that include it.
108 // See notes on |source| and callbacks in class description above.
109 void RemoveConfiguration(
110 const std::string& service_path,
111 NetworkConfigurationObserver::Source source,
112 const base::Closure& callback,
113 const network_handler::ErrorCallback& error_callback);
115 // Changes the profile for the network |service_path| to |profile_path|.
116 // See notes on |source| and callbacks in class description above.
117 void SetNetworkProfile(const std::string& service_path,
118 const std::string& profile_path,
119 NetworkConfigurationObserver::Source source,
120 const base::Closure& callback,
121 const network_handler::ErrorCallback& error_callback);
123 // Construct and initialize an instance for testing.
124 static NetworkConfigurationHandler* InitializeForTest(
125 NetworkStateHandler* network_state_handler,
126 NetworkDeviceHandler* network_device_handler);
128 protected:
129 friend class ClientCertResolverTest;
130 friend class NetworkHandler;
131 friend class NetworkConfigurationHandlerTest;
132 friend class NetworkConfigurationHandlerStubTest;
133 class ProfileEntryDeleter;
135 NetworkConfigurationHandler();
136 void Init(NetworkStateHandler* network_state_handler,
137 NetworkDeviceHandler* network_device_handler);
139 void RunCreateNetworkCallback(
140 const std::string& profile_path,
141 NetworkConfigurationObserver::Source source,
142 scoped_ptr<base::DictionaryValue> configure_properties,
143 const network_handler::StringResultCallback& callback,
144 const dbus::ObjectPath& service_path);
146 // Called from ProfileEntryDeleter instances when they complete causing
147 // this class to delete the instance.
148 void ProfileEntryDeleterCompleted(const std::string& service_path,
149 const std::string& guid,
150 NetworkConfigurationObserver::Source source,
151 bool success);
152 bool PendingProfileEntryDeleterForTest(const std::string& service_path) {
153 return profile_entry_deleters_.count(service_path);
156 // Callback after moving a network configuration.
157 void SetNetworkProfileCompleted(const std::string& service_path,
158 const std::string& profile_path,
159 NetworkConfigurationObserver::Source source,
160 const base::Closure& callback);
162 // Invoke the callback and inform NetworkStateHandler to request an update
163 // for the service after setting properties.
164 void SetPropertiesSuccessCallback(
165 const std::string& service_path,
166 scoped_ptr<base::DictionaryValue> set_properties,
167 NetworkConfigurationObserver::Source source,
168 const base::Closure& callback);
169 void SetPropertiesErrorCallback(
170 const std::string& service_path,
171 const network_handler::ErrorCallback& error_callback,
172 const std::string& dbus_error_name,
173 const std::string& dbus_error_message);
175 // Invoke the callback and inform NetworkStateHandler to request an update
176 // for the service after clearing properties.
177 void ClearPropertiesSuccessCallback(
178 const std::string& service_path,
179 const std::vector<std::string>& names,
180 const base::Closure& callback,
181 const base::ListValue& result);
182 void ClearPropertiesErrorCallback(
183 const std::string& service_path,
184 const network_handler::ErrorCallback& error_callback,
185 const std::string& dbus_error_name,
186 const std::string& dbus_error_message);
188 // Signals the device handler to request an IP config refresh.
189 void RequestRefreshIPConfigs(const std::string& service_path);
191 // Unowned associated Network*Handlers (global or test instance).
192 NetworkStateHandler* network_state_handler_;
193 NetworkDeviceHandler* network_device_handler_;
195 // Map of in-progress deleter instances. Owned by this class.
196 std::map<std::string, ProfileEntryDeleter*> profile_entry_deleters_;
198 ObserverList<NetworkConfigurationObserver> observers_;
200 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationHandler);
203 } // namespace chromeos
205 #endif // CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_