cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chromeos / network / network_configuration_handler.h
blob1c6abaec705c79f8e2e6ce5b2241924d07de8dc1
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 GetShillProperties(
70 const std::string& service_path,
71 const network_handler::DictionaryResultCallback& callback,
72 const network_handler::ErrorCallback& error_callback);
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 SetShillProperties(const std::string& service_path,
79 const base::DictionaryValue& shill_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 ClearShillProperties(
91 const std::string& service_path,
92 const std::vector<std::string>& property_paths,
93 const base::Closure& callback,
94 const network_handler::ErrorCallback& error_callback);
96 // Creates a network with the given |properties| in the specified Shill
97 // profile, and returns the new service_path to |callback| if successful.
98 // kProfileProperty must be set in |properties|. See notes on |source| and
99 // callbacks in class description above. This may also be used to update an
100 // existing matching configuration, see Shill documentation for
101 // Manager.ConfigureServiceForProfile. NOTE: Normally
102 // ManagedNetworkConfigurationHandler should be used to call
103 // CreateConfiguration. This will set GUID if not provided.
104 void CreateShillConfiguration(
105 const base::DictionaryValue& shill_properties,
106 NetworkConfigurationObserver::Source source,
107 const network_handler::StringResultCallback& callback,
108 const network_handler::ErrorCallback& error_callback);
110 // Removes the network |service_path| from any profiles that include it.
111 // See notes on |source| and callbacks in class description above.
112 void RemoveConfiguration(
113 const std::string& service_path,
114 NetworkConfigurationObserver::Source source,
115 const base::Closure& callback,
116 const network_handler::ErrorCallback& error_callback);
118 // Changes the profile for the network |service_path| to |profile_path|.
119 // See notes on |source| and callbacks in class description above.
120 void SetNetworkProfile(const std::string& service_path,
121 const std::string& profile_path,
122 NetworkConfigurationObserver::Source source,
123 const base::Closure& callback,
124 const network_handler::ErrorCallback& error_callback);
126 // Construct and initialize an instance for testing.
127 static NetworkConfigurationHandler* InitializeForTest(
128 NetworkStateHandler* network_state_handler,
129 NetworkDeviceHandler* network_device_handler);
131 private:
132 friend class ClientCertResolverTest;
133 friend class NetworkHandler;
134 friend class NetworkConfigurationHandlerTest;
135 friend class NetworkConfigurationHandlerStubTest;
136 class ProfileEntryDeleter;
138 NetworkConfigurationHandler();
139 void Init(NetworkStateHandler* network_state_handler,
140 NetworkDeviceHandler* network_device_handler);
142 void RunCreateNetworkCallback(
143 const std::string& profile_path,
144 NetworkConfigurationObserver::Source source,
145 scoped_ptr<base::DictionaryValue> configure_properties,
146 const network_handler::StringResultCallback& callback,
147 const dbus::ObjectPath& service_path);
149 // Called from ProfileEntryDeleter instances when they complete causing
150 // this class to delete the instance.
151 void ProfileEntryDeleterCompleted(const std::string& service_path,
152 const std::string& guid,
153 NetworkConfigurationObserver::Source source,
154 bool success);
155 bool PendingProfileEntryDeleterForTest(const std::string& service_path) {
156 return profile_entry_deleters_.count(service_path);
159 // Callback after moving a network configuration.
160 void SetNetworkProfileCompleted(const std::string& service_path,
161 const std::string& profile_path,
162 NetworkConfigurationObserver::Source source,
163 const base::Closure& callback);
165 // Set the Name and GUID properties correctly and Invoke |callback|.
166 void GetPropertiesCallback(
167 const network_handler::DictionaryResultCallback& callback,
168 const network_handler::ErrorCallback& error_callback,
169 const std::string& service_path,
170 DBusMethodCallStatus call_status,
171 const base::DictionaryValue& properties);
173 // Invoke |callback| and inform NetworkStateHandler to request an update
174 // for the service after setting properties.
175 void SetPropertiesSuccessCallback(
176 const std::string& service_path,
177 scoped_ptr<base::DictionaryValue> set_properties,
178 NetworkConfigurationObserver::Source source,
179 const base::Closure& callback);
180 void SetPropertiesErrorCallback(
181 const std::string& service_path,
182 const network_handler::ErrorCallback& error_callback,
183 const std::string& dbus_error_name,
184 const std::string& dbus_error_message);
186 // Invoke |callback| and inform NetworkStateHandler to request an update
187 // for the service after clearing properties.
188 void ClearPropertiesSuccessCallback(
189 const std::string& service_path,
190 const std::vector<std::string>& names,
191 const base::Closure& callback,
192 const base::ListValue& result);
193 void ClearPropertiesErrorCallback(
194 const std::string& service_path,
195 const network_handler::ErrorCallback& error_callback,
196 const std::string& dbus_error_name,
197 const std::string& dbus_error_message);
199 // Signals the device handler to request an IP config refresh.
200 void RequestRefreshIPConfigs(const std::string& service_path);
202 // Unowned associated Network*Handlers (global or test instance).
203 NetworkStateHandler* network_state_handler_;
204 NetworkDeviceHandler* network_device_handler_;
206 // Map of in-progress deleter instances. Owned by this class.
207 std::map<std::string, ProfileEntryDeleter*> profile_entry_deleters_;
209 base::ObserverList<NetworkConfigurationObserver> observers_;
211 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationHandler);
214 } // namespace chromeos
216 #endif // CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_