Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "extensions/browser/api/networking_cast/networking_cast_api.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "extensions/browser/api/extensions_api_client.h" | |
| 9 #include "extensions/browser/api/networking_cast/networking_cast_delegate.h" | |
| 10 #include "extensions/common/api/networking_cast.h" | |
| 11 | |
| 12 #if defined(OS_CHROMEOS) | |
| 13 #include "chromeos/network/network_device_handler.h" | |
| 14 #include "chromeos/network/network_handler.h" | |
| 15 #endif | |
| 16 | |
| 17 namespace extensions { | |
| 18 | |
| 19 NetworkingCastVerifyDestinationFunction:: | |
| 20 ~NetworkingCastVerifyDestinationFunction() {} | |
| 21 | |
| 22 ExtensionFunction::ResponseAction | |
| 23 NetworkingCastVerifyDestinationFunction::Run() { | |
| 24 std::unique_ptr<api::networking_cast::VerifyDestination::Params> params = | |
| 25 api::networking_cast::VerifyDestination::Params::Create(*args_); | |
| 26 EXTENSION_FUNCTION_VALIDATE(params); | |
| 27 | |
| 28 NetworkingCastDelegate* delegate = | |
| 29 ExtensionsAPIClient::Get()->GetNetworkingCastDelegate(); | |
| 30 if (!delegate) | |
| 31 return RespondNow(Error("Not supported.")); | |
|
Devlin
2017/03/13 05:21:49
Why is the API compiled on unsupported platforms?
tbarzic
2017/03/13 22:35:01
Done.
| |
| 32 | |
| 33 delegate->VerifyDestination( | |
| 34 params->properties, | |
| 35 base::Bind(&NetworkingCastVerifyDestinationFunction::Success, this), | |
| 36 base::Bind(&NetworkingCastVerifyDestinationFunction::Failure, this)); | |
| 37 return did_respond() ? AlreadyResponded() : RespondLater(); | |
| 38 } | |
| 39 | |
| 40 void NetworkingCastVerifyDestinationFunction::Success(bool result) { | |
| 41 Respond(ArgumentList( | |
| 42 api::networking_cast::VerifyDestination::Results::Create(result))); | |
| 43 } | |
| 44 | |
| 45 void NetworkingCastVerifyDestinationFunction::Failure( | |
| 46 const std::string& error) { | |
| 47 Respond(Error(error)); | |
| 48 } | |
| 49 | |
| 50 NetworkingCastVerifyAndEncryptCredentialsFunction:: | |
| 51 ~NetworkingCastVerifyAndEncryptCredentialsFunction() {} | |
| 52 | |
| 53 ExtensionFunction::ResponseAction | |
| 54 NetworkingCastVerifyAndEncryptCredentialsFunction::Run() { | |
| 55 std::unique_ptr<api::networking_cast::VerifyAndEncryptCredentials::Params> | |
| 56 params = | |
| 57 api::networking_cast::VerifyAndEncryptCredentials::Params::Create( | |
| 58 *args_); | |
| 59 EXTENSION_FUNCTION_VALIDATE(params); | |
| 60 | |
| 61 NetworkingCastDelegate* delegate = | |
| 62 ExtensionsAPIClient::Get()->GetNetworkingCastDelegate(); | |
| 63 if (!delegate) | |
| 64 return RespondNow(Error("Not supported.")); | |
| 65 | |
| 66 delegate->VerifyAndEncryptCredentials( | |
| 67 params->network_guid, params->properties, | |
| 68 base::Bind(&NetworkingCastVerifyAndEncryptCredentialsFunction::Success, | |
| 69 this), | |
| 70 base::Bind(&NetworkingCastVerifyAndEncryptCredentialsFunction::Failure, | |
| 71 this)); | |
| 72 return did_respond() ? AlreadyResponded() : RespondLater(); | |
|
Devlin
2017/03/13 05:21:49
Can these respond synchronously? If so, we should
tbarzic
2017/03/13 22:35:01
Yes, it can respond synchronously, in tests.
| |
| 73 } | |
| 74 | |
| 75 void NetworkingCastVerifyAndEncryptCredentialsFunction::Success( | |
| 76 const std::string& result) { | |
| 77 Respond(ArgumentList( | |
| 78 api::networking_cast::VerifyAndEncryptCredentials::Results::Create( | |
| 79 result))); | |
| 80 } | |
| 81 | |
| 82 void NetworkingCastVerifyAndEncryptCredentialsFunction::Failure( | |
| 83 const std::string& error) { | |
| 84 Respond(Error(error)); | |
| 85 } | |
| 86 | |
| 87 NetworkingCastVerifyAndEncryptDataFunction:: | |
| 88 ~NetworkingCastVerifyAndEncryptDataFunction() {} | |
| 89 | |
| 90 ExtensionFunction::ResponseAction | |
| 91 NetworkingCastVerifyAndEncryptDataFunction::Run() { | |
| 92 std::unique_ptr<api::networking_cast::VerifyAndEncryptData::Params> params = | |
| 93 api::networking_cast::VerifyAndEncryptData::Params::Create(*args_); | |
| 94 EXTENSION_FUNCTION_VALIDATE(params); | |
| 95 | |
| 96 NetworkingCastDelegate* delegate = | |
| 97 ExtensionsAPIClient::Get()->GetNetworkingCastDelegate(); | |
| 98 if (!delegate) | |
| 99 return RespondNow(Error("Not supported.")); | |
| 100 | |
| 101 delegate->VerifyAndEncryptData( | |
| 102 params->data, params->properties, | |
| 103 base::Bind(&NetworkingCastVerifyAndEncryptDataFunction::Success, this), | |
| 104 base::Bind(&NetworkingCastVerifyAndEncryptDataFunction::Failure, this)); | |
| 105 return did_respond() ? AlreadyResponded() : RespondLater(); | |
| 106 } | |
| 107 | |
| 108 void NetworkingCastVerifyAndEncryptDataFunction::Success( | |
| 109 const std::string& result) { | |
| 110 Respond(ArgumentList( | |
| 111 api::networking_cast::VerifyAndEncryptData::Results::Create(result))); | |
| 112 } | |
| 113 | |
| 114 void NetworkingCastVerifyAndEncryptDataFunction::Failure( | |
| 115 const std::string& error) { | |
| 116 Respond(Error(error)); | |
| 117 } | |
| 118 | |
| 119 NetworkingCastSetWifiTDLSEnabledStateFunction:: | |
| 120 ~NetworkingCastSetWifiTDLSEnabledStateFunction() {} | |
| 121 | |
| 122 ExtensionFunction::ResponseAction | |
| 123 NetworkingCastSetWifiTDLSEnabledStateFunction::Run() { | |
| 124 std::unique_ptr<api::networking_cast::SetWifiTDLSEnabledState::Params> | |
| 125 params = | |
| 126 api::networking_cast::SetWifiTDLSEnabledState::Params::Create(*args_); | |
| 127 EXTENSION_FUNCTION_VALIDATE(params); | |
| 128 | |
| 129 #if defined(OS_CHROMEOS) | |
| 130 chromeos::NetworkHandler::Get()->network_device_handler()->SetWifiTDLSEnabled( | |
| 131 params->ip_or_mac_address, params->enabled, | |
| 132 base::Bind(&NetworkingCastSetWifiTDLSEnabledStateFunction::Success, this), | |
| 133 base::Bind(&NetworkingCastSetWifiTDLSEnabledStateFunction::Failure, | |
| 134 this)); | |
| 135 return did_respond() ? AlreadyResponded() : RespondLater(); | |
| 136 #else | |
| 137 return RespondNow(Error("Not supported")); | |
| 138 #endif | |
| 139 } | |
| 140 | |
| 141 void NetworkingCastSetWifiTDLSEnabledStateFunction::Success( | |
| 142 const std::string& result) { | |
| 143 Respond(ArgumentList( | |
| 144 api::networking_cast::SetWifiTDLSEnabledState::Results::Create( | |
| 145 api::networking_cast::ParseTDLSStatus(result)))); | |
| 146 } | |
| 147 | |
| 148 void NetworkingCastSetWifiTDLSEnabledStateFunction::Failure( | |
| 149 const std::string& error, | |
| 150 std::unique_ptr<base::DictionaryValue> error_data) { | |
| 151 Respond(Error(error)); | |
| 152 } | |
| 153 | |
| 154 NetworkingCastGetWifiTDLSStatusFunction:: | |
| 155 ~NetworkingCastGetWifiTDLSStatusFunction() {} | |
| 156 | |
| 157 ExtensionFunction::ResponseAction | |
| 158 NetworkingCastGetWifiTDLSStatusFunction::Run() { | |
| 159 std::unique_ptr<api::networking_cast::GetWifiTDLSStatus::Params> params = | |
| 160 api::networking_cast::GetWifiTDLSStatus::Params::Create(*args_); | |
| 161 EXTENSION_FUNCTION_VALIDATE(params); | |
| 162 | |
| 163 #if defined(OS_CHROMEOS) | |
| 164 chromeos::NetworkHandler::Get()->network_device_handler()->GetWifiTDLSStatus( | |
| 165 params->ip_or_mac_address, | |
| 166 base::Bind(&NetworkingCastGetWifiTDLSStatusFunction::Success, this), | |
| 167 base::Bind(&NetworkingCastGetWifiTDLSStatusFunction::Failure, this)); | |
| 168 return did_respond() ? AlreadyResponded() : RespondLater(); | |
| 169 #else | |
| 170 return RespondNow(Error("Not supported")); | |
| 171 #endif | |
| 172 } | |
| 173 | |
| 174 void NetworkingCastGetWifiTDLSStatusFunction::Success( | |
| 175 const std::string& result) { | |
| 176 Respond(ArgumentList(api::networking_cast::GetWifiTDLSStatus::Results::Create( | |
| 177 api::networking_cast::ParseTDLSStatus(result)))); | |
| 178 } | |
| 179 | |
| 180 void NetworkingCastGetWifiTDLSStatusFunction::Failure( | |
| 181 const std::string& error, | |
| 182 std::unique_ptr<base::DictionaryValue> error_data) { | |
| 183 Respond(Error(error)); | |
| 184 } | |
| 185 | |
| 186 } // namespace extensions | |
| OLD | NEW |