df4f145133ffaee569ac6dc9a36695d354cd9f42
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / networking_private / networking_private_api_chromeos.cc
1 // Copyright 2013 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.
4
5 #include "chrome/browser/extensions/api/networking_private/networking_private_api.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
10 #include "base/command_line.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/browser_process_platform_part_chromeos.h"
13 #include "chrome/browser/chromeos/profiles/profile_helper.h"
14 #include "chrome/browser/extensions/extension_function_registry.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/api/networking_private.h"
17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/shill_manager_client.h"
19 #include "chromeos/network/managed_network_configuration_handler.h"
20 #include "chromeos/network/network_connection_handler.h"
21 #include "chromeos/network/network_device_handler.h"
22 #include "chromeos/network/network_state.h"
23 #include "chromeos/network/network_state_handler.h"
24 #include "chromeos/network/onc/onc_signature.h"
25 #include "chromeos/network/onc/onc_translator.h"
26 #include "chromeos/network/shill_property_util.h"
27 #include "components/onc/onc_constants.h"
28
29 namespace api = extensions::api::networking_private;
30
31 using chromeos::DBusThreadManager;
32 using chromeos::ManagedNetworkConfigurationHandler;
33 using chromeos::NetworkHandler;
34 using chromeos::NetworkState;
35 using chromeos::NetworkStateHandler;
36 using chromeos::NetworkTypePattern;
37 using chromeos::ShillManagerClient;
38
39 namespace {
40
41 // Helper function that converts between the two types of verification
42 // properties. They should always have the same fields, but we do this here to
43 // prevent ShillManagerClient from depending directly on the extension API.
44 ShillManagerClient::VerificationProperties ConvertVerificationProperties(
45     const api::VerificationProperties& input) {
46   ShillManagerClient::VerificationProperties output;
47   COMPILE_ASSERT(sizeof(api::VerificationProperties) ==
48                      sizeof(ShillManagerClient::VerificationProperties),
49                  verification_properties_no_longer_match);
50
51   output.certificate = input.certificate;
52   output.public_key = input.public_key;
53   output.nonce = input.nonce;
54   output.signed_data = input.signed_data;
55   output.device_serial = input.device_serial;
56   output.device_ssid = input.device_ssid;
57   output.device_bssid = input.device_bssid;
58   return output;
59 }
60
61 std::string GetUserIdHash(Profile* profile) {
62   if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) {
63     return g_browser_process->platform_part()->
64         profile_helper()->GetUserIdHashFromProfile(profile);
65   } else {
66     return g_browser_process->platform_part()->
67         profile_helper()->active_user_id_hash();
68   }
69 }
70
71 }  // namespace
72
73 ////////////////////////////////////////////////////////////////////////////////
74 // NetworkingPrivateGetPropertiesFunction
75
76 NetworkingPrivateGetPropertiesFunction::
77   ~NetworkingPrivateGetPropertiesFunction() {
78 }
79
80 bool NetworkingPrivateGetPropertiesFunction::RunImpl() {
81   scoped_ptr<api::GetProperties::Params> params =
82       api::GetProperties::Params::Create(*args_);
83   EXTENSION_FUNCTION_VALIDATE(params);
84
85   NetworkHandler::Get()->managed_network_configuration_handler()->GetProperties(
86       params->network_guid,  // service path
87       base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess,
88                  this),
89       base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed,
90                  this));
91   return true;
92 }
93
94 void NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess(
95     const std::string& service_path,
96     const base::DictionaryValue& dictionary) {
97   base::DictionaryValue* network_properties = dictionary.DeepCopy();
98   network_properties->SetStringWithoutPathExpansion(onc::network_config::kGUID,
99                                                     service_path);
100   SetResult(network_properties);
101   SendResponse(true);
102 }
103
104 void NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed(
105     const std::string& error_name,
106     scoped_ptr<base::DictionaryValue> error_data) {
107   error_ = error_name;
108   SendResponse(false);
109 }
110
111 ////////////////////////////////////////////////////////////////////////////////
112 // NetworkingPrivateGetManagedPropertiesFunction
113
114 NetworkingPrivateGetManagedPropertiesFunction::
115   ~NetworkingPrivateGetManagedPropertiesFunction() {
116 }
117
118 bool NetworkingPrivateGetManagedPropertiesFunction::RunImpl() {
119   scoped_ptr<api::GetManagedProperties::Params> params =
120       api::GetManagedProperties::Params::Create(*args_);
121   EXTENSION_FUNCTION_VALIDATE(params);
122
123   std::string user_id_hash;
124   GetUserIdHash(GetProfile());
125   NetworkHandler::Get()->managed_network_configuration_handler()->
126       GetManagedProperties(
127           user_id_hash,
128           params->network_guid,  // service path
129           base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success,
130                      this),
131           base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure,
132                      this));
133   return true;
134 }
135
136 void NetworkingPrivateGetManagedPropertiesFunction::Success(
137     const std::string& service_path,
138     const base::DictionaryValue& dictionary) {
139   base::DictionaryValue* network_properties = dictionary.DeepCopy();
140   network_properties->SetStringWithoutPathExpansion(onc::network_config::kGUID,
141                                                     service_path);
142   SetResult(network_properties);
143   SendResponse(true);
144 }
145
146 void NetworkingPrivateGetManagedPropertiesFunction::Failure(
147     const std::string& error_name,
148     scoped_ptr<base::DictionaryValue> error_data) {
149   error_ = error_name;
150   SendResponse(false);
151 }
152
153 ////////////////////////////////////////////////////////////////////////////////
154 // NetworkingPrivateGetStateFunction
155
156 NetworkingPrivateGetStateFunction::
157   ~NetworkingPrivateGetStateFunction() {
158 }
159
160 bool NetworkingPrivateGetStateFunction::RunImpl() {
161   scoped_ptr<api::GetState::Params> params =
162       api::GetState::Params::Create(*args_);
163   EXTENSION_FUNCTION_VALIDATE(params);
164   // The |network_guid| parameter is storing the service path.
165   std::string service_path = params->network_guid;
166
167   const NetworkState* state = NetworkHandler::Get()->network_state_handler()->
168       GetNetworkState(service_path);
169   if (!state) {
170     error_ = "Error.InvalidParameter";
171     return false;
172   }
173
174   scoped_ptr<base::DictionaryValue> result_dict(new base::DictionaryValue);
175   state->GetProperties(result_dict.get());
176   scoped_ptr<base::DictionaryValue> onc_network_part =
177       chromeos::onc::TranslateShillServiceToONCPart(*result_dict,
178           &chromeos::onc::kNetworkWithStateSignature);
179   SetResult(onc_network_part.release());
180   SendResponse(true);
181
182   return true;
183 }
184
185 ////////////////////////////////////////////////////////////////////////////////
186 // NetworkingPrivateSetPropertiesFunction
187
188 NetworkingPrivateSetPropertiesFunction::
189 ~NetworkingPrivateSetPropertiesFunction() {
190 }
191
192 bool NetworkingPrivateSetPropertiesFunction::RunImpl() {
193   scoped_ptr<api::SetProperties::Params> params =
194       api::SetProperties::Params::Create(*args_);
195   EXTENSION_FUNCTION_VALIDATE(params);
196
197   scoped_ptr<base::DictionaryValue> properties_dict(
198       params->properties.ToValue());
199
200   NetworkHandler::Get()->managed_network_configuration_handler()->SetProperties(
201       params->network_guid,  // service path
202       *properties_dict,
203       base::Bind(&NetworkingPrivateSetPropertiesFunction::ResultCallback,
204                  this),
205       base::Bind(&NetworkingPrivateSetPropertiesFunction::ErrorCallback,
206                  this));
207   return true;
208 }
209
210 void NetworkingPrivateSetPropertiesFunction::ErrorCallback(
211     const std::string& error_name,
212     const scoped_ptr<base::DictionaryValue> error_data) {
213   error_ = error_name;
214   SendResponse(false);
215 }
216
217 void NetworkingPrivateSetPropertiesFunction::ResultCallback() {
218   SendResponse(true);
219 }
220
221 ////////////////////////////////////////////////////////////////////////////////
222 // NetworkingPrivateCreateNetworkFunction
223
224 NetworkingPrivateCreateNetworkFunction::
225 ~NetworkingPrivateCreateNetworkFunction() {
226 }
227
228 bool NetworkingPrivateCreateNetworkFunction::RunImpl() {
229   scoped_ptr<api::CreateNetwork::Params> params =
230       api::CreateNetwork::Params::Create(*args_);
231   EXTENSION_FUNCTION_VALIDATE(params);
232
233   std::string user_id_hash;
234   if (!params->shared)
235     user_id_hash = GetUserIdHash(GetProfile());
236
237   scoped_ptr<base::DictionaryValue> properties_dict(
238       params->properties.ToValue());
239
240   NetworkHandler::Get()->managed_network_configuration_handler()->
241       CreateConfiguration(
242           user_id_hash,
243           *properties_dict,
244           base::Bind(&NetworkingPrivateCreateNetworkFunction::ResultCallback,
245                      this),
246           base::Bind(&NetworkingPrivateCreateNetworkFunction::ErrorCallback,
247                      this));
248   return true;
249 }
250
251 void NetworkingPrivateCreateNetworkFunction::ErrorCallback(
252     const std::string& error_name,
253     const scoped_ptr<base::DictionaryValue> error_data) {
254   error_ = error_name;
255   SendResponse(false);
256 }
257
258 void NetworkingPrivateCreateNetworkFunction::ResultCallback(
259     const std::string& guid) {
260   results_ = api::CreateNetwork::Results::Create(guid);
261   SendResponse(true);
262 }
263
264 ////////////////////////////////////////////////////////////////////////////////
265 // NetworkingPrivateGetVisibleNetworksFunction
266
267 NetworkingPrivateGetVisibleNetworksFunction::
268 ~NetworkingPrivateGetVisibleNetworksFunction() {
269 }
270
271 bool NetworkingPrivateGetVisibleNetworksFunction::RunImpl() {
272   scoped_ptr<api::GetVisibleNetworks::Params> params =
273       api::GetVisibleNetworks::Params::Create(*args_);
274   EXTENSION_FUNCTION_VALIDATE(params);
275   std::string type_filter =
276       api::GetVisibleNetworks::Params::ToString(params->type);
277
278   NetworkStateHandler::NetworkStateList network_states;
279   NetworkHandler::Get()->network_state_handler()->GetNetworkList(
280       &network_states);
281
282   base::ListValue* network_properties_list = new base::ListValue;
283   for (NetworkStateHandler::NetworkStateList::iterator it =
284            network_states.begin();
285        it != network_states.end(); ++it) {
286     const std::string& service_path = (*it)->path();
287     base::DictionaryValue shill_dictionary;
288     (*it)->GetProperties(&shill_dictionary);
289
290     scoped_ptr<base::DictionaryValue> onc_network_part =
291         chromeos::onc::TranslateShillServiceToONCPart(shill_dictionary,
292             &chromeos::onc::kNetworkWithStateSignature);
293
294     std::string onc_type;
295     onc_network_part->GetStringWithoutPathExpansion(onc::network_config::kType,
296                                                     &onc_type);
297     if (type_filter == onc::network_type::kAllTypes ||
298         onc_type == type_filter) {
299       onc_network_part->SetStringWithoutPathExpansion(
300           onc::network_config::kGUID,
301           service_path);
302       network_properties_list->Append(onc_network_part.release());
303     }
304   }
305
306   SetResult(network_properties_list);
307   SendResponse(true);
308   return true;
309 }
310
311 ////////////////////////////////////////////////////////////////////////////////
312 // NetworkingPrivateGetEnabledNetworkTypesFunction
313
314 NetworkingPrivateGetEnabledNetworkTypesFunction::
315 ~NetworkingPrivateGetEnabledNetworkTypesFunction() {
316 }
317
318 bool NetworkingPrivateGetEnabledNetworkTypesFunction::RunImpl() {
319   NetworkStateHandler* state_handler =
320       NetworkHandler::Get()->network_state_handler();
321
322   base::ListValue* network_list = new base::ListValue;
323
324   if (state_handler->IsTechnologyEnabled(NetworkTypePattern::Ethernet()))
325     network_list->AppendString("Ethernet");
326   if (state_handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()))
327     network_list->AppendString("WiFi");
328   if (state_handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()))
329     network_list->AppendString("Cellular");
330
331   SetResult(network_list);
332   return true;
333 }
334
335 ////////////////////////////////////////////////////////////////////////////////
336 // NetworkingPrivateEnableNetworkTypeFunction
337
338 NetworkingPrivateEnableNetworkTypeFunction::
339 ~NetworkingPrivateEnableNetworkTypeFunction() {
340 }
341
342 bool NetworkingPrivateEnableNetworkTypeFunction::RunImpl() {
343   scoped_ptr<api::EnableNetworkType::Params> params =
344       api::EnableNetworkType::Params::Create(*args_);
345   EXTENSION_FUNCTION_VALIDATE(params);
346   NetworkStateHandler* state_handler =
347       NetworkHandler::Get()->network_state_handler();
348
349   switch (params->network_type) {
350     case api::NETWORK_TYPE_ETHERNET:
351       state_handler->SetTechnologyEnabled(
352           NetworkTypePattern::Ethernet(), true,
353           chromeos::network_handler::ErrorCallback());
354       break;
355
356     case api::NETWORK_TYPE_WIFI:
357       state_handler->SetTechnologyEnabled(
358           NetworkTypePattern::WiFi(), true,
359           chromeos::network_handler::ErrorCallback());
360       break;
361
362     case api::NETWORK_TYPE_CELLULAR:
363       state_handler->SetTechnologyEnabled(
364           NetworkTypePattern::Cellular(), true,
365           chromeos::network_handler::ErrorCallback());
366       break;
367
368     default:
369       break;
370   }
371   return true;
372 }
373
374 ////////////////////////////////////////////////////////////////////////////////
375 // NetworkingPrivateDisableNetworkTypeFunction
376
377 NetworkingPrivateDisableNetworkTypeFunction::
378 ~NetworkingPrivateDisableNetworkTypeFunction() {
379 }
380
381 bool NetworkingPrivateDisableNetworkTypeFunction::RunImpl() {
382   scoped_ptr<api::DisableNetworkType::Params> params =
383       api::DisableNetworkType::Params::Create(*args_);
384   NetworkStateHandler* state_handler =
385       NetworkHandler::Get()->network_state_handler();
386
387   switch (params->network_type) {
388     case api::NETWORK_TYPE_ETHERNET:
389       state_handler->SetTechnologyEnabled(
390           NetworkTypePattern::Ethernet(), false,
391           chromeos::network_handler::ErrorCallback());
392       break;
393
394     case api::NETWORK_TYPE_WIFI:
395       state_handler->SetTechnologyEnabled(
396           NetworkTypePattern::WiFi(), false,
397           chromeos::network_handler::ErrorCallback());
398       break;
399
400     case api::NETWORK_TYPE_CELLULAR:
401       state_handler->SetTechnologyEnabled(
402           NetworkTypePattern::Cellular(), false,
403           chromeos::network_handler::ErrorCallback());
404       break;
405
406     default:
407       break;
408   }
409
410   return true;
411 }
412
413 ////////////////////////////////////////////////////////////////////////////////
414 // NetworkingPrivateRequestNetworkScanFunction
415
416 NetworkingPrivateRequestNetworkScanFunction::
417 ~NetworkingPrivateRequestNetworkScanFunction() {
418 }
419
420 bool NetworkingPrivateRequestNetworkScanFunction::RunImpl() {
421   NetworkHandler::Get()->network_state_handler()->RequestScan();
422   return true;
423 }
424
425 ////////////////////////////////////////////////////////////////////////////////
426 // NetworkingPrivateStartConnectFunction
427
428 NetworkingPrivateStartConnectFunction::
429   ~NetworkingPrivateStartConnectFunction() {
430 }
431
432 void  NetworkingPrivateStartConnectFunction::ConnectionStartSuccess() {
433   SendResponse(true);
434 }
435
436 void NetworkingPrivateStartConnectFunction::ConnectionStartFailed(
437     const std::string& error_name,
438     const scoped_ptr<base::DictionaryValue> error_data) {
439   error_ = error_name;
440   SendResponse(false);
441 }
442
443 bool NetworkingPrivateStartConnectFunction::RunImpl() {
444   scoped_ptr<api::StartConnect::Params> params =
445       api::StartConnect::Params::Create(*args_);
446   EXTENSION_FUNCTION_VALIDATE(params);
447
448   const bool check_error_state = false;
449   NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork(
450       params->network_guid,  // service path
451       base::Bind(
452           &NetworkingPrivateStartConnectFunction::ConnectionStartSuccess,
453           this),
454       base::Bind(
455           &NetworkingPrivateStartConnectFunction::ConnectionStartFailed,
456           this),
457       check_error_state);
458   return true;
459 }
460
461 ////////////////////////////////////////////////////////////////////////////////
462 // NetworkingPrivateStartDisconnectFunction
463
464 NetworkingPrivateStartDisconnectFunction::
465   ~NetworkingPrivateStartDisconnectFunction() {
466 }
467
468 void  NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess() {
469   SendResponse(true);
470 }
471
472 void NetworkingPrivateStartDisconnectFunction::DisconnectionStartFailed(
473     const std::string& error_name,
474     const scoped_ptr<base::DictionaryValue> error_data) {
475   error_ = error_name;
476   SendResponse(false);
477 }
478
479 bool NetworkingPrivateStartDisconnectFunction::RunImpl() {
480   scoped_ptr<api::StartDisconnect::Params> params =
481       api::StartDisconnect::Params::Create(*args_);
482   EXTENSION_FUNCTION_VALIDATE(params);
483
484   NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork(
485       params->network_guid,  // service path
486       base::Bind(
487           &NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess,
488           this),
489       base::Bind(
490           &NetworkingPrivateStartDisconnectFunction::DisconnectionStartFailed,
491           this));
492   return true;
493 }
494
495 ////////////////////////////////////////////////////////////////////////////////
496 // NetworkingPrivateVerifyDestinationFunction
497
498 NetworkingPrivateVerifyDestinationFunction::
499   ~NetworkingPrivateVerifyDestinationFunction() {
500 }
501
502 bool NetworkingPrivateVerifyDestinationFunction::RunImpl() {
503   scoped_ptr<api::VerifyDestination::Params> params =
504       api::VerifyDestination::Params::Create(*args_);
505   EXTENSION_FUNCTION_VALIDATE(params);
506
507   ShillManagerClient::VerificationProperties verification_properties =
508       ConvertVerificationProperties(params->properties);
509
510   DBusThreadManager::Get()->GetShillManagerClient()->VerifyDestination(
511       verification_properties,
512       base::Bind(
513           &NetworkingPrivateVerifyDestinationFunction::ResultCallback,
514           this),
515       base::Bind(
516           &NetworkingPrivateVerifyDestinationFunction::ErrorCallback,
517           this));
518   return true;
519 }
520
521 void NetworkingPrivateVerifyDestinationFunction::ResultCallback(
522     bool result) {
523   results_ = api::VerifyDestination::Results::Create(result);
524   SendResponse(true);
525 }
526
527 void NetworkingPrivateVerifyDestinationFunction::ErrorCallback(
528     const std::string& error_name, const std::string& error) {
529   error_ = error_name;
530   SendResponse(false);
531 }
532
533 ////////////////////////////////////////////////////////////////////////////////
534 // NetworkingPrivateVerifyAndEncryptCredentialsFunction
535
536 NetworkingPrivateVerifyAndEncryptCredentialsFunction::
537   ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() {
538 }
539
540 bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunImpl() {
541   scoped_ptr<api::VerifyAndEncryptCredentials::Params> params =
542       api::VerifyAndEncryptCredentials::Params::Create(*args_);
543   EXTENSION_FUNCTION_VALIDATE(params);
544   ShillManagerClient* shill_manager_client =
545       DBusThreadManager::Get()->GetShillManagerClient();
546
547   ShillManagerClient::VerificationProperties verification_properties =
548       ConvertVerificationProperties(params->properties);
549
550   shill_manager_client->VerifyAndEncryptCredentials(
551       verification_properties,
552       params->guid,
553       base::Bind(
554           &NetworkingPrivateVerifyAndEncryptCredentialsFunction::ResultCallback,
555           this),
556       base::Bind(
557           &NetworkingPrivateVerifyAndEncryptCredentialsFunction::ErrorCallback,
558           this));
559   return true;
560 }
561
562 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::ResultCallback(
563     const std::string& result) {
564   results_ = api::VerifyAndEncryptCredentials::Results::Create(result);
565   SendResponse(true);
566 }
567
568 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::ErrorCallback(
569     const std::string& error_name, const std::string& error) {
570   error_ = error_name;
571   SendResponse(false);
572 }
573
574 ////////////////////////////////////////////////////////////////////////////////
575 // NetworkingPrivateVerifyAndEncryptDataFunction
576
577 NetworkingPrivateVerifyAndEncryptDataFunction::
578   ~NetworkingPrivateVerifyAndEncryptDataFunction() {
579 }
580
581 bool NetworkingPrivateVerifyAndEncryptDataFunction::RunImpl() {
582   scoped_ptr<api::VerifyAndEncryptData::Params> params =
583       api::VerifyAndEncryptData::Params::Create(*args_);
584   EXTENSION_FUNCTION_VALIDATE(params);
585
586   ShillManagerClient::VerificationProperties verification_properties =
587       ConvertVerificationProperties(params->properties);
588
589   DBusThreadManager::Get()->GetShillManagerClient()->VerifyAndEncryptData(
590       verification_properties,
591       params->data,
592       base::Bind(
593           &NetworkingPrivateVerifyAndEncryptDataFunction::ResultCallback,
594           this),
595       base::Bind(
596           &NetworkingPrivateVerifyAndEncryptDataFunction::ErrorCallback,
597           this));
598   return true;
599 }
600
601 void NetworkingPrivateVerifyAndEncryptDataFunction::ResultCallback(
602     const std::string& result) {
603   results_ = api::VerifyAndEncryptData::Results::Create(result);
604   SendResponse(true);
605 }
606
607 void NetworkingPrivateVerifyAndEncryptDataFunction::ErrorCallback(
608     const std::string& error_name,
609     const std::string& error) {
610   error_ = error_name;
611   SendResponse(false);
612 }
613
614 ////////////////////////////////////////////////////////////////////////////////
615 // NetworkingPrivateSetWifiTDLSEnabledStateFunction
616
617 NetworkingPrivateSetWifiTDLSEnabledStateFunction::
618   ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() {
619 }
620
621 bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunImpl() {
622   scoped_ptr<api::SetWifiTDLSEnabledState::Params> params =
623       api::SetWifiTDLSEnabledState::Params::Create(*args_);
624   EXTENSION_FUNCTION_VALIDATE(params);
625
626   std::string ip_or_mac_address = params->ip_or_mac_address;
627   bool enable = params->enabled;
628
629   NetworkHandler::Get()->network_device_handler()->
630       SetWifiTDLSEnabled(
631           ip_or_mac_address,
632           enable,
633           base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success,
634                      this),
635           base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure,
636                      this));
637
638   return true;
639 }
640
641 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success(
642     const std::string& result) {
643   results_ = api::SetWifiTDLSEnabledState::Results::Create(result);
644   SendResponse(true);
645 }
646
647 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure(
648     const std::string& error_name,
649     scoped_ptr<base::DictionaryValue> error_data) {
650   error_ = error_name;
651   SendResponse(false);
652 }
653
654 ////////////////////////////////////////////////////////////////////////////////
655 // NetworkingPrivateGetWifiTDLSStatusFunction
656
657 NetworkingPrivateGetWifiTDLSStatusFunction::
658   ~NetworkingPrivateGetWifiTDLSStatusFunction() {
659 }
660
661 bool NetworkingPrivateGetWifiTDLSStatusFunction::RunImpl() {
662   scoped_ptr<api::GetWifiTDLSStatus::Params> params =
663       api::GetWifiTDLSStatus::Params::Create(*args_);
664   EXTENSION_FUNCTION_VALIDATE(params);
665
666   std::string ip_or_mac_address = params->ip_or_mac_address;
667
668   NetworkHandler::Get()->network_device_handler()->
669       GetWifiTDLSStatus(
670           ip_or_mac_address,
671           base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success,
672                      this),
673           base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure,
674                      this));
675
676   return true;
677 }
678
679 void NetworkingPrivateGetWifiTDLSStatusFunction::Success(
680     const std::string& result) {
681   results_ = api::GetWifiTDLSStatus::Results::Create(result);
682   SendResponse(true);
683 }
684
685 void NetworkingPrivateGetWifiTDLSStatusFunction::Failure(
686     const std::string& error_name,
687     scoped_ptr<base::DictionaryValue> error_data) {
688   error_ = error_name;
689   SendResponse(false);
690 }