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_
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"
23 class DictionaryValue
;
33 // The NetworkConfigurationHandler class is used to create and configure
34 // networks in ChromeOS. It mostly calls through to the Shill service API, and
35 // most calls are asynchronous for that reason. No calls will block on DBus
38 // This is owned and it's lifetime managed by the Chrome startup code. It's
39 // basically a singleton, but with explicit lifetime management.
41 // For accessing lists of remembered networks, and other state information, see
42 // the class NetworkStateHandler.
44 // Note on callbacks: Because all the functions here are meant to be
45 // asynchronous, they all take a |callback| of some type, and an
46 // |error_callback|. When the operation succeeds, |callback| will be called, and
47 // when it doesn't, |error_callback| will be called with information about the
48 // error, including a symbolic name for the error and often some error message
49 // that is suitable for logging. None of the error message text is meant for
52 class CHROMEOS_EXPORT NetworkConfigurationHandler
53 : public base::SupportsWeakPtr
<NetworkConfigurationHandler
> {
55 ~NetworkConfigurationHandler();
57 // Gets the properties of the network with id |service_path|. See note on
58 // |callback| and |error_callback|, in class description above.
60 const std::string
& service_path
,
61 const network_handler::DictionaryResultCallback
& callback
,
62 const network_handler::ErrorCallback
& error_callback
) const;
64 // Sets the properties of the network with id |service_path|. This means the
65 // given properties will be merged with the existing settings, and it won't
66 // clear any existing properties. See note on |callback| and |error_callback|,
67 // in class description above.
69 const std::string
& service_path
,
70 const base::DictionaryValue
& properties
,
71 const base::Closure
& callback
,
72 const network_handler::ErrorCallback
& error_callback
);
74 // Removes the properties with the given property paths. If any of them are
75 // unable to be cleared, the |error_callback| will only be run once with
76 // accumulated information about all of the errors as a list attached to the
77 // "errors" key of the error data, and the |callback| will not be run, even
78 // though some of the properties may have been cleared. If there are no
79 // errors, |callback| will be run.
80 void ClearProperties(const std::string
& service_path
,
81 const std::vector
<std::string
>& property_paths
,
82 const base::Closure
& callback
,
83 const network_handler::ErrorCallback
& error_callback
);
85 // Creates a network with the given |properties| in the specified Shill
86 // profile, and returns the new service_path to |callback| if successful.
87 // kProfileProperty must be set in |properties|. See note on |callback| and
88 // |error_callback|, in the class description above. This may also be used to
89 // update an existing matching configuration, see Shill documentation for
90 // Manager.ConfigureServiceForProfile.
91 void CreateConfiguration(
92 const base::DictionaryValue
& properties
,
93 const network_handler::StringResultCallback
& callback
,
94 const network_handler::ErrorCallback
& error_callback
);
96 // Removes the network |service_path| from any profiles that include it.
97 // See note on |callback| and |error_callback| in class description above.
98 void RemoveConfiguration(
99 const std::string
& service_path
,
100 const base::Closure
& callback
,
101 const network_handler::ErrorCallback
& error_callback
);
103 // Changes the profile for the network |service_path| to |profile_path|.
104 // See note on |callback| and |error_callback| in class description above.
105 void SetNetworkProfile(const std::string
& service_path
,
106 const std::string
& profile_path
,
107 const base::Closure
& callback
,
108 const network_handler::ErrorCallback
& error_callback
);
110 // Construct and initialize an instance for testing.
111 static NetworkConfigurationHandler
* InitializeForTest(
112 NetworkStateHandler
* network_state_handler
);
115 friend class ClientCertResolverTest
;
116 friend class NetworkHandler
;
117 friend class NetworkConfigurationHandlerTest
;
118 friend class NetworkConfigurationHandlerStubTest
;
119 class ProfileEntryDeleter
;
121 NetworkConfigurationHandler();
122 void Init(NetworkStateHandler
* network_state_handler
);
124 void RunCreateNetworkCallback(
125 const network_handler::StringResultCallback
& callback
,
126 const dbus::ObjectPath
& service_path
);
128 // Called from ProfileEntryDeleter instances when they complete causing
129 // this class to delete the instance.
130 void ProfileEntryDeleterCompleted(const std::string
& service_path
);
131 bool PendingProfileEntryDeleterForTest(const std::string
& service_path
) {
132 return profile_entry_deleters_
.count(service_path
);
135 // Invoke the callback and inform NetworkStateHandler to request an update
136 // for the service after setting properties.
137 void SetPropertiesSuccessCallback(const std::string
& service_path
,
138 const base::Closure
& callback
);
139 void SetPropertiesErrorCallback(
140 const std::string
& service_path
,
141 const network_handler::ErrorCallback
& error_callback
,
142 const std::string
& dbus_error_name
,
143 const std::string
& dbus_error_message
);
145 // Invoke the callback and inform NetworkStateHandler to request an update
146 // for the service after clearing properties.
147 void ClearPropertiesSuccessCallback(
148 const std::string
& service_path
,
149 const std::vector
<std::string
>& names
,
150 const base::Closure
& callback
,
151 const network_handler::ErrorCallback
& error_callback
,
152 const base::ListValue
& result
);
153 void ClearPropertiesErrorCallback(
154 const std::string
& service_path
,
155 const network_handler::ErrorCallback
& error_callback
,
156 const std::string
& dbus_error_name
,
157 const std::string
& dbus_error_message
);
159 // Unowned associated NetworkStateHandler* (global or test instance).
160 NetworkStateHandler
* network_state_handler_
;
162 // Map of in-progress deleter instances. Owned by this class.
163 std::map
<std::string
, ProfileEntryDeleter
*> profile_entry_deleters_
;
165 DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationHandler
);
168 } // namespace chromeos
170 #endif // CHROMEOS_NETWORK_NETWORK_CONFIGURATION_HANDLER_H_