Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / api / networking_private / networking_private_api.cc
blobf429462cb75b607e6b021aa4b2c849fb20b6bd39
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/browser/api/networking_private/networking_private_api.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
10 #include "components/onc/onc_constants.h"
11 #include "extensions/browser/api/networking_private/networking_private_delegate.h"
12 #include "extensions/browser/api/networking_private/networking_private_delegate_factory.h"
13 #include "extensions/browser/extension_function_registry.h"
14 #include "extensions/common/api/networking_private.h"
16 namespace {
18 const int kDefaultNetworkListLimit = 1000;
20 extensions::NetworkingPrivateDelegate* GetDelegate(
21 content::BrowserContext* browser_context) {
22 return extensions::NetworkingPrivateDelegateFactory::GetForBrowserContext(
23 browser_context);
26 } // namespace
28 namespace extensions {
30 namespace private_api = api::networking_private;
32 namespace networking_private {
34 // static
35 const char kErrorInvalidNetworkGuid[] = "Error.InvalidNetworkGuid";
36 const char kErrorInvalidNetworkOperation[] = "Error.InvalidNetworkOperation";
37 const char kErrorNetworkUnavailable[] = "Error.NetworkUnavailable";
38 const char kErrorEncryptionError[] = "Error.EncryptionError";
39 const char kErrorNotReady[] = "Error.NotReady";
40 const char kErrorNotSupported[] = "Error.NotSupported";
41 const char kErrorSimLocked[] = "Error.SimLocked";
43 } // namespace networking_private
45 ////////////////////////////////////////////////////////////////////////////////
46 // NetworkingPrivateGetPropertiesFunction
48 NetworkingPrivateGetPropertiesFunction::
49 ~NetworkingPrivateGetPropertiesFunction() {
52 bool NetworkingPrivateGetPropertiesFunction::RunAsync() {
53 scoped_ptr<private_api::GetProperties::Params> params =
54 private_api::GetProperties::Params::Create(*args_);
55 EXTENSION_FUNCTION_VALIDATE(params);
57 GetDelegate(browser_context())
58 ->GetProperties(
59 params->network_guid,
60 base::Bind(&NetworkingPrivateGetPropertiesFunction::Success, this),
61 base::Bind(&NetworkingPrivateGetPropertiesFunction::Failure, this));
62 return true;
65 void NetworkingPrivateGetPropertiesFunction::Success(
66 scoped_ptr<base::DictionaryValue> result) {
67 SetResult(result.release());
68 SendResponse(true);
71 void NetworkingPrivateGetPropertiesFunction::Failure(const std::string& error) {
72 error_ = error;
73 SendResponse(false);
76 ////////////////////////////////////////////////////////////////////////////////
77 // NetworkingPrivateGetManagedPropertiesFunction
79 NetworkingPrivateGetManagedPropertiesFunction::
80 ~NetworkingPrivateGetManagedPropertiesFunction() {
83 bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() {
84 scoped_ptr<private_api::GetManagedProperties::Params> params =
85 private_api::GetManagedProperties::Params::Create(*args_);
86 EXTENSION_FUNCTION_VALIDATE(params);
88 GetDelegate(browser_context())
89 ->GetManagedProperties(
90 params->network_guid,
91 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success,
92 this),
93 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure,
94 this));
95 return true;
98 void NetworkingPrivateGetManagedPropertiesFunction::Success(
99 scoped_ptr<base::DictionaryValue> result) {
100 SetResult(result.release());
101 SendResponse(true);
104 void NetworkingPrivateGetManagedPropertiesFunction::Failure(
105 const std::string& error) {
106 error_ = error;
107 SendResponse(false);
110 ////////////////////////////////////////////////////////////////////////////////
111 // NetworkingPrivateGetStateFunction
113 NetworkingPrivateGetStateFunction::~NetworkingPrivateGetStateFunction() {
116 bool NetworkingPrivateGetStateFunction::RunAsync() {
117 scoped_ptr<private_api::GetState::Params> params =
118 private_api::GetState::Params::Create(*args_);
119 EXTENSION_FUNCTION_VALIDATE(params);
121 GetDelegate(browser_context())
122 ->GetState(params->network_guid,
123 base::Bind(&NetworkingPrivateGetStateFunction::Success, this),
124 base::Bind(&NetworkingPrivateGetStateFunction::Failure, this));
125 return true;
128 void NetworkingPrivateGetStateFunction::Success(
129 scoped_ptr<base::DictionaryValue> result) {
130 SetResult(result.release());
131 SendResponse(true);
134 void NetworkingPrivateGetStateFunction::Failure(const std::string& error) {
135 error_ = error;
136 SendResponse(false);
139 ////////////////////////////////////////////////////////////////////////////////
140 // NetworkingPrivateSetPropertiesFunction
142 NetworkingPrivateSetPropertiesFunction::
143 ~NetworkingPrivateSetPropertiesFunction() {
146 bool NetworkingPrivateSetPropertiesFunction::RunAsync() {
147 scoped_ptr<private_api::SetProperties::Params> params =
148 private_api::SetProperties::Params::Create(*args_);
149 EXTENSION_FUNCTION_VALIDATE(params);
151 scoped_ptr<base::DictionaryValue> properties_dict(
152 params->properties.ToValue());
154 GetDelegate(browser_context())
155 ->SetProperties(
156 params->network_guid, properties_dict.Pass(),
157 base::Bind(&NetworkingPrivateSetPropertiesFunction::Success, this),
158 base::Bind(&NetworkingPrivateSetPropertiesFunction::Failure, this));
159 return true;
162 void NetworkingPrivateSetPropertiesFunction::Success() {
163 SendResponse(true);
166 void NetworkingPrivateSetPropertiesFunction::Failure(const std::string& error) {
167 error_ = error;
168 SendResponse(false);
171 ////////////////////////////////////////////////////////////////////////////////
172 // NetworkingPrivateCreateNetworkFunction
174 NetworkingPrivateCreateNetworkFunction::
175 ~NetworkingPrivateCreateNetworkFunction() {
178 bool NetworkingPrivateCreateNetworkFunction::RunAsync() {
179 scoped_ptr<private_api::CreateNetwork::Params> params =
180 private_api::CreateNetwork::Params::Create(*args_);
181 EXTENSION_FUNCTION_VALIDATE(params);
183 scoped_ptr<base::DictionaryValue> properties_dict(
184 params->properties.ToValue());
186 GetDelegate(browser_context())
187 ->CreateNetwork(
188 params->shared, properties_dict.Pass(),
189 base::Bind(&NetworkingPrivateCreateNetworkFunction::Success, this),
190 base::Bind(&NetworkingPrivateCreateNetworkFunction::Failure, this));
191 return true;
194 void NetworkingPrivateCreateNetworkFunction::Success(const std::string& guid) {
195 results_ = private_api::CreateNetwork::Results::Create(guid);
196 SendResponse(true);
199 void NetworkingPrivateCreateNetworkFunction::Failure(const std::string& error) {
200 error_ = error;
201 SendResponse(false);
204 ////////////////////////////////////////////////////////////////////////////////
205 // NetworkingPrivateForgetNetworkFunction
207 NetworkingPrivateForgetNetworkFunction::
208 ~NetworkingPrivateForgetNetworkFunction() {
211 bool NetworkingPrivateForgetNetworkFunction::RunAsync() {
212 scoped_ptr<private_api::ForgetNetwork::Params> params =
213 private_api::ForgetNetwork::Params::Create(*args_);
214 EXTENSION_FUNCTION_VALIDATE(params);
216 GetDelegate(browser_context())
217 ->ForgetNetwork(
218 params->network_guid,
219 base::Bind(&NetworkingPrivateForgetNetworkFunction::Success, this),
220 base::Bind(&NetworkingPrivateForgetNetworkFunction::Failure, this));
221 return true;
224 void NetworkingPrivateForgetNetworkFunction::Success() {
225 SendResponse(true);
228 void NetworkingPrivateForgetNetworkFunction::Failure(const std::string& error) {
229 error_ = error;
230 SendResponse(false);
233 ////////////////////////////////////////////////////////////////////////////////
234 // NetworkingPrivateGetNetworksFunction
236 NetworkingPrivateGetNetworksFunction::~NetworkingPrivateGetNetworksFunction() {
239 bool NetworkingPrivateGetNetworksFunction::RunAsync() {
240 scoped_ptr<private_api::GetNetworks::Params> params =
241 private_api::GetNetworks::Params::Create(*args_);
242 EXTENSION_FUNCTION_VALIDATE(params);
244 std::string network_type = private_api::ToString(params->filter.network_type);
245 const bool configured_only =
246 params->filter.configured ? *params->filter.configured : false;
247 const bool visible_only =
248 params->filter.visible ? *params->filter.visible : false;
249 const int limit =
250 params->filter.limit ? *params->filter.limit : kDefaultNetworkListLimit;
252 GetDelegate(browser_context())
253 ->GetNetworks(
254 network_type, configured_only, visible_only, limit,
255 base::Bind(&NetworkingPrivateGetNetworksFunction::Success, this),
256 base::Bind(&NetworkingPrivateGetNetworksFunction::Failure, this));
257 return true;
260 void NetworkingPrivateGetNetworksFunction::Success(
261 scoped_ptr<base::ListValue> network_list) {
262 SetResult(network_list.release());
263 SendResponse(true);
266 void NetworkingPrivateGetNetworksFunction::Failure(const std::string& error) {
267 error_ = error;
268 SendResponse(false);
271 ////////////////////////////////////////////////////////////////////////////////
272 // NetworkingPrivateGetVisibleNetworksFunction
274 NetworkingPrivateGetVisibleNetworksFunction::
275 ~NetworkingPrivateGetVisibleNetworksFunction() {
278 bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() {
279 scoped_ptr<private_api::GetVisibleNetworks::Params> params =
280 private_api::GetVisibleNetworks::Params::Create(*args_);
281 EXTENSION_FUNCTION_VALIDATE(params);
283 std::string network_type = private_api::ToString(params->network_type);
284 const bool configured_only = false;
285 const bool visible_only = true;
287 GetDelegate(browser_context())
288 ->GetNetworks(
289 network_type, configured_only, visible_only, kDefaultNetworkListLimit,
290 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success,
291 this),
292 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure,
293 this));
294 return true;
297 void NetworkingPrivateGetVisibleNetworksFunction::Success(
298 scoped_ptr<base::ListValue> network_properties_list) {
299 SetResult(network_properties_list.release());
300 SendResponse(true);
303 void NetworkingPrivateGetVisibleNetworksFunction::Failure(
304 const std::string& error) {
305 error_ = error;
306 SendResponse(false);
309 ////////////////////////////////////////////////////////////////////////////////
310 // NetworkingPrivateGetEnabledNetworkTypesFunction
312 NetworkingPrivateGetEnabledNetworkTypesFunction::
313 ~NetworkingPrivateGetEnabledNetworkTypesFunction() {
316 bool NetworkingPrivateGetEnabledNetworkTypesFunction::RunSync() {
317 scoped_ptr<base::ListValue> enabled_networks_onc_types(
318 GetDelegate(browser_context())->GetEnabledNetworkTypes());
319 if (!enabled_networks_onc_types) {
320 error_ = networking_private::kErrorNotSupported;
321 return false;
323 scoped_ptr<base::ListValue> enabled_networks_list(new base::ListValue);
324 for (base::ListValue::iterator iter = enabled_networks_onc_types->begin();
325 iter != enabled_networks_onc_types->end(); ++iter) {
326 std::string type;
327 if (!(*iter)->GetAsString(&type))
328 NOTREACHED();
329 if (type == ::onc::network_type::kEthernet) {
330 enabled_networks_list->AppendString(
331 private_api::ToString(private_api::NETWORK_TYPE_ETHERNET));
332 } else if (type == ::onc::network_type::kWiFi) {
333 enabled_networks_list->AppendString(
334 private_api::ToString(private_api::NETWORK_TYPE_WIFI));
335 } else if (type == ::onc::network_type::kWimax) {
336 enabled_networks_list->AppendString(
337 private_api::ToString(private_api::NETWORK_TYPE_WIMAX));
338 } else if (type == ::onc::network_type::kCellular) {
339 enabled_networks_list->AppendString(
340 private_api::ToString(private_api::NETWORK_TYPE_CELLULAR));
341 } else {
342 LOG(ERROR) << "networkingPrivate: Unexpected type: " << type;
345 SetResult(enabled_networks_list.release());
346 return true;
349 ////////////////////////////////////////////////////////////////////////////////
350 // NetworkingPrivateGetDeviceStatesFunction
352 NetworkingPrivateGetDeviceStatesFunction::
353 ~NetworkingPrivateGetDeviceStatesFunction() {
356 bool NetworkingPrivateGetDeviceStatesFunction::RunSync() {
357 scoped_ptr<NetworkingPrivateDelegate::DeviceStateList> device_states(
358 GetDelegate(browser_context())->GetDeviceStateList());
359 if (!device_states) {
360 error_ = networking_private::kErrorNotSupported;
361 return false;
364 scoped_ptr<base::ListValue> device_state_list(new base::ListValue);
365 for (const private_api::DeviceStateProperties* properties : *device_states)
366 device_state_list->Append(properties->ToValue().release());
367 SetResult(device_state_list.release());
368 return true;
371 ////////////////////////////////////////////////////////////////////////////////
372 // NetworkingPrivateEnableNetworkTypeFunction
374 NetworkingPrivateEnableNetworkTypeFunction::
375 ~NetworkingPrivateEnableNetworkTypeFunction() {
378 bool NetworkingPrivateEnableNetworkTypeFunction::RunSync() {
379 scoped_ptr<private_api::EnableNetworkType::Params> params =
380 private_api::EnableNetworkType::Params::Create(*args_);
381 EXTENSION_FUNCTION_VALIDATE(params);
383 return GetDelegate(browser_context())
384 ->EnableNetworkType(private_api::ToString(params->network_type));
387 ////////////////////////////////////////////////////////////////////////////////
388 // NetworkingPrivateDisableNetworkTypeFunction
390 NetworkingPrivateDisableNetworkTypeFunction::
391 ~NetworkingPrivateDisableNetworkTypeFunction() {
394 bool NetworkingPrivateDisableNetworkTypeFunction::RunSync() {
395 scoped_ptr<private_api::DisableNetworkType::Params> params =
396 private_api::DisableNetworkType::Params::Create(*args_);
398 return GetDelegate(browser_context())
399 ->DisableNetworkType(private_api::ToString(params->network_type));
402 ////////////////////////////////////////////////////////////////////////////////
403 // NetworkingPrivateRequestNetworkScanFunction
405 NetworkingPrivateRequestNetworkScanFunction::
406 ~NetworkingPrivateRequestNetworkScanFunction() {
409 bool NetworkingPrivateRequestNetworkScanFunction::RunSync() {
410 return GetDelegate(browser_context())->RequestScan();
413 ////////////////////////////////////////////////////////////////////////////////
414 // NetworkingPrivateStartConnectFunction
416 NetworkingPrivateStartConnectFunction::
417 ~NetworkingPrivateStartConnectFunction() {
420 bool NetworkingPrivateStartConnectFunction::RunAsync() {
421 scoped_ptr<private_api::StartConnect::Params> params =
422 private_api::StartConnect::Params::Create(*args_);
423 EXTENSION_FUNCTION_VALIDATE(params);
425 GetDelegate(browser_context())
426 ->StartConnect(
427 params->network_guid,
428 base::Bind(&NetworkingPrivateStartConnectFunction::Success, this),
429 base::Bind(&NetworkingPrivateStartConnectFunction::Failure, this));
430 return true;
433 void NetworkingPrivateStartConnectFunction::Success() {
434 SendResponse(true);
437 void NetworkingPrivateStartConnectFunction::Failure(const std::string& error) {
438 error_ = error;
439 SendResponse(false);
442 ////////////////////////////////////////////////////////////////////////////////
443 // NetworkingPrivateStartDisconnectFunction
445 NetworkingPrivateStartDisconnectFunction::
446 ~NetworkingPrivateStartDisconnectFunction() {
449 bool NetworkingPrivateStartDisconnectFunction::RunAsync() {
450 scoped_ptr<private_api::StartDisconnect::Params> params =
451 private_api::StartDisconnect::Params::Create(*args_);
452 EXTENSION_FUNCTION_VALIDATE(params);
454 GetDelegate(browser_context())
455 ->StartDisconnect(
456 params->network_guid,
457 base::Bind(&NetworkingPrivateStartDisconnectFunction::Success, this),
458 base::Bind(&NetworkingPrivateStartDisconnectFunction::Failure, this));
459 return true;
462 void NetworkingPrivateStartDisconnectFunction::Success() {
463 SendResponse(true);
466 void NetworkingPrivateStartDisconnectFunction::Failure(
467 const std::string& error) {
468 error_ = error;
469 SendResponse(false);
472 ////////////////////////////////////////////////////////////////////////////////
473 // NetworkingPrivateStartActivateFunction
475 NetworkingPrivateStartActivateFunction::
476 ~NetworkingPrivateStartActivateFunction() {
479 bool NetworkingPrivateStartActivateFunction::RunAsync() {
480 scoped_ptr<private_api::StartActivate::Params> params =
481 private_api::StartActivate::Params::Create(*args_);
482 EXTENSION_FUNCTION_VALIDATE(params);
484 GetDelegate(browser_context())
485 ->StartActivate(
486 params->network_guid, params->carrier ? *params->carrier : "",
487 base::Bind(&NetworkingPrivateStartActivateFunction::Success, this),
488 base::Bind(&NetworkingPrivateStartActivateFunction::Failure, this));
489 return true;
492 void NetworkingPrivateStartActivateFunction::Success() {
493 SendResponse(true);
496 void NetworkingPrivateStartActivateFunction::Failure(const std::string& error) {
497 error_ = error;
498 SendResponse(false);
501 ////////////////////////////////////////////////////////////////////////////////
502 // NetworkingPrivateVerifyDestinationFunction
504 NetworkingPrivateVerifyDestinationFunction::
505 ~NetworkingPrivateVerifyDestinationFunction() {
508 bool NetworkingPrivateVerifyDestinationFunction::RunAsync() {
509 scoped_ptr<private_api::VerifyDestination::Params> params =
510 private_api::VerifyDestination::Params::Create(*args_);
511 EXTENSION_FUNCTION_VALIDATE(params);
513 GetDelegate(browser_context())
514 ->VerifyDestination(
515 params->properties,
516 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Success,
517 this),
518 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure,
519 this));
520 return true;
523 void NetworkingPrivateVerifyDestinationFunction::Success(bool result) {
524 results_ = private_api::VerifyDestination::Results::Create(result);
525 SendResponse(true);
528 void NetworkingPrivateVerifyDestinationFunction::Failure(
529 const std::string& error) {
530 error_ = error;
531 SendResponse(false);
534 ////////////////////////////////////////////////////////////////////////////////
535 // NetworkingPrivateVerifyAndEncryptCredentialsFunction
537 NetworkingPrivateVerifyAndEncryptCredentialsFunction::
538 ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() {
541 bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() {
542 scoped_ptr<private_api::VerifyAndEncryptCredentials::Params> params =
543 private_api::VerifyAndEncryptCredentials::Params::Create(*args_);
544 EXTENSION_FUNCTION_VALIDATE(params);
546 GetDelegate(browser_context())
547 ->VerifyAndEncryptCredentials(
548 params->network_guid, params->properties,
549 base::Bind(
550 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success,
551 this),
552 base::Bind(
553 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure,
554 this));
555 return true;
558 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success(
559 const std::string& result) {
560 results_ = private_api::VerifyAndEncryptCredentials::Results::Create(result);
561 SendResponse(true);
564 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure(
565 const std::string& error) {
566 error_ = error;
567 SendResponse(false);
570 ////////////////////////////////////////////////////////////////////////////////
571 // NetworkingPrivateVerifyAndEncryptDataFunction
573 NetworkingPrivateVerifyAndEncryptDataFunction::
574 ~NetworkingPrivateVerifyAndEncryptDataFunction() {
577 bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() {
578 scoped_ptr<private_api::VerifyAndEncryptData::Params> params =
579 private_api::VerifyAndEncryptData::Params::Create(*args_);
580 EXTENSION_FUNCTION_VALIDATE(params);
582 GetDelegate(browser_context())
583 ->VerifyAndEncryptData(
584 params->properties, params->data,
585 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Success,
586 this),
587 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure,
588 this));
589 return true;
592 void NetworkingPrivateVerifyAndEncryptDataFunction::Success(
593 const std::string& result) {
594 results_ = private_api::VerifyAndEncryptData::Results::Create(result);
595 SendResponse(true);
598 void NetworkingPrivateVerifyAndEncryptDataFunction::Failure(
599 const std::string& error) {
600 error_ = error;
601 SendResponse(false);
604 ////////////////////////////////////////////////////////////////////////////////
605 // NetworkingPrivateSetWifiTDLSEnabledStateFunction
607 NetworkingPrivateSetWifiTDLSEnabledStateFunction::
608 ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() {
611 bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() {
612 scoped_ptr<private_api::SetWifiTDLSEnabledState::Params> params =
613 private_api::SetWifiTDLSEnabledState::Params::Create(*args_);
614 EXTENSION_FUNCTION_VALIDATE(params);
616 GetDelegate(browser_context())
617 ->SetWifiTDLSEnabledState(
618 params->ip_or_mac_address, params->enabled,
619 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success,
620 this),
621 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure,
622 this));
624 return true;
627 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success(
628 const std::string& result) {
629 results_ = private_api::SetWifiTDLSEnabledState::Results::Create(result);
630 SendResponse(true);
633 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure(
634 const std::string& error) {
635 error_ = error;
636 SendResponse(false);
639 ////////////////////////////////////////////////////////////////////////////////
640 // NetworkingPrivateGetWifiTDLSStatusFunction
642 NetworkingPrivateGetWifiTDLSStatusFunction::
643 ~NetworkingPrivateGetWifiTDLSStatusFunction() {
646 bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() {
647 scoped_ptr<private_api::GetWifiTDLSStatus::Params> params =
648 private_api::GetWifiTDLSStatus::Params::Create(*args_);
649 EXTENSION_FUNCTION_VALIDATE(params);
651 GetDelegate(browser_context())
652 ->GetWifiTDLSStatus(
653 params->ip_or_mac_address,
654 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success,
655 this),
656 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure,
657 this));
659 return true;
662 void NetworkingPrivateGetWifiTDLSStatusFunction::Success(
663 const std::string& result) {
664 results_ = private_api::GetWifiTDLSStatus::Results::Create(result);
665 SendResponse(true);
668 void NetworkingPrivateGetWifiTDLSStatusFunction::Failure(
669 const std::string& error) {
670 error_ = error;
671 SendResponse(false);
674 ////////////////////////////////////////////////////////////////////////////////
675 // NetworkingPrivateGetCaptivePortalStatusFunction
677 NetworkingPrivateGetCaptivePortalStatusFunction::
678 ~NetworkingPrivateGetCaptivePortalStatusFunction() {
681 bool NetworkingPrivateGetCaptivePortalStatusFunction::RunAsync() {
682 scoped_ptr<private_api::GetCaptivePortalStatus::Params> params =
683 private_api::GetCaptivePortalStatus::Params::Create(*args_);
684 EXTENSION_FUNCTION_VALIDATE(params);
686 GetDelegate(browser_context())
687 ->GetCaptivePortalStatus(
688 params->network_guid,
689 base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Success,
690 this),
691 base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Failure,
692 this));
693 return true;
696 void NetworkingPrivateGetCaptivePortalStatusFunction::Success(
697 const std::string& result) {
698 results_ = private_api::GetCaptivePortalStatus::Results::Create(
699 private_api::ParseCaptivePortalStatus(result));
700 SendResponse(true);
703 void NetworkingPrivateGetCaptivePortalStatusFunction::Failure(
704 const std::string& error) {
705 error_ = error;
706 SendResponse(false);
709 ////////////////////////////////////////////////////////////////////////////////
710 // NetworkingPrivateUnlockCellularSimFunction
712 NetworkingPrivateUnlockCellularSimFunction::
713 ~NetworkingPrivateUnlockCellularSimFunction() {}
715 bool NetworkingPrivateUnlockCellularSimFunction::RunAsync() {
716 scoped_ptr<private_api::UnlockCellularSim::Params> params =
717 private_api::UnlockCellularSim::Params::Create(*args_);
718 EXTENSION_FUNCTION_VALIDATE(params);
720 GetDelegate(browser_context())
721 ->UnlockCellularSim(
722 params->network_guid, params->pin, params->puk ? *params->puk : "",
723 base::Bind(&NetworkingPrivateUnlockCellularSimFunction::Success,
724 this),
725 base::Bind(&NetworkingPrivateUnlockCellularSimFunction::Failure,
726 this));
727 return true;
730 void NetworkingPrivateUnlockCellularSimFunction::Success() {
731 SendResponse(true);
734 void NetworkingPrivateUnlockCellularSimFunction::Failure(
735 const std::string& error) {
736 error_ = error;
737 SendResponse(false);
740 ////////////////////////////////////////////////////////////////////////////////
741 // NetworkingPrivateSetCellularSimStateFunction
743 NetworkingPrivateSetCellularSimStateFunction::
744 ~NetworkingPrivateSetCellularSimStateFunction() {}
746 bool NetworkingPrivateSetCellularSimStateFunction::RunAsync() {
747 scoped_ptr<private_api::SetCellularSimState::Params> params =
748 private_api::SetCellularSimState::Params::Create(*args_);
749 EXTENSION_FUNCTION_VALIDATE(params);
751 GetDelegate(browser_context())
752 ->SetCellularSimState(
753 params->network_guid, params->sim_state.require_pin,
754 params->sim_state.current_pin,
755 params->sim_state.new_pin ? *params->sim_state.new_pin : "",
756 base::Bind(&NetworkingPrivateSetCellularSimStateFunction::Success,
757 this),
758 base::Bind(&NetworkingPrivateSetCellularSimStateFunction::Failure,
759 this));
760 return true;
763 void NetworkingPrivateSetCellularSimStateFunction::Success() {
764 SendResponse(true);
767 void NetworkingPrivateSetCellularSimStateFunction::Failure(
768 const std::string& error) {
769 error_ = error;
770 SendResponse(false);
773 } // namespace extensions