Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / browser / api / networking_private / networking_private_api.cc
blobee660122234cd3f95b17ef26108d89866f10b0ff
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 = core_api::networking_private;
32 namespace networking_private {
34 // static
35 const char kErrorInvalidNetworkGuid[] = "Error.InvalidNetworkGuid";
36 const char kErrorNetworkUnavailable[] = "Error.NetworkUnavailable";
37 const char kErrorEncryptionError[] = "Error.EncryptionError";
38 const char kErrorNotReady[] = "Error.NotReady";
39 const char kErrorNotSupported[] = "Error.NotSupported";
41 } // namespace networking_private
43 ////////////////////////////////////////////////////////////////////////////////
44 // NetworkingPrivateGetPropertiesFunction
46 NetworkingPrivateGetPropertiesFunction::
47 ~NetworkingPrivateGetPropertiesFunction() {
50 bool NetworkingPrivateGetPropertiesFunction::RunAsync() {
51 scoped_ptr<private_api::GetProperties::Params> params =
52 private_api::GetProperties::Params::Create(*args_);
53 EXTENSION_FUNCTION_VALIDATE(params);
55 GetDelegate(browser_context())
56 ->GetProperties(
57 params->network_guid,
58 base::Bind(&NetworkingPrivateGetPropertiesFunction::Success, this),
59 base::Bind(&NetworkingPrivateGetPropertiesFunction::Failure, this));
60 return true;
63 void NetworkingPrivateGetPropertiesFunction::Success(
64 scoped_ptr<base::DictionaryValue> result) {
65 SetResult(result.release());
66 SendResponse(true);
69 void NetworkingPrivateGetPropertiesFunction::Failure(const std::string& error) {
70 error_ = error;
71 SendResponse(false);
74 ////////////////////////////////////////////////////////////////////////////////
75 // NetworkingPrivateGetManagedPropertiesFunction
77 NetworkingPrivateGetManagedPropertiesFunction::
78 ~NetworkingPrivateGetManagedPropertiesFunction() {
81 bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() {
82 scoped_ptr<private_api::GetManagedProperties::Params> params =
83 private_api::GetManagedProperties::Params::Create(*args_);
84 EXTENSION_FUNCTION_VALIDATE(params);
86 GetDelegate(browser_context())
87 ->GetManagedProperties(
88 params->network_guid,
89 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success,
90 this),
91 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure,
92 this));
93 return true;
96 void NetworkingPrivateGetManagedPropertiesFunction::Success(
97 scoped_ptr<base::DictionaryValue> result) {
98 SetResult(result.release());
99 SendResponse(true);
102 void NetworkingPrivateGetManagedPropertiesFunction::Failure(
103 const std::string& error) {
104 error_ = error;
105 SendResponse(false);
108 ////////////////////////////////////////////////////////////////////////////////
109 // NetworkingPrivateGetStateFunction
111 NetworkingPrivateGetStateFunction::~NetworkingPrivateGetStateFunction() {
114 bool NetworkingPrivateGetStateFunction::RunAsync() {
115 scoped_ptr<private_api::GetState::Params> params =
116 private_api::GetState::Params::Create(*args_);
117 EXTENSION_FUNCTION_VALIDATE(params);
119 GetDelegate(browser_context())
120 ->GetState(params->network_guid,
121 base::Bind(&NetworkingPrivateGetStateFunction::Success, this),
122 base::Bind(&NetworkingPrivateGetStateFunction::Failure, this));
123 return true;
126 void NetworkingPrivateGetStateFunction::Success(
127 scoped_ptr<base::DictionaryValue> result) {
128 SetResult(result.release());
129 SendResponse(true);
132 void NetworkingPrivateGetStateFunction::Failure(const std::string& error) {
133 error_ = error;
134 SendResponse(false);
137 ////////////////////////////////////////////////////////////////////////////////
138 // NetworkingPrivateSetPropertiesFunction
140 NetworkingPrivateSetPropertiesFunction::
141 ~NetworkingPrivateSetPropertiesFunction() {
144 bool NetworkingPrivateSetPropertiesFunction::RunAsync() {
145 scoped_ptr<private_api::SetProperties::Params> params =
146 private_api::SetProperties::Params::Create(*args_);
147 EXTENSION_FUNCTION_VALIDATE(params);
149 scoped_ptr<base::DictionaryValue> properties_dict(
150 params->properties.ToValue());
152 GetDelegate(browser_context())
153 ->SetProperties(
154 params->network_guid, properties_dict.Pass(),
155 base::Bind(&NetworkingPrivateSetPropertiesFunction::Success, this),
156 base::Bind(&NetworkingPrivateSetPropertiesFunction::Failure, this));
157 return true;
160 void NetworkingPrivateSetPropertiesFunction::Success() {
161 SendResponse(true);
164 void NetworkingPrivateSetPropertiesFunction::Failure(const std::string& error) {
165 error_ = error;
166 SendResponse(false);
169 ////////////////////////////////////////////////////////////////////////////////
170 // NetworkingPrivateCreateNetworkFunction
172 NetworkingPrivateCreateNetworkFunction::
173 ~NetworkingPrivateCreateNetworkFunction() {
176 bool NetworkingPrivateCreateNetworkFunction::RunAsync() {
177 scoped_ptr<private_api::CreateNetwork::Params> params =
178 private_api::CreateNetwork::Params::Create(*args_);
179 EXTENSION_FUNCTION_VALIDATE(params);
181 scoped_ptr<base::DictionaryValue> properties_dict(
182 params->properties.ToValue());
184 GetDelegate(browser_context())
185 ->CreateNetwork(
186 params->shared, properties_dict.Pass(),
187 base::Bind(&NetworkingPrivateCreateNetworkFunction::Success, this),
188 base::Bind(&NetworkingPrivateCreateNetworkFunction::Failure, this));
189 return true;
192 void NetworkingPrivateCreateNetworkFunction::Success(const std::string& guid) {
193 results_ = private_api::CreateNetwork::Results::Create(guid);
194 SendResponse(true);
197 void NetworkingPrivateCreateNetworkFunction::Failure(const std::string& error) {
198 error_ = error;
199 SendResponse(false);
202 ////////////////////////////////////////////////////////////////////////////////
203 // NetworkingPrivateForgetNetworkFunction
205 NetworkingPrivateForgetNetworkFunction::
206 ~NetworkingPrivateForgetNetworkFunction() {
209 bool NetworkingPrivateForgetNetworkFunction::RunAsync() {
210 scoped_ptr<private_api::ForgetNetwork::Params> params =
211 private_api::ForgetNetwork::Params::Create(*args_);
212 EXTENSION_FUNCTION_VALIDATE(params);
214 GetDelegate(browser_context())
215 ->ForgetNetwork(
216 params->network_guid,
217 base::Bind(&NetworkingPrivateForgetNetworkFunction::Success, this),
218 base::Bind(&NetworkingPrivateForgetNetworkFunction::Failure, this));
219 return true;
222 void NetworkingPrivateForgetNetworkFunction::Success() {
223 SendResponse(true);
226 void NetworkingPrivateForgetNetworkFunction::Failure(const std::string& error) {
227 error_ = error;
228 SendResponse(false);
231 ////////////////////////////////////////////////////////////////////////////////
232 // NetworkingPrivateGetNetworksFunction
234 NetworkingPrivateGetNetworksFunction::~NetworkingPrivateGetNetworksFunction() {
237 bool NetworkingPrivateGetNetworksFunction::RunAsync() {
238 scoped_ptr<private_api::GetNetworks::Params> params =
239 private_api::GetNetworks::Params::Create(*args_);
240 EXTENSION_FUNCTION_VALIDATE(params);
242 std::string network_type = private_api::ToString(params->filter.network_type);
243 const bool configured_only =
244 params->filter.configured ? *params->filter.configured : false;
245 const bool visible_only =
246 params->filter.visible ? *params->filter.visible : false;
247 const int limit =
248 params->filter.limit ? *params->filter.limit : kDefaultNetworkListLimit;
250 GetDelegate(browser_context())
251 ->GetNetworks(
252 network_type, configured_only, visible_only, limit,
253 base::Bind(&NetworkingPrivateGetNetworksFunction::Success, this),
254 base::Bind(&NetworkingPrivateGetNetworksFunction::Failure, this));
255 return true;
258 void NetworkingPrivateGetNetworksFunction::Success(
259 scoped_ptr<base::ListValue> network_list) {
260 SetResult(network_list.release());
261 SendResponse(true);
264 void NetworkingPrivateGetNetworksFunction::Failure(const std::string& error) {
265 error_ = error;
266 SendResponse(false);
269 ////////////////////////////////////////////////////////////////////////////////
270 // NetworkingPrivateGetVisibleNetworksFunction
272 NetworkingPrivateGetVisibleNetworksFunction::
273 ~NetworkingPrivateGetVisibleNetworksFunction() {
276 bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() {
277 scoped_ptr<private_api::GetVisibleNetworks::Params> params =
278 private_api::GetVisibleNetworks::Params::Create(*args_);
279 EXTENSION_FUNCTION_VALIDATE(params);
281 std::string network_type = private_api::ToString(params->network_type);
282 const bool configured_only = false;
283 const bool visible_only = true;
285 GetDelegate(browser_context())
286 ->GetNetworks(
287 network_type, configured_only, visible_only, kDefaultNetworkListLimit,
288 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success,
289 this),
290 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure,
291 this));
292 return true;
295 void NetworkingPrivateGetVisibleNetworksFunction::Success(
296 scoped_ptr<base::ListValue> network_properties_list) {
297 SetResult(network_properties_list.release());
298 SendResponse(true);
301 void NetworkingPrivateGetVisibleNetworksFunction::Failure(
302 const std::string& error) {
303 error_ = error;
304 SendResponse(false);
307 ////////////////////////////////////////////////////////////////////////////////
308 // NetworkingPrivateGetEnabledNetworkTypesFunction
310 NetworkingPrivateGetEnabledNetworkTypesFunction::
311 ~NetworkingPrivateGetEnabledNetworkTypesFunction() {
314 bool NetworkingPrivateGetEnabledNetworkTypesFunction::RunSync() {
315 scoped_ptr<base::ListValue> enabled_networks_onc_types(
316 GetDelegate(browser_context())->GetEnabledNetworkTypes());
317 if (!enabled_networks_onc_types) {
318 error_ = networking_private::kErrorNotSupported;
319 return false;
321 scoped_ptr<base::ListValue> enabled_networks_list(new base::ListValue);
322 for (base::ListValue::iterator iter = enabled_networks_onc_types->begin();
323 iter != enabled_networks_onc_types->end(); ++iter) {
324 std::string type;
325 if (!(*iter)->GetAsString(&type))
326 NOTREACHED();
327 if (type == ::onc::network_type::kEthernet) {
328 enabled_networks_list->AppendString(
329 private_api::ToString(private_api::NETWORK_TYPE_ETHERNET));
330 } else if (type == ::onc::network_type::kWiFi) {
331 enabled_networks_list->AppendString(
332 private_api::ToString(private_api::NETWORK_TYPE_WIFI));
333 } else if (type == ::onc::network_type::kWimax) {
334 enabled_networks_list->AppendString(
335 private_api::ToString(private_api::NETWORK_TYPE_WIMAX));
336 } else if (type == ::onc::network_type::kCellular) {
337 enabled_networks_list->AppendString(
338 private_api::ToString(private_api::NETWORK_TYPE_CELLULAR));
339 } else {
340 LOG(ERROR) << "networkingPrivate: Unexpected type: " << type;
343 SetResult(enabled_networks_list.release());
344 return true;
347 ////////////////////////////////////////////////////////////////////////////////
348 // NetworkingPrivateGetDeviceStatesFunction
350 NetworkingPrivateGetDeviceStatesFunction::
351 ~NetworkingPrivateGetDeviceStatesFunction() {
354 bool NetworkingPrivateGetDeviceStatesFunction::RunSync() {
355 scoped_ptr<NetworkingPrivateDelegate::DeviceStateList> device_states(
356 GetDelegate(browser_context())->GetDeviceStateList());
357 if (!device_states) {
358 error_ = networking_private::kErrorNotSupported;
359 return false;
362 scoped_ptr<base::ListValue> device_state_list(new base::ListValue);
363 for (const private_api::DeviceStateProperties* properties : *device_states)
364 device_state_list->Append(properties->ToValue().release());
365 SetResult(device_state_list.release());
366 return true;
369 ////////////////////////////////////////////////////////////////////////////////
370 // NetworkingPrivateEnableNetworkTypeFunction
372 NetworkingPrivateEnableNetworkTypeFunction::
373 ~NetworkingPrivateEnableNetworkTypeFunction() {
376 bool NetworkingPrivateEnableNetworkTypeFunction::RunSync() {
377 scoped_ptr<private_api::EnableNetworkType::Params> params =
378 private_api::EnableNetworkType::Params::Create(*args_);
379 EXTENSION_FUNCTION_VALIDATE(params);
381 return GetDelegate(browser_context())
382 ->EnableNetworkType(private_api::ToString(params->network_type));
385 ////////////////////////////////////////////////////////////////////////////////
386 // NetworkingPrivateDisableNetworkTypeFunction
388 NetworkingPrivateDisableNetworkTypeFunction::
389 ~NetworkingPrivateDisableNetworkTypeFunction() {
392 bool NetworkingPrivateDisableNetworkTypeFunction::RunSync() {
393 scoped_ptr<private_api::DisableNetworkType::Params> params =
394 private_api::DisableNetworkType::Params::Create(*args_);
396 return GetDelegate(browser_context())
397 ->DisableNetworkType(private_api::ToString(params->network_type));
400 ////////////////////////////////////////////////////////////////////////////////
401 // NetworkingPrivateRequestNetworkScanFunction
403 NetworkingPrivateRequestNetworkScanFunction::
404 ~NetworkingPrivateRequestNetworkScanFunction() {
407 bool NetworkingPrivateRequestNetworkScanFunction::RunSync() {
408 return GetDelegate(browser_context())->RequestScan();
411 ////////////////////////////////////////////////////////////////////////////////
412 // NetworkingPrivateStartConnectFunction
414 NetworkingPrivateStartConnectFunction::
415 ~NetworkingPrivateStartConnectFunction() {
418 bool NetworkingPrivateStartConnectFunction::RunAsync() {
419 scoped_ptr<private_api::StartConnect::Params> params =
420 private_api::StartConnect::Params::Create(*args_);
421 EXTENSION_FUNCTION_VALIDATE(params);
423 GetDelegate(browser_context())
424 ->StartConnect(
425 params->network_guid,
426 base::Bind(&NetworkingPrivateStartConnectFunction::Success, this),
427 base::Bind(&NetworkingPrivateStartConnectFunction::Failure, this));
428 return true;
431 void NetworkingPrivateStartConnectFunction::Success() {
432 SendResponse(true);
435 void NetworkingPrivateStartConnectFunction::Failure(const std::string& error) {
436 error_ = error;
437 SendResponse(false);
440 ////////////////////////////////////////////////////////////////////////////////
441 // NetworkingPrivateStartDisconnectFunction
443 NetworkingPrivateStartDisconnectFunction::
444 ~NetworkingPrivateStartDisconnectFunction() {
447 bool NetworkingPrivateStartDisconnectFunction::RunAsync() {
448 scoped_ptr<private_api::StartDisconnect::Params> params =
449 private_api::StartDisconnect::Params::Create(*args_);
450 EXTENSION_FUNCTION_VALIDATE(params);
452 GetDelegate(browser_context())
453 ->StartDisconnect(
454 params->network_guid,
455 base::Bind(&NetworkingPrivateStartDisconnectFunction::Success, this),
456 base::Bind(&NetworkingPrivateStartDisconnectFunction::Failure, this));
457 return true;
460 void NetworkingPrivateStartDisconnectFunction::Success() {
461 SendResponse(true);
464 void NetworkingPrivateStartDisconnectFunction::Failure(
465 const std::string& error) {
466 error_ = error;
467 SendResponse(false);
470 ////////////////////////////////////////////////////////////////////////////////
471 // NetworkingPrivateStartActivateFunction
473 NetworkingPrivateStartActivateFunction::
474 ~NetworkingPrivateStartActivateFunction() {
477 bool NetworkingPrivateStartActivateFunction::RunAsync() {
478 scoped_ptr<private_api::StartActivate::Params> params =
479 private_api::StartActivate::Params::Create(*args_);
480 EXTENSION_FUNCTION_VALIDATE(params);
482 GetDelegate(browser_context())
483 ->StartActivate(
484 params->network_guid, params->carrier ? *params->carrier : "",
485 base::Bind(&NetworkingPrivateStartActivateFunction::Success, this),
486 base::Bind(&NetworkingPrivateStartActivateFunction::Failure, this));
487 return true;
490 void NetworkingPrivateStartActivateFunction::Success() {
491 SendResponse(true);
494 void NetworkingPrivateStartActivateFunction::Failure(const std::string& error) {
495 error_ = error;
496 SendResponse(false);
499 ////////////////////////////////////////////////////////////////////////////////
500 // NetworkingPrivateVerifyDestinationFunction
502 NetworkingPrivateVerifyDestinationFunction::
503 ~NetworkingPrivateVerifyDestinationFunction() {
506 bool NetworkingPrivateVerifyDestinationFunction::RunAsync() {
507 scoped_ptr<private_api::VerifyDestination::Params> params =
508 private_api::VerifyDestination::Params::Create(*args_);
509 EXTENSION_FUNCTION_VALIDATE(params);
511 GetDelegate(browser_context())
512 ->VerifyDestination(
513 params->properties,
514 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Success,
515 this),
516 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure,
517 this));
518 return true;
521 void NetworkingPrivateVerifyDestinationFunction::Success(bool result) {
522 results_ = private_api::VerifyDestination::Results::Create(result);
523 SendResponse(true);
526 void NetworkingPrivateVerifyDestinationFunction::Failure(
527 const std::string& error) {
528 error_ = error;
529 SendResponse(false);
532 ////////////////////////////////////////////////////////////////////////////////
533 // NetworkingPrivateVerifyAndEncryptCredentialsFunction
535 NetworkingPrivateVerifyAndEncryptCredentialsFunction::
536 ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() {
539 bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() {
540 scoped_ptr<private_api::VerifyAndEncryptCredentials::Params> params =
541 private_api::VerifyAndEncryptCredentials::Params::Create(*args_);
542 EXTENSION_FUNCTION_VALIDATE(params);
544 GetDelegate(browser_context())
545 ->VerifyAndEncryptCredentials(
546 params->network_guid, params->properties,
547 base::Bind(
548 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success,
549 this),
550 base::Bind(
551 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure,
552 this));
553 return true;
556 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success(
557 const std::string& result) {
558 results_ = private_api::VerifyAndEncryptCredentials::Results::Create(result);
559 SendResponse(true);
562 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure(
563 const std::string& error) {
564 error_ = error;
565 SendResponse(false);
568 ////////////////////////////////////////////////////////////////////////////////
569 // NetworkingPrivateVerifyAndEncryptDataFunction
571 NetworkingPrivateVerifyAndEncryptDataFunction::
572 ~NetworkingPrivateVerifyAndEncryptDataFunction() {
575 bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() {
576 scoped_ptr<private_api::VerifyAndEncryptData::Params> params =
577 private_api::VerifyAndEncryptData::Params::Create(*args_);
578 EXTENSION_FUNCTION_VALIDATE(params);
580 GetDelegate(browser_context())
581 ->VerifyAndEncryptData(
582 params->properties, params->data,
583 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Success,
584 this),
585 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure,
586 this));
587 return true;
590 void NetworkingPrivateVerifyAndEncryptDataFunction::Success(
591 const std::string& result) {
592 results_ = private_api::VerifyAndEncryptData::Results::Create(result);
593 SendResponse(true);
596 void NetworkingPrivateVerifyAndEncryptDataFunction::Failure(
597 const std::string& error) {
598 error_ = error;
599 SendResponse(false);
602 ////////////////////////////////////////////////////////////////////////////////
603 // NetworkingPrivateSetWifiTDLSEnabledStateFunction
605 NetworkingPrivateSetWifiTDLSEnabledStateFunction::
606 ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() {
609 bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() {
610 scoped_ptr<private_api::SetWifiTDLSEnabledState::Params> params =
611 private_api::SetWifiTDLSEnabledState::Params::Create(*args_);
612 EXTENSION_FUNCTION_VALIDATE(params);
614 GetDelegate(browser_context())
615 ->SetWifiTDLSEnabledState(
616 params->ip_or_mac_address, params->enabled,
617 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success,
618 this),
619 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure,
620 this));
622 return true;
625 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success(
626 const std::string& result) {
627 results_ = private_api::SetWifiTDLSEnabledState::Results::Create(result);
628 SendResponse(true);
631 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure(
632 const std::string& error) {
633 error_ = error;
634 SendResponse(false);
637 ////////////////////////////////////////////////////////////////////////////////
638 // NetworkingPrivateGetWifiTDLSStatusFunction
640 NetworkingPrivateGetWifiTDLSStatusFunction::
641 ~NetworkingPrivateGetWifiTDLSStatusFunction() {
644 bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() {
645 scoped_ptr<private_api::GetWifiTDLSStatus::Params> params =
646 private_api::GetWifiTDLSStatus::Params::Create(*args_);
647 EXTENSION_FUNCTION_VALIDATE(params);
649 GetDelegate(browser_context())
650 ->GetWifiTDLSStatus(
651 params->ip_or_mac_address,
652 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success,
653 this),
654 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure,
655 this));
657 return true;
660 void NetworkingPrivateGetWifiTDLSStatusFunction::Success(
661 const std::string& result) {
662 results_ = private_api::GetWifiTDLSStatus::Results::Create(result);
663 SendResponse(true);
666 void NetworkingPrivateGetWifiTDLSStatusFunction::Failure(
667 const std::string& error) {
668 error_ = error;
669 SendResponse(false);
672 ////////////////////////////////////////////////////////////////////////////////
673 // NetworkingPrivateGetCaptivePortalStatusFunction
675 NetworkingPrivateGetCaptivePortalStatusFunction::
676 ~NetworkingPrivateGetCaptivePortalStatusFunction() {
679 bool NetworkingPrivateGetCaptivePortalStatusFunction::RunAsync() {
680 scoped_ptr<private_api::GetCaptivePortalStatus::Params> params =
681 private_api::GetCaptivePortalStatus::Params::Create(*args_);
682 EXTENSION_FUNCTION_VALIDATE(params);
684 GetDelegate(browser_context())
685 ->GetCaptivePortalStatus(
686 params->network_guid,
687 base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Success,
688 this),
689 base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Failure,
690 this));
691 return true;
694 void NetworkingPrivateGetCaptivePortalStatusFunction::Success(
695 const std::string& result) {
696 results_ = private_api::GetCaptivePortalStatus::Results::Create(
697 private_api::ParseCaptivePortalStatus(result));
698 SendResponse(true);
701 void NetworkingPrivateGetCaptivePortalStatusFunction::Failure(
702 const std::string& error) {
703 error_ = error;
704 SendResponse(false);
707 } // namespace extensions