Index: chromeos/network/network_connection_handler.h |
diff --git a/chromeos/network/network_connection_handler.h b/chromeos/network/network_connection_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..794905af8b3925eb25a2addd2011ca865efb3092 |
--- /dev/null |
+++ b/chromeos/network/network_connection_handler.h |
@@ -0,0 +1,140 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |
+#define CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |
+ |
+#include <set> |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/values.h" |
+#include "chromeos/chromeos_export.h" |
+#include "chromeos/dbus/dbus_method_call_status.h" |
+#include "chromeos/network/network_handler_callbacks.h" |
+ |
+namespace chromeos { |
+ |
+class NetworkState; |
+ |
+// The NetworkConnectionHandler class is used to manage network connection |
+// requests. This is the only class that should make Shill Connect calls. |
+// It handles the following steps: |
+// 1. Determine whether or not sufficient information (e.g. passphrase) is |
+// known to be available to connect to the network. |
+// 2. Request additional information (e.g. user data which contains certificate |
+// information) and determine whether sufficient information is available. |
+// 3. Send the connect request. |
+// 4. Invoke the appropriate callback (always) on success or failure. |
+// |
+// NetworkConnectionHandler depends on NetworkStateHandler for immediately |
+// available State information, and NetworkConfigurationHandler for any |
+// configuration calls. |
+ |
+class CHROMEOS_EXPORT NetworkConnectionHandler |
+ : public base::SupportsWeakPtr<NetworkConnectionHandler> { |
+ public: |
+ // Sets the global instance. Must be called before any calls to Get(). |
+ static void Initialize(); |
+ |
+ // Destroys the global instance. |
+ static void Shutdown(); |
+ |
+ // Gets the global instance. Initialize() must be called first. |
+ static NetworkConnectionHandler* Get(); |
+ |
+ // ConnectToNetwork() will start an asynchronous connection attempt. |
+ // On success, |success_callback| will be called. |
+ // On failure, |error_callback| will be called with |error_name| one of: |
+ // kNetworkNotFound if no network matching |service_path| is found |
+ // (hidden networks must be configured before connecting). |
+ // kConnected if already connected to the network. |
+ // kConnecting if already connecting to the network. |
+ // kCertificateRequired if the network requires a cert and none exists. |
+ // kPassphraseRequired if passphrase only is required. |
+ // kConfigurationRequired if additional configuration is required. |
+ // kShillError if a DBus or Shill error occurred. |
+ // |error_message| will contain an additional error string for debugging. |
+ void ConnectToNetwork(const std::string& service_path, |
+ const base::Closure& success_callback, |
+ const network_handler::ErrorCallback& error_callback); |
+ |
+ // DisconnectToNetwork() will send a Disconnect request to Shill. |
+ // On success, |success_callback| will be called. |
+ // On failure, |error_callback| will be called with |error_name| one of: |
+ // kNetworkNotFound if no network matching |service_path| is found. |
+ // kNotConnected if not connected to the network. |
+ // kShillError if a DBus or Shill error occurred. |
+ // |error_message| will contain and additional error string for debugging. |
+ void DisconnectNetwork(const std::string& service_path, |
+ const base::Closure& success_callback, |
+ const network_handler::ErrorCallback& error_callback); |
+ |
+ // Constants for |error_name| from |error_callback| for Connect/Disconnect. |
+ static const char kNetworkNotFound[]; |
gauravsh
2013/05/08 19:22:04
as per style, static const members should be decla
stevenjb
2013/05/09 00:13:00
Done.
|
+ static const char kConnected[]; |
+ static const char kConnecting[]; |
gauravsh
2013/05/08 19:22:04
Renaming these constants as kConnectedError, kConn
stevenjb
2013/05/09 00:13:00
Done.
|
+ static const char kNotConnected[]; |
+ static const char kPassphraseRequired[]; |
+ static const char kActivationRequired[]; |
+ static const char kCertificateRequired[]; |
+ static const char kConfigurationRequired[]; |
+ static const char kShillError[]; |
+ |
+ private: |
+ NetworkConnectionHandler(); |
+ ~NetworkConnectionHandler(); |
+ |
+ // Calls Shill.Manager.Connect asynchronously. |
+ void CallShillConnect( |
+ const std::string& service_path, |
+ const base::Closure& success_callback, |
+ const network_handler::ErrorCallback& error_callback); |
+ |
+ // Calls Shill.Manager.Disconnect asynchronously. |
+ void CallShillDisconnect( |
+ const std::string& service_path, |
+ const base::Closure& success_callback, |
+ const network_handler::ErrorCallback& error_callback); |
+ |
+ // Callback to Shill.Service.GetProperties. Parses properties to determine |
+ // whether to invoke |error_callback|, or attemt a connection. |
gauravsh
2013/05/08 19:22:04
attempt
This also needs a more detailed comment s
stevenjb
2013/05/09 00:13:00
Renamed, improved comment.
|
+ void GetPropertiesCallback( |
+ const base::Closure& success_callback, |
+ const network_handler::ErrorCallback& error_callback, |
+ const std::string& service_path, |
+ const base::DictionaryValue& properties); |
+ |
+ // Sets the property for the service with an empty callback (logs errors). |
+ void SetServiceProperty(const std::string& service_path, |
+ const std::string& property, |
+ const std::string& value) const; |
+ |
+ // Handle failure from ConfigurationHandler calls. |
+ void HandleConfigurationFailure( |
+ const std::string& service_path, |
+ const network_handler::ErrorCallback& error_callback, |
+ const std::string& error_name, |
+ scoped_ptr<base::DictionaryValue> error_data); |
+ |
+ // Handle success or failure from Shill.Service.Connect. |
+ void HandleShillSuccess(const std::string& service_path, |
+ const base::Closure& success_callback); |
+ void HandleShillFailure(const std::string& service_path, |
+ const network_handler::ErrorCallback& error_callback, |
+ const std::string& error_name, |
+ const std::string& error_message); |
+ |
+ // Set of pending connect requests, used to prevent repeat attempts while |
+ // waiting for Shill. |
+ std::set<std::string> pending_requests_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandler); |
+}; |
+ |
+} // namespace chromeos |
+ |
+#endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |