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

Side by Side Diff: chrome/browser/chromeos/extensions/networking_private_api.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: . 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 "chrome/browser/chromeos/extensions/networking_private_api.h" 5 #include "chrome/browser/chromeos/extensions/networking_private_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/browser_process_platform_part_chromeos.h" 12 #include "chrome/browser/browser_process_platform_part_chromeos.h"
13 #include "chrome/browser/chromeos/profiles/profile_helper.h" 13 #include "chrome/browser/chromeos/profiles/profile_helper.h"
14 #include "chrome/browser/extensions/extension_function_registry.h" 14 #include "chrome/browser/extensions/extension_function_registry.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/api/networking_private.h" 16 #include "chrome/common/extensions/api/networking_private.h"
17 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/shill_manager_client.h" 18 #include "chromeos/dbus/shill_manager_client.h"
19 #include "chromeos/network/managed_network_configuration_handler.h" 19 #include "chromeos/network/managed_network_configuration_handler.h"
20 #include "chromeos/network/network_state.h" 20 #include "chromeos/network/network_state.h"
21 #include "chromeos/network/network_state_handler.h" 21 #include "chromeos/network/network_state_handler.h"
22 #include "chromeos/network/onc/onc_constants.h" 22 #include "chromeos/network/onc/onc_constants.h"
23 #include "chromeos/network/onc/onc_signature.h" 23 #include "chromeos/network/onc/onc_signature.h"
24 #include "chromeos/network/onc/onc_translator.h" 24 #include "chromeos/network/onc/onc_translator.h"
25 25
26 namespace api = extensions::api::networking_private; 26 namespace api = extensions::api::networking_private;
27 namespace onc = chromeos::onc; 27 namespace onc = chromeos::onc;
28 using chromeos::DBusThreadManager; 28 using chromeos::DBusThreadManager;
29 using chromeos::ManagedNetworkConfigurationHandler; 29 using chromeos::ManagedNetworkConfigurationHandler;
30 using chromeos::NetworkHandler;
30 using chromeos::NetworkState; 31 using chromeos::NetworkState;
31 using chromeos::NetworkStateHandler; 32 using chromeos::NetworkStateHandler;
32 using chromeos::ShillManagerClient; 33 using chromeos::ShillManagerClient;
33 34
34 namespace { 35 namespace {
35 36
36 // Helper function that converts between the two types of verification 37 // Helper function that converts between the two types of verification
37 // properties. They should always have the same fields, but we do this here to 38 // properties. They should always have the same fields, but we do this here to
38 // prevent ShillManagerClient from depending directly on the extension API. 39 // prevent ShillManagerClient from depending directly on the extension API.
39 ShillManagerClient::VerificationProperties ConvertVerificationProperties( 40 ShillManagerClient::VerificationProperties ConvertVerificationProperties(
(...skipping 20 matching lines...) Expand all
60 61
61 NetworkingPrivateGetPropertiesFunction:: 62 NetworkingPrivateGetPropertiesFunction::
62 ~NetworkingPrivateGetPropertiesFunction() { 63 ~NetworkingPrivateGetPropertiesFunction() {
63 } 64 }
64 65
65 bool NetworkingPrivateGetPropertiesFunction::RunImpl() { 66 bool NetworkingPrivateGetPropertiesFunction::RunImpl() {
66 scoped_ptr<api::GetProperties::Params> params = 67 scoped_ptr<api::GetProperties::Params> params =
67 api::GetProperties::Params::Create(*args_); 68 api::GetProperties::Params::Create(*args_);
68 EXTENSION_FUNCTION_VALIDATE(params); 69 EXTENSION_FUNCTION_VALIDATE(params);
69 70
70 ManagedNetworkConfigurationHandler::Get()->GetProperties( 71 NetworkHandler::Get()->managed_network_configuration_handler()->GetProperties(
71 params->network_guid, // service path 72 params->network_guid, // service path
72 base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess, 73 base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess,
73 this), 74 this),
74 base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed, 75 base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed,
75 this)); 76 this));
76 return true; 77 return true;
77 } 78 }
78 79
79 void NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess( 80 void NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess(
80 const std::string& service_path, 81 const std::string& service_path,
(...skipping 27 matching lines...) Expand all
108 // User ID hash presence is only enforced when multi-profiles are turned on. 109 // User ID hash presence is only enforced when multi-profiles are turned on.
109 std::string user_id_hash; 110 std::string user_id_hash;
110 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) { 111 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) {
111 user_id_hash = g_browser_process->platform_part()-> 112 user_id_hash = g_browser_process->platform_part()->
112 profile_helper()->GetUserIdHashFromProfile(profile()); 113 profile_helper()->GetUserIdHashFromProfile(profile());
113 } else { 114 } else {
114 user_id_hash = g_browser_process->platform_part()-> 115 user_id_hash = g_browser_process->platform_part()->
115 profile_helper()->active_user_id_hash(); 116 profile_helper()->active_user_id_hash();
116 } 117 }
117 118
118 ManagedNetworkConfigurationHandler::Get()->GetManagedProperties( 119 NetworkHandler::Get()->managed_network_configuration_handler()->
119 user_id_hash, 120 GetManagedProperties(
120 params->network_guid, // service path 121 user_id_hash,
121 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success, 122 params->network_guid, // service path
122 this), 123 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success,
123 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure, 124 this),
124 this)); 125 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure,
126 this));
125 return true; 127 return true;
126 } 128 }
127 129
128 void NetworkingPrivateGetManagedPropertiesFunction::Success( 130 void NetworkingPrivateGetManagedPropertiesFunction::Success(
129 const std::string& service_path, 131 const std::string& service_path,
130 const base::DictionaryValue& dictionary) { 132 const base::DictionaryValue& dictionary) {
131 base::DictionaryValue* network_properties = dictionary.DeepCopy(); 133 base::DictionaryValue* network_properties = dictionary.DeepCopy();
132 network_properties->SetStringWithoutPathExpansion(onc::network_config::kGUID, 134 network_properties->SetStringWithoutPathExpansion(onc::network_config::kGUID,
133 service_path); 135 service_path);
134 SetResult(network_properties); 136 SetResult(network_properties);
(...skipping 14 matching lines...) Expand all
149 ~NetworkingPrivateGetStateFunction() { 151 ~NetworkingPrivateGetStateFunction() {
150 } 152 }
151 153
152 bool NetworkingPrivateGetStateFunction::RunImpl() { 154 bool NetworkingPrivateGetStateFunction::RunImpl() {
153 scoped_ptr<api::GetState::Params> params = 155 scoped_ptr<api::GetState::Params> params =
154 api::GetState::Params::Create(*args_); 156 api::GetState::Params::Create(*args_);
155 EXTENSION_FUNCTION_VALIDATE(params); 157 EXTENSION_FUNCTION_VALIDATE(params);
156 // The |network_guid| parameter is storing the service path. 158 // The |network_guid| parameter is storing the service path.
157 std::string service_path = params->network_guid; 159 std::string service_path = params->network_guid;
158 160
159 const NetworkState* state = 161 const NetworkState* state = NetworkHandler::Get()->network_state_handler()->
160 NetworkStateHandler::Get()->GetNetworkState(service_path); 162 GetNetworkState(service_path);
161 if (!state) { 163 if (!state) {
162 error_ = "Error.InvalidParameter"; 164 error_ = "Error.InvalidParameter";
163 SendResponse(false); 165 SendResponse(false);
164 } 166 }
165 167
166 scoped_ptr<base::DictionaryValue> result_dict(new base::DictionaryValue); 168 scoped_ptr<base::DictionaryValue> result_dict(new base::DictionaryValue);
167 state->GetProperties(result_dict.get()); 169 state->GetProperties(result_dict.get());
168 scoped_ptr<base::DictionaryValue> onc_network_part = 170 scoped_ptr<base::DictionaryValue> onc_network_part =
169 onc::TranslateShillServiceToONCPart(*result_dict, 171 onc::TranslateShillServiceToONCPart(*result_dict,
170 &onc::kNetworkWithStateSignature); 172 &onc::kNetworkWithStateSignature);
(...skipping 11 matching lines...) Expand all
182 } 184 }
183 185
184 bool NetworkingPrivateSetPropertiesFunction::RunImpl() { 186 bool NetworkingPrivateSetPropertiesFunction::RunImpl() {
185 scoped_ptr<api::SetProperties::Params> params = 187 scoped_ptr<api::SetProperties::Params> params =
186 api::SetProperties::Params::Create(*args_); 188 api::SetProperties::Params::Create(*args_);
187 EXTENSION_FUNCTION_VALIDATE(params); 189 EXTENSION_FUNCTION_VALIDATE(params);
188 190
189 scoped_ptr<base::DictionaryValue> properties_dict( 191 scoped_ptr<base::DictionaryValue> properties_dict(
190 params->properties.ToValue()); 192 params->properties.ToValue());
191 193
192 ManagedNetworkConfigurationHandler::Get()->SetProperties( 194 NetworkHandler::Get()->managed_network_configuration_handler()->SetProperties(
193 params->network_guid, // service path 195 params->network_guid, // service path
194 *properties_dict, 196 *properties_dict,
195 base::Bind(&NetworkingPrivateSetPropertiesFunction::ResultCallback, 197 base::Bind(&NetworkingPrivateSetPropertiesFunction::ResultCallback,
196 this), 198 this),
197 base::Bind(&NetworkingPrivateSetPropertiesFunction::ErrorCallback, 199 base::Bind(&NetworkingPrivateSetPropertiesFunction::ErrorCallback,
198 this)); 200 this));
199 return true; 201 return true;
200 } 202 }
201 203
202 void NetworkingPrivateSetPropertiesFunction::ErrorCallback( 204 void NetworkingPrivateSetPropertiesFunction::ErrorCallback(
(...skipping 15 matching lines...) Expand all
218 } 220 }
219 221
220 bool NetworkingPrivateGetVisibleNetworksFunction::RunImpl() { 222 bool NetworkingPrivateGetVisibleNetworksFunction::RunImpl() {
221 scoped_ptr<api::GetVisibleNetworks::Params> params = 223 scoped_ptr<api::GetVisibleNetworks::Params> params =
222 api::GetVisibleNetworks::Params::Create(*args_); 224 api::GetVisibleNetworks::Params::Create(*args_);
223 EXTENSION_FUNCTION_VALIDATE(params); 225 EXTENSION_FUNCTION_VALIDATE(params);
224 std::string type_filter = 226 std::string type_filter =
225 api::GetVisibleNetworks::Params::ToString(params->type); 227 api::GetVisibleNetworks::Params::ToString(params->type);
226 228
227 NetworkStateHandler::NetworkStateList network_states; 229 NetworkStateHandler::NetworkStateList network_states;
228 NetworkStateHandler::Get()->GetNetworkList(&network_states); 230 NetworkHandler::Get()->network_state_handler()->GetNetworkList(
231 &network_states);
229 232
230 base::ListValue* network_properties_list = new base::ListValue; 233 base::ListValue* network_properties_list = new base::ListValue;
231 for (NetworkStateHandler::NetworkStateList::iterator it = 234 for (NetworkStateHandler::NetworkStateList::iterator it =
232 network_states.begin(); 235 network_states.begin();
233 it != network_states.end(); ++it) { 236 it != network_states.end(); ++it) {
234 const std::string& service_path = (*it)->path(); 237 const std::string& service_path = (*it)->path();
235 base::DictionaryValue shill_dictionary; 238 base::DictionaryValue shill_dictionary;
236 (*it)->GetProperties(&shill_dictionary); 239 (*it)->GetProperties(&shill_dictionary);
237 240
238 scoped_ptr<base::DictionaryValue> onc_network_part = 241 scoped_ptr<base::DictionaryValue> onc_network_part =
(...skipping 17 matching lines...) Expand all
256 } 259 }
257 260
258 //////////////////////////////////////////////////////////////////////////////// 261 ////////////////////////////////////////////////////////////////////////////////
259 // NetworkingPrivateRequestNetworkScanFunction 262 // NetworkingPrivateRequestNetworkScanFunction
260 263
261 NetworkingPrivateRequestNetworkScanFunction:: 264 NetworkingPrivateRequestNetworkScanFunction::
262 ~NetworkingPrivateRequestNetworkScanFunction() { 265 ~NetworkingPrivateRequestNetworkScanFunction() {
263 } 266 }
264 267
265 bool NetworkingPrivateRequestNetworkScanFunction::RunImpl() { 268 bool NetworkingPrivateRequestNetworkScanFunction::RunImpl() {
266 NetworkStateHandler::Get()->RequestScan(); 269 NetworkHandler::Get()->network_state_handler()->RequestScan();
267 return true; 270 return true;
268 } 271 }
269 272
270 //////////////////////////////////////////////////////////////////////////////// 273 ////////////////////////////////////////////////////////////////////////////////
271 // NetworkingPrivateStartConnectFunction 274 // NetworkingPrivateStartConnectFunction
272 275
273 NetworkingPrivateStartConnectFunction:: 276 NetworkingPrivateStartConnectFunction::
274 ~NetworkingPrivateStartConnectFunction() { 277 ~NetworkingPrivateStartConnectFunction() {
275 } 278 }
276 279
277 void NetworkingPrivateStartConnectFunction::ConnectionStartSuccess() { 280 void NetworkingPrivateStartConnectFunction::ConnectionStartSuccess() {
278 SendResponse(true); 281 SendResponse(true);
279 } 282 }
280 283
281 void NetworkingPrivateStartConnectFunction::ConnectionStartFailed( 284 void NetworkingPrivateStartConnectFunction::ConnectionStartFailed(
282 const std::string& error_name, 285 const std::string& error_name,
283 const scoped_ptr<base::DictionaryValue> error_data) { 286 const scoped_ptr<base::DictionaryValue> error_data) {
284 error_ = error_name; 287 error_ = error_name;
285 SendResponse(false); 288 SendResponse(false);
286 } 289 }
287 290
288 bool NetworkingPrivateStartConnectFunction::RunImpl() { 291 bool NetworkingPrivateStartConnectFunction::RunImpl() {
289 scoped_ptr<api::StartConnect::Params> params = 292 scoped_ptr<api::StartConnect::Params> params =
290 api::StartConnect::Params::Create(*args_); 293 api::StartConnect::Params::Create(*args_);
291 EXTENSION_FUNCTION_VALIDATE(params); 294 EXTENSION_FUNCTION_VALIDATE(params);
292 295
293 ManagedNetworkConfigurationHandler::Get()->Connect( 296 NetworkHandler::Get()->managed_network_configuration_handler()->Connect(
294 params->network_guid, // service path 297 params->network_guid, // service path
295 base::Bind( 298 base::Bind(
296 &NetworkingPrivateStartConnectFunction::ConnectionStartSuccess, 299 &NetworkingPrivateStartConnectFunction::ConnectionStartSuccess,
297 this), 300 this),
298 base::Bind( 301 base::Bind(
299 &NetworkingPrivateStartConnectFunction::ConnectionStartFailed, 302 &NetworkingPrivateStartConnectFunction::ConnectionStartFailed,
300 this)); 303 this));
301 return true; 304 return true;
302 } 305 }
303 306
(...skipping 13 matching lines...) Expand all
317 const scoped_ptr<base::DictionaryValue> error_data) { 320 const scoped_ptr<base::DictionaryValue> error_data) {
318 error_ = error_name; 321 error_ = error_name;
319 SendResponse(false); 322 SendResponse(false);
320 } 323 }
321 324
322 bool NetworkingPrivateStartDisconnectFunction::RunImpl() { 325 bool NetworkingPrivateStartDisconnectFunction::RunImpl() {
323 scoped_ptr<api::StartDisconnect::Params> params = 326 scoped_ptr<api::StartDisconnect::Params> params =
324 api::StartDisconnect::Params::Create(*args_); 327 api::StartDisconnect::Params::Create(*args_);
325 EXTENSION_FUNCTION_VALIDATE(params); 328 EXTENSION_FUNCTION_VALIDATE(params);
326 329
327 ManagedNetworkConfigurationHandler::Get()->Disconnect( 330 NetworkHandler::Get()->managed_network_configuration_handler()->Disconnect(
328 params->network_guid, // service path 331 params->network_guid, // service path
329 base::Bind( 332 base::Bind(
330 &NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess, 333 &NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess,
331 this), 334 this),
332 base::Bind( 335 base::Bind(
333 &NetworkingPrivateStartDisconnectFunction::DisconnectionStartFailed, 336 &NetworkingPrivateStartDisconnectFunction::DisconnectionStartFailed,
334 this)); 337 this));
335 return true; 338 return true;
336 } 339 }
337 340
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 const std::string& result) { 448 const std::string& result) {
446 results_ = api::VerifyAndEncryptData::Results::Create(result); 449 results_ = api::VerifyAndEncryptData::Results::Create(result);
447 SendResponse(true); 450 SendResponse(true);
448 } 451 }
449 452
450 void NetworkingPrivateVerifyAndEncryptDataFunction::ErrorCallback( 453 void NetworkingPrivateVerifyAndEncryptDataFunction::ErrorCallback(
451 const std::string& error_name, const std::string& error) { 454 const std::string& error_name, const std::string& error) {
452 error_ = error_name; 455 error_ = error_name;
453 SendResponse(false); 456 SendResponse(false);
454 } 457 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698