OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |
6 #define CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ | 6 #define CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chromeos/chromeos_export.h" | 15 #include "chromeos/chromeos_export.h" |
16 #include "chromeos/dbus/dbus_method_call_status.h" | 16 #include "chromeos/dbus/dbus_method_call_status.h" |
| 17 #include "chromeos/network/network_handler.h" |
17 #include "chromeos/network/network_handler_callbacks.h" | 18 #include "chromeos/network/network_handler_callbacks.h" |
18 | 19 |
19 namespace chromeos { | 20 namespace chromeos { |
20 | 21 |
21 class NetworkState; | 22 class NetworkState; |
22 | 23 |
23 // The NetworkConnectionHandler class is used to manage network connection | 24 // The NetworkConnectionHandler class is used to manage network connection |
24 // requests. This is the only class that should make Shill Connect calls. | 25 // requests. This is the only class that should make Shill Connect calls. |
25 // It handles the following steps: | 26 // It handles the following steps: |
26 // 1. Determine whether or not sufficient information (e.g. passphrase) is | 27 // 1. Determine whether or not sufficient information (e.g. passphrase) is |
(...skipping 15 matching lines...) Expand all Loading... |
42 static const char kErrorConnected[]; | 43 static const char kErrorConnected[]; |
43 static const char kErrorConnecting[]; | 44 static const char kErrorConnecting[]; |
44 static const char kErrorNotConnected[]; | 45 static const char kErrorNotConnected[]; |
45 static const char kErrorPassphraseRequired[]; | 46 static const char kErrorPassphraseRequired[]; |
46 static const char kErrorActivationRequired[]; | 47 static const char kErrorActivationRequired[]; |
47 static const char kErrorCertificateRequired[]; | 48 static const char kErrorCertificateRequired[]; |
48 static const char kErrorConfigurationRequired[]; | 49 static const char kErrorConfigurationRequired[]; |
49 static const char kErrorShillError[]; | 50 static const char kErrorShillError[]; |
50 static const char kErrorPreviousConnectFailed[]; | 51 static const char kErrorPreviousConnectFailed[]; |
51 | 52 |
52 // Sets the global instance. Must be called before any calls to Get(). | 53 ~NetworkConnectionHandler(); |
53 static void Initialize(); | |
54 | |
55 // Destroys the global instance. | |
56 static void Shutdown(); | |
57 | |
58 // Gets the global instance. Initialize() must be called first. | |
59 static NetworkConnectionHandler* Get(); | |
60 | 54 |
61 // ConnectToNetwork() will start an asynchronous connection attempt. | 55 // ConnectToNetwork() will start an asynchronous connection attempt. |
62 // On success, |success_callback| will be called. | 56 // On success, |success_callback| will be called. |
63 // On failure, |error_callback| will be called with |error_name| one of: | 57 // On failure, |error_callback| will be called with |error_name| one of: |
64 // kErrorNotFound if no network matching |service_path| is found | 58 // kErrorNotFound if no network matching |service_path| is found |
65 // (hidden networks must be configured before connecting). | 59 // (hidden networks must be configured before connecting). |
66 // kErrorConnected if already connected to the network. | 60 // kErrorConnected if already connected to the network. |
67 // kErrorConnecting if already connecting to the network. | 61 // kErrorConnecting if already connecting to the network. |
68 // kErrorCertificateRequired if the network requires a cert and none exists. | 62 // kErrorCertificateRequired if the network requires a cert and none exists. |
69 // kErrorPassphraseRequired if passphrase only is required. | 63 // kErrorPassphraseRequired if passphrase only is required. |
(...skipping 12 matching lines...) Expand all Loading... |
82 // On failure, |error_callback| will be called with |error_name| one of: | 76 // On failure, |error_callback| will be called with |error_name| one of: |
83 // kErrorNotFound if no network matching |service_path| is found. | 77 // kErrorNotFound if no network matching |service_path| is found. |
84 // kErrorNotConnected if not connected to the network. | 78 // kErrorNotConnected if not connected to the network. |
85 // kErrorShillError if a DBus or Shill error occurred. | 79 // kErrorShillError if a DBus or Shill error occurred. |
86 // |error_message| will contain and additional error string for debugging. | 80 // |error_message| will contain and additional error string for debugging. |
87 void DisconnectNetwork(const std::string& service_path, | 81 void DisconnectNetwork(const std::string& service_path, |
88 const base::Closure& success_callback, | 82 const base::Closure& success_callback, |
89 const network_handler::ErrorCallback& error_callback); | 83 const network_handler::ErrorCallback& error_callback); |
90 | 84 |
91 private: | 85 private: |
| 86 friend class NetworkHandler; |
| 87 friend class NetworkConnectionHandlerTest; |
92 NetworkConnectionHandler(); | 88 NetworkConnectionHandler(); |
93 ~NetworkConnectionHandler(); | 89 |
| 90 void Init(NetworkStateHandler* network_state_handler, |
| 91 NetworkConfigurationHandler* network_configuration_handler); |
94 | 92 |
95 // Calls Shill.Manager.Connect asynchronously. | 93 // Calls Shill.Manager.Connect asynchronously. |
96 void CallShillConnect( | 94 void CallShillConnect( |
97 const std::string& service_path, | 95 const std::string& service_path, |
98 const base::Closure& success_callback, | 96 const base::Closure& success_callback, |
99 const network_handler::ErrorCallback& error_callback); | 97 const network_handler::ErrorCallback& error_callback); |
100 | 98 |
101 // Calls Shill.Manager.Disconnect asynchronously. | 99 // Calls Shill.Manager.Disconnect asynchronously. |
102 void CallShillDisconnect( | 100 void CallShillDisconnect( |
103 const std::string& service_path, | 101 const std::string& service_path, |
(...skipping 22 matching lines...) Expand all Loading... |
126 scoped_ptr<base::DictionaryValue> error_data); | 124 scoped_ptr<base::DictionaryValue> error_data); |
127 | 125 |
128 // Handle success or failure from Shill.Service.Connect. | 126 // Handle success or failure from Shill.Service.Connect. |
129 void HandleShillSuccess(const std::string& service_path, | 127 void HandleShillSuccess(const std::string& service_path, |
130 const base::Closure& success_callback); | 128 const base::Closure& success_callback); |
131 void HandleShillFailure(const std::string& service_path, | 129 void HandleShillFailure(const std::string& service_path, |
132 const network_handler::ErrorCallback& error_callback, | 130 const network_handler::ErrorCallback& error_callback, |
133 const std::string& error_name, | 131 const std::string& error_name, |
134 const std::string& error_message); | 132 const std::string& error_message); |
135 | 133 |
| 134 // Local references to the associated handler instances. |
| 135 NetworkStateHandler* network_state_handler_; |
| 136 NetworkProfileHandler* network_profile_handler_; |
| 137 NetworkConfigurationHandler* network_configuration_handler_; |
| 138 |
136 // Set of pending connect requests, used to prevent repeat attempts while | 139 // Set of pending connect requests, used to prevent repeat attempts while |
137 // waiting for Shill. | 140 // waiting for Shill. |
138 std::set<std::string> pending_requests_; | 141 std::set<std::string> pending_requests_; |
139 | 142 |
140 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandler); | 143 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandler); |
141 }; | 144 }; |
142 | 145 |
143 } // namespace chromeos | 146 } // namespace chromeos |
144 | 147 |
145 #endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ | 148 #endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |
OLD | NEW |