Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: chromeos/network/network_connection_handler.cc

Issue 14729017: Add NetworkHandler to own network handlers in src/chromeos/network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Add NetworkConnectionHandler to NetworkHandler Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "chromeos/network/network_connection_handler.h" 5 #include "chromeos/network/network_connection_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "chromeos/dbus/dbus_thread_manager.h" 9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/shill_manager_client.h" 10 #include "chromeos/dbus/shill_manager_client.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 scoped_refptr<net::X509Certificate> matching_cert = 100 scoped_refptr<net::X509Certificate> matching_cert =
101 certificate_pattern::GetCertificateMatch( 101 certificate_pattern::GetCertificateMatch(
102 ui_data->certificate_pattern()); 102 ui_data->certificate_pattern());
103 if (!matching_cert.get()) 103 if (!matching_cert.get())
104 return false; 104 return false;
105 return true; 105 return true;
106 } 106 }
107 107
108 } // namespace 108 } // namespace
109 109
110 static NetworkConnectionHandler* g_connection_handler_instance = NULL;
111
112 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; 110 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found";
113 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; 111 const char NetworkConnectionHandler::kErrorConnected[] = "connected";
114 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; 112 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting";
115 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; 113 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected";
116 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = 114 const char NetworkConnectionHandler::kErrorPassphraseRequired[] =
117 "passphrase-required"; 115 "passphrase-required";
118 const char NetworkConnectionHandler::kErrorActivationRequired[] = 116 const char NetworkConnectionHandler::kErrorActivationRequired[] =
119 "activation-required"; 117 "activation-required";
120 const char NetworkConnectionHandler::kErrorCertificateRequired[] = 118 const char NetworkConnectionHandler::kErrorCertificateRequired[] =
121 "certificate-required"; 119 "certificate-required";
122 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = 120 const char NetworkConnectionHandler::kErrorConfigurationRequired[] =
123 "configuration-required"; 121 "configuration-required";
124 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; 122 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error";
125 123
126 // static 124 NetworkConnectionHandler::NetworkConnectionHandler()
127 void NetworkConnectionHandler::Initialize() { 125 : network_state_handler_(NULL),
128 CHECK(!g_connection_handler_instance); 126 network_configuration_handler_(NULL) {
129 g_connection_handler_instance = new NetworkConnectionHandler;
130 }
131
132 // static
133 void NetworkConnectionHandler::Shutdown() {
134 CHECK(g_connection_handler_instance);
135 delete g_connection_handler_instance;
136 g_connection_handler_instance = NULL;
137 }
138
139 // static
140 NetworkConnectionHandler* NetworkConnectionHandler::Get() {
141 CHECK(g_connection_handler_instance)
142 << "NetworkConnectionHandler::Get() called before Initialize()";
143 return g_connection_handler_instance;
144 }
145
146 NetworkConnectionHandler::NetworkConnectionHandler() {
147 } 127 }
148 128
149 NetworkConnectionHandler::~NetworkConnectionHandler() { 129 NetworkConnectionHandler::~NetworkConnectionHandler() {
150 } 130 }
151 131
132 void NetworkConnectionHandler::Init(
133 NetworkStateHandler* network_state_handler,
134 NetworkConfigurationHandler* network_configuration_handler) {
135 network_state_handler_ = network_state_handler;
136 network_configuration_handler_ = network_configuration_handler;
137 }
138
152 void NetworkConnectionHandler::ConnectToNetwork( 139 void NetworkConnectionHandler::ConnectToNetwork(
153 const std::string& service_path, 140 const std::string& service_path,
154 const base::Closure& success_callback, 141 const base::Closure& success_callback,
155 const network_handler::ErrorCallback& error_callback) { 142 const network_handler::ErrorCallback& error_callback) {
156 const NetworkState* network = 143 const NetworkState* network =
157 NetworkStateHandler::Get()->GetNetworkState(service_path); 144 network_state_handler_->GetNetworkState(service_path);
158 if (!network) { 145 if (!network) {
159 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); 146 InvokeErrorCallback(service_path, error_callback, kErrorNotFound);
160 return; 147 return;
161 } 148 }
162 if (network->IsConnectedState()) { 149 if (network->IsConnectedState()) {
163 InvokeErrorCallback(service_path, error_callback, kErrorConnected); 150 InvokeErrorCallback(service_path, error_callback, kErrorConnected);
164 return; 151 return;
165 } 152 }
166 if (network->IsConnectingState() || 153 if (network->IsConnectingState() ||
167 pending_requests_.find(service_path) != pending_requests_.end()) { 154 pending_requests_.find(service_path) != pending_requests_.end()) {
168 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); 155 InvokeErrorCallback(service_path, error_callback, kErrorConnecting);
169 return; 156 return;
170 } 157 }
171 if (network->passphrase_required()) { 158 if (network->passphrase_required()) {
172 InvokeErrorCallback(service_path, error_callback, kErrorPassphraseRequired); 159 InvokeErrorCallback(service_path, error_callback, kErrorPassphraseRequired);
173 return; 160 return;
174 } 161 }
175 if (NetworkRequiresActivation(network)) { 162 if (NetworkRequiresActivation(network)) {
176 InvokeErrorCallback(service_path, error_callback, kErrorActivationRequired); 163 InvokeErrorCallback(service_path, error_callback, kErrorActivationRequired);
177 return; 164 return;
178 } 165 }
179 166
180 // All synchronous checks passed, add |service_path| to connecting list. 167 // All synchronous checks passed, add |service_path| to connecting list.
181 pending_requests_.insert(service_path); 168 pending_requests_.insert(service_path);
182 169
183 if (!network->connectable() && NetworkMayNeedCredentials(network)) { 170 if (!network->connectable() && NetworkMayNeedCredentials(network)) {
184 // Request additional properties to check. 171 // Request additional properties to check.
185 NetworkConfigurationHandler::Get()->GetProperties( 172 network_configuration_handler_->GetProperties(
186 network->path(), 173 network->path(),
187 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, 174 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect,
188 AsWeakPtr(), success_callback, error_callback), 175 AsWeakPtr(), success_callback, error_callback),
189 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, 176 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure,
190 AsWeakPtr(), network->path(), error_callback)); 177 AsWeakPtr(), network->path(), error_callback));
191 return; 178 return;
192 } 179 }
193 // All checks passed, send connect request. 180 // All checks passed, send connect request.
194 CallShillConnect(service_path, success_callback, error_callback); 181 CallShillConnect(service_path, success_callback, error_callback);
195 } 182 }
196 183
197 void NetworkConnectionHandler::DisconnectNetwork( 184 void NetworkConnectionHandler::DisconnectNetwork(
198 const std::string& service_path, 185 const std::string& service_path,
199 const base::Closure& success_callback, 186 const base::Closure& success_callback,
200 const network_handler::ErrorCallback& error_callback) { 187 const network_handler::ErrorCallback& error_callback) {
201 const NetworkState* network = 188 const NetworkState* network =
202 NetworkStateHandler::Get()->GetNetworkState(service_path); 189 network_state_handler_->GetNetworkState(service_path);
203 if (!network) { 190 if (!network) {
204 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); 191 InvokeErrorCallback(service_path, error_callback, kErrorNotFound);
205 return; 192 return;
206 } 193 }
207 if (!network->IsConnectedState()) { 194 if (!network->IsConnectedState()) {
208 InvokeErrorCallback(service_path, error_callback, kErrorNotConnected); 195 InvokeErrorCallback(service_path, error_callback, kErrorNotConnected);
209 return; 196 return;
210 } 197 }
211 CallShillDisconnect(service_path, success_callback, error_callback); 198 CallShillDisconnect(service_path, success_callback, error_callback);
212 } 199 }
213 200
214 void NetworkConnectionHandler::CallShillConnect( 201 void NetworkConnectionHandler::CallShillConnect(
215 const std::string& service_path, 202 const std::string& service_path,
216 const base::Closure& success_callback, 203 const base::Closure& success_callback,
217 const network_handler::ErrorCallback& error_callback) { 204 const network_handler::ErrorCallback& error_callback) {
218 // TODO(stevenjb): Remove SetConnectingNetwork and use this class to maintain 205 // TODO(stevenjb): Remove SetConnectingNetwork and use this class to maintain
219 // the connecting network(s) once NetworkLibrary path is eliminated. 206 // the connecting network(s) once NetworkLibrary path is eliminated.
220 NetworkStateHandler::Get()->SetConnectingNetwork(service_path); 207 network_state_handler_->SetConnectingNetwork(service_path);
221 network_event_log::AddEntry(kLogModule, "Connect Request", service_path); 208 network_event_log::AddEntry(kLogModule, "Connect Request", service_path);
222 DBusThreadManager::Get()->GetShillServiceClient()->Connect( 209 DBusThreadManager::Get()->GetShillServiceClient()->Connect(
223 dbus::ObjectPath(service_path), 210 dbus::ObjectPath(service_path),
224 base::Bind(&NetworkConnectionHandler::HandleShillSuccess, 211 base::Bind(&NetworkConnectionHandler::HandleShillSuccess,
225 AsWeakPtr(), service_path, success_callback), 212 AsWeakPtr(), service_path, success_callback),
226 base::Bind(&NetworkConnectionHandler::HandleShillFailure, 213 base::Bind(&NetworkConnectionHandler::HandleShillFailure,
227 AsWeakPtr(), service_path, error_callback)); 214 AsWeakPtr(), service_path, error_callback));
228 } 215 }
229 216
230 void NetworkConnectionHandler::CallShillDisconnect( 217 void NetworkConnectionHandler::CallShillDisconnect(
231 const std::string& service_path, 218 const std::string& service_path,
232 const base::Closure& success_callback, 219 const base::Closure& success_callback,
233 const network_handler::ErrorCallback& error_callback) { 220 const network_handler::ErrorCallback& error_callback) {
234 network_event_log::AddEntry(kLogModule, "Disconnect Request", service_path); 221 network_event_log::AddEntry(kLogModule, "Disconnect Request", service_path);
235 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( 222 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect(
236 dbus::ObjectPath(service_path), 223 dbus::ObjectPath(service_path),
237 base::Bind(&NetworkConnectionHandler::HandleShillSuccess, 224 base::Bind(&NetworkConnectionHandler::HandleShillSuccess,
238 AsWeakPtr(), service_path, success_callback), 225 AsWeakPtr(), service_path, success_callback),
239 base::Bind(&NetworkConnectionHandler::HandleShillFailure, 226 base::Bind(&NetworkConnectionHandler::HandleShillFailure,
240 AsWeakPtr(), service_path, error_callback)); 227 AsWeakPtr(), service_path, error_callback));
241 } 228 }
242 229
243 void NetworkConnectionHandler::VerifyConfiguredAndConnect( 230 void NetworkConnectionHandler::VerifyConfiguredAndConnect(
244 const base::Closure& success_callback, 231 const base::Closure& success_callback,
245 const network_handler::ErrorCallback& error_callback, 232 const network_handler::ErrorCallback& error_callback,
246 const std::string& service_path, 233 const std::string& service_path,
247 const base::DictionaryValue& properties) { 234 const base::DictionaryValue& properties) {
248 const NetworkState* network = 235 const NetworkState* network =
249 NetworkStateHandler::Get()->GetNetworkState(service_path); 236 network_state_handler_->GetNetworkState(service_path);
250 if (!network) { 237 if (!network) {
251 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); 238 InvokeErrorCallback(service_path, error_callback, kErrorNotFound);
252 return; 239 return;
253 } 240 }
254 241
255 // VPN requires a host and username to be set. 242 // VPN requires a host and username to be set.
256 if (network->type() == flimflam::kTypeVPN && 243 if (network->type() == flimflam::kTypeVPN &&
257 !VPNIsConfigured(properties)) { 244 !VPNIsConfigured(properties)) {
258 InvokeErrorCallback(service_path, error_callback, 245 InvokeErrorCallback(service_path, error_callback,
259 kErrorConfigurationRequired); 246 kErrorConfigurationRequired);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 const network_handler::ErrorCallback& error_callback, 287 const network_handler::ErrorCallback& error_callback,
301 const std::string& error_name, 288 const std::string& error_name,
302 const std::string& error_message) { 289 const std::string& error_message) {
303 pending_requests_.erase(service_path); 290 pending_requests_.erase(service_path);
304 std::string error = "Connect Failure: " + error_name + ": " + error_message; 291 std::string error = "Connect Failure: " + error_name + ": " + error_message;
305 network_handler::ShillErrorCallbackFunction( 292 network_handler::ShillErrorCallbackFunction(
306 kLogModule, service_path, error_callback, error_name, error_message); 293 kLogModule, service_path, error_callback, error_name, error_message);
307 } 294 }
308 295
309 } // namespace chromeos 296 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698