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 14 matching lines...) Expand all Loading... |
41 static const char kErrorNotFound[]; | 42 static const char kErrorNotFound[]; |
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 | 51 |
51 // Sets the global instance. Must be called before any calls to Get(). | 52 ~NetworkConnectionHandler(); |
52 static void Initialize(); | |
53 | |
54 // Destroys the global instance. | |
55 static void Shutdown(); | |
56 | |
57 // Gets the global instance. Initialize() must be called first. | |
58 static NetworkConnectionHandler* Get(); | |
59 | 53 |
60 // ConnectToNetwork() will start an asynchronous connection attempt. | 54 // ConnectToNetwork() will start an asynchronous connection attempt. |
61 // On success, |success_callback| will be called. | 55 // On success, |success_callback| will be called. |
62 // On failure, |error_callback| will be called with |error_name| one of: | 56 // On failure, |error_callback| will be called with |error_name| one of: |
63 // kErrorNotFound if no network matching |service_path| is found | 57 // kErrorNotFound if no network matching |service_path| is found |
64 // (hidden networks must be configured before connecting). | 58 // (hidden networks must be configured before connecting). |
65 // kErrorConnected if already connected to the network. | 59 // kErrorConnected if already connected to the network. |
66 // kErrorConnecting if already connecting to the network. | 60 // kErrorConnecting if already connecting to the network. |
67 // kErrorCertificateRequired if the network requires a cert and none exists. | 61 // kErrorCertificateRequired if the network requires a cert and none exists. |
68 // kErrorPassphraseRequired if passphrase only is required. | 62 // kErrorPassphraseRequired if passphrase only is required. |
69 // kErrorConfigurationRequired if additional configuration is required. | 63 // kErrorConfigurationRequired if additional configuration is required. |
70 // kErrorShillError if a DBus or Shill error occurred. | 64 // kErrorShillError if a DBus or Shill error occurred. |
71 // |error_message| will contain an additional error string for debugging. | 65 // |error_message| will contain an additional error string for debugging. |
72 void ConnectToNetwork(const std::string& service_path, | 66 void ConnectToNetwork(const std::string& service_path, |
73 const base::Closure& success_callback, | 67 const base::Closure& success_callback, |
74 const network_handler::ErrorCallback& error_callback); | 68 const network_handler::ErrorCallback& error_callback); |
75 | 69 |
76 // DisconnectToNetwork() will send a Disconnect request to Shill. | 70 // DisconnectToNetwork() will send a Disconnect request to Shill. |
77 // On success, |success_callback| will be called. | 71 // On success, |success_callback| will be called. |
78 // On failure, |error_callback| will be called with |error_name| one of: | 72 // On failure, |error_callback| will be called with |error_name| one of: |
79 // kErrorNotFound if no network matching |service_path| is found. | 73 // kErrorNotFound if no network matching |service_path| is found. |
80 // kErrorNotConnected if not connected to the network. | 74 // kErrorNotConnected if not connected to the network. |
81 // kErrorShillError if a DBus or Shill error occurred. | 75 // kErrorShillError if a DBus or Shill error occurred. |
82 // |error_message| will contain and additional error string for debugging. | 76 // |error_message| will contain and additional error string for debugging. |
83 void DisconnectNetwork(const std::string& service_path, | 77 void DisconnectNetwork(const std::string& service_path, |
84 const base::Closure& success_callback, | 78 const base::Closure& success_callback, |
85 const network_handler::ErrorCallback& error_callback); | 79 const network_handler::ErrorCallback& error_callback); |
86 | 80 |
87 private: | 81 private: |
| 82 friend class NetworkHandler; |
| 83 friend class NetworkConnectionHandlerTest; |
88 NetworkConnectionHandler(); | 84 NetworkConnectionHandler(); |
89 ~NetworkConnectionHandler(); | 85 |
| 86 void Init(NetworkStateHandler* network_state_handler, |
| 87 NetworkConfigurationHandler* network_configuration_handler); |
90 | 88 |
91 // Calls Shill.Manager.Connect asynchronously. | 89 // Calls Shill.Manager.Connect asynchronously. |
92 void CallShillConnect( | 90 void CallShillConnect( |
93 const std::string& service_path, | 91 const std::string& service_path, |
94 const base::Closure& success_callback, | 92 const base::Closure& success_callback, |
95 const network_handler::ErrorCallback& error_callback); | 93 const network_handler::ErrorCallback& error_callback); |
96 | 94 |
97 // Calls Shill.Manager.Disconnect asynchronously. | 95 // Calls Shill.Manager.Disconnect asynchronously. |
98 void CallShillDisconnect( | 96 void CallShillDisconnect( |
99 const std::string& service_path, | 97 const std::string& service_path, |
(...skipping 22 matching lines...) Expand all Loading... |
122 scoped_ptr<base::DictionaryValue> error_data); | 120 scoped_ptr<base::DictionaryValue> error_data); |
123 | 121 |
124 // Handle success or failure from Shill.Service.Connect. | 122 // Handle success or failure from Shill.Service.Connect. |
125 void HandleShillSuccess(const std::string& service_path, | 123 void HandleShillSuccess(const std::string& service_path, |
126 const base::Closure& success_callback); | 124 const base::Closure& success_callback); |
127 void HandleShillFailure(const std::string& service_path, | 125 void HandleShillFailure(const std::string& service_path, |
128 const network_handler::ErrorCallback& error_callback, | 126 const network_handler::ErrorCallback& error_callback, |
129 const std::string& error_name, | 127 const std::string& error_name, |
130 const std::string& error_message); | 128 const std::string& error_message); |
131 | 129 |
| 130 // Local references to the associated handler instances. |
| 131 NetworkStateHandler* network_state_handler_; |
| 132 NetworkProfileHandler* network_profile_handler_; |
| 133 NetworkConfigurationHandler* network_configuration_handler_; |
| 134 |
132 // Set of pending connect requests, used to prevent repeat attempts while | 135 // Set of pending connect requests, used to prevent repeat attempts while |
133 // waiting for Shill. | 136 // waiting for Shill. |
134 std::set<std::string> pending_requests_; | 137 std::set<std::string> pending_requests_; |
135 | 138 |
136 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandler); | 139 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandler); |
137 }; | 140 }; |
138 | 141 |
139 } // namespace chromeos | 142 } // namespace chromeos |
140 | 143 |
141 #endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ | 144 #endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |
OLD | NEW |