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