Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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_CONNECTION_HANDLER_H_ | |
| 6 #define CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/callback.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/values.h" | |
| 15 #include "chromeos/chromeos_export.h" | |
| 16 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 17 #include "chromeos/network/network_handler_callbacks.h" | |
| 18 | |
| 19 namespace chromeos { | |
| 20 | |
| 21 class NetworkState; | |
| 22 | |
| 23 // The NetworkConnectionHandler class is used to connect to networks. It | |
|
pneubeck (no reviews)
2013/05/07 08:46:39
The main responsibility (not contradicting to the
stevenjb
2013/05/08 01:57:22
This is also the only class that should make Conne
| |
| 24 // handles the following steps: | |
| 25 // 1. Determine whether or not sufficient information (e.g. passphrase) is | |
| 26 // known to be available to connect to the network. | |
| 27 // 2. Request additional information (e.g. user data which contains certificate | |
|
pneubeck (no reviews)
2013/05/07 08:46:39
I'm not happy about that checking of sufficient in
stevenjb
2013/05/08 01:57:22
I agree with centralizing any shared logic, howeve
pneubeck (no reviews)
2013/05/08 08:07:46
sg
| |
| 28 // information) and determine whether sufficient information is available. | |
| 29 // 3. Set certificate and related properties to allow a successful connection | |
|
pneubeck (no reviews)
2013/05/07 08:46:39
See my later comments: CertificateLoader/Handler i
stevenjb
2013/05/08 01:57:22
I have thought about this and related comments, an
| |
| 30 // (if necessary). | |
| 31 // 4. Send the connect request. | |
| 32 // 5. Call back (always) on success or failure. | |
| 33 // | |
| 34 // NetworkConnectionHandler depends on NetworkStateHandler for immediately | |
| 35 // available State information, and NetworkConfigurationHandler for any | |
| 36 // configuration calls. | |
| 37 | |
| 38 class CHROMEOS_EXPORT NetworkConnectionHandler | |
| 39 : public base::SupportsWeakPtr<NetworkConnectionHandler> { | |
| 40 public: | |
| 41 // Sets the global instance. Must be called before any calls to Get(). | |
| 42 static void Initialize(); | |
| 43 | |
| 44 // Destroys the global instance. | |
| 45 static void Shutdown(); | |
| 46 | |
| 47 // Gets the global instance. Initialize() must be called first. | |
| 48 static NetworkConnectionHandler* Get(); | |
| 49 | |
| 50 // ConnectToNetwork() will start an asynchronous connection attempt. | |
| 51 // On success, |success_callback| will be called. | |
| 52 // On failure, |error_callback| will be called with |error_name| one of: | |
| 53 // kNetworkNotFound if no network matching |service_path| is found | |
| 54 // (hidden networks must be configured before connecting). | |
| 55 // kConnected if already connected to the network. | |
| 56 // kConnecting if already connecting to the network. | |
| 57 // kCertificateRequired if the network requires a cert and none exists. | |
| 58 // kPassphraseRequired if passphrase only is required. | |
| 59 // kConfigurationRequired if additional configuration is required. | |
| 60 // kShillError if a DBus or Shill error occurred. | |
| 61 // |error_message| will contain and additional error string for debugging. | |
|
pneubeck (no reviews)
2013/05/07 08:46:39
and -> an
stevenjb
2013/05/08 01:57:22
Done.
| |
| 62 void ConnectToNetwork(const std::string& service_path, | |
| 63 const base::Closure& success_callback, | |
| 64 const network_handler::ErrorCallback& error_callback); | |
| 65 | |
| 66 // DisconnectToNetwork() will send a Disconnect request to Shill. | |
| 67 // On success, |success_callback| will be called. | |
| 68 // On failure, |error_callback| will be called with |error_name| one of: | |
| 69 // kNetworkNotFound if no network matching |service_path| is found. | |
| 70 // kNotConnected if not connected to the network. | |
| 71 // kShillError if a DBus or Shill error occurred. | |
| 72 // |error_message| will contain and additional error string for debugging. | |
| 73 void DisconnectNetwork(const std::string& service_path, | |
| 74 const base::Closure& success_callback, | |
| 75 const network_handler::ErrorCallback& error_callback); | |
| 76 | |
| 77 // Constants for |error_name| from |error_callback| for Connect/Disconnect. | |
| 78 static const char kNetworkNotFound[]; | |
| 79 static const char kConnected[]; | |
| 80 static const char kConnecting[]; | |
| 81 static const char kNotConnected[]; | |
| 82 static const char kPassphraseRequired[]; | |
| 83 static const char kActivationRequired[]; | |
| 84 static const char kCertificateRequired[]; | |
| 85 static const char kConfigurationRequired[]; | |
| 86 static const char kShillError[]; | |
| 87 | |
| 88 private: | |
|
pneubeck (no reviews)
2013/05/07 08:46:39
there are several functions that could be .cc-loca
pneubeck (no reviews)
2013/05/08 08:07:46
Done.
| |
| 89 NetworkConnectionHandler(); | |
| 90 ~NetworkConnectionHandler(); | |
| 91 | |
| 92 // Calls Shill.Manager.Connect asynchronously. | |
| 93 void CallShillConnect( | |
| 94 const std::string& service_path, | |
| 95 const base::Closure& success_callback, | |
| 96 const network_handler::ErrorCallback& error_callback); | |
| 97 | |
| 98 // Calls Shill.Manager.Disconnect asynchronously. | |
| 99 void CallShillDisconnect( | |
| 100 const std::string& service_path, | |
| 101 const base::Closure& success_callback, | |
| 102 const network_handler::ErrorCallback& error_callback); | |
| 103 | |
| 104 // Invokes |callback| with |error_name| for 'result'. | |
|
pneubeck (no reviews)
2013/05/07 08:46:39
'result' ?
stevenjb
2013/05/08 01:57:22
Done.
| |
| 105 void InvokeErrorCallback(const std::string& service_path, | |
| 106 const network_handler::ErrorCallback& error_callback, | |
| 107 const std::string& error_name); | |
| 108 | |
| 109 // Returns true if we need to request properties for |network| to determine | |
| 110 // whether or not we can connect to it. | |
| 111 bool NetworkMayNeedCredentials(const NetworkState* network) const; | |
| 112 | |
| 113 // Returns true if |network| is cellular and not activated or out of credits. | |
| 114 bool NetworkRequiresActivation(const NetworkState* network) const; | |
| 115 | |
| 116 // Callback to Shill.Service.GetProperties. Parses properties to determine | |
| 117 // whether to invoke |error_callback|, or attemt a connection. | |
| 118 void GetPropertiesCallback( | |
| 119 const base::Closure& success_callback, | |
| 120 const network_handler::ErrorCallback& error_callback, | |
| 121 const std::string& service_path, | |
| 122 const base::DictionaryValue& properties); | |
| 123 | |
| 124 // Sets the property for the service with an empty callback (logs errors). | |
| 125 void SetServiceProperty(const std::string& service_path, | |
| 126 const std::string& property, | |
| 127 const std::string& value) const; | |
| 128 | |
| 129 // Handle failure from ConfigurationHandler calls. | |
| 130 void HandleConfigurationFailure( | |
| 131 const std::string& service_path, | |
| 132 const network_handler::ErrorCallback& error_callback, | |
| 133 const std::string& error_name, | |
| 134 scoped_ptr<base::DictionaryValue> error_data); | |
| 135 | |
| 136 // Handle success or failure from Shill.Service.Connect. | |
| 137 void HandleShillSuccess(const std::string& service_path, | |
| 138 const base::Closure& success_callback); | |
| 139 void HandleShillFailure(const std::string& service_path, | |
| 140 const network_handler::ErrorCallback& error_callback, | |
| 141 const std::string& error_name, | |
| 142 const std::string& error_message); | |
| 143 | |
| 144 // Set of pending connect requests, used to prevent repeat attempts while | |
| 145 // waiting for Shill. | |
| 146 std::set<std::string> pending_requests_; | |
| 147 | |
| 148 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandler); | |
| 149 }; | |
| 150 | |
| 151 } // namespace chromeos | |
| 152 | |
| 153 #endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ | |
| OLD | NEW |