| Index: extensions/browser/api/networking_private/networking_private_api.cc
|
| diff --git a/extensions/browser/api/networking_private/networking_private_api.cc b/extensions/browser/api/networking_private/networking_private_api.cc
|
| index e1fbf985b5422f1b388b7ede5b3f25f90a8581ba..bbda2bbf81ab1e5405886ec25b93ef76f60f15de 100644
|
| --- a/extensions/browser/api/networking_private/networking_private_api.cc
|
| +++ b/extensions/browser/api/networking_private/networking_private_api.cc
|
| @@ -64,7 +64,8 @@ NetworkingPrivateGetPropertiesFunction::
|
| ~NetworkingPrivateGetPropertiesFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateGetPropertiesFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateGetPropertiesFunction::Run() {
|
| std::unique_ptr<private_api::GetProperties::Params> params =
|
| private_api::GetProperties::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -74,18 +75,19 @@ bool NetworkingPrivateGetPropertiesFunction::RunAsync() {
|
| params->network_guid,
|
| base::Bind(&NetworkingPrivateGetPropertiesFunction::Success, this),
|
| base::Bind(&NetworkingPrivateGetPropertiesFunction::Failure, this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateGetPropertiesFunction::Success(
|
| std::unique_ptr<base::DictionaryValue> result) {
|
| - SetResult(std::move(result));
|
| - SendResponse(true);
|
| + Respond(OneArgument(std::move(result)));
|
| }
|
|
|
| void NetworkingPrivateGetPropertiesFunction::Failure(const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -95,7 +97,8 @@ NetworkingPrivateGetManagedPropertiesFunction::
|
| ~NetworkingPrivateGetManagedPropertiesFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateGetManagedPropertiesFunction::Run() {
|
| std::unique_ptr<private_api::GetManagedProperties::Params> params =
|
| private_api::GetManagedProperties::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -107,19 +110,20 @@ bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() {
|
| this),
|
| base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure,
|
| this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateGetManagedPropertiesFunction::Success(
|
| std::unique_ptr<base::DictionaryValue> result) {
|
| - SetResult(std::move(result));
|
| - SendResponse(true);
|
| + Respond(OneArgument(std::move(result)));
|
| }
|
|
|
| void NetworkingPrivateGetManagedPropertiesFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -128,7 +132,7 @@ void NetworkingPrivateGetManagedPropertiesFunction::Failure(
|
| NetworkingPrivateGetStateFunction::~NetworkingPrivateGetStateFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateGetStateFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction NetworkingPrivateGetStateFunction::Run() {
|
| std::unique_ptr<private_api::GetState::Params> params =
|
| private_api::GetState::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -137,18 +141,19 @@ bool NetworkingPrivateGetStateFunction::RunAsync() {
|
| ->GetState(params->network_guid,
|
| base::Bind(&NetworkingPrivateGetStateFunction::Success, this),
|
| base::Bind(&NetworkingPrivateGetStateFunction::Failure, this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateGetStateFunction::Success(
|
| std::unique_ptr<base::DictionaryValue> result) {
|
| - SetResult(std::move(result));
|
| - SendResponse(true);
|
| + Respond(OneArgument(std::move(result)));
|
| }
|
|
|
| void NetworkingPrivateGetStateFunction::Failure(const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -158,7 +163,8 @@ NetworkingPrivateSetPropertiesFunction::
|
| ~NetworkingPrivateSetPropertiesFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateSetPropertiesFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateSetPropertiesFunction::Run() {
|
| std::unique_ptr<private_api::SetProperties::Params> params =
|
| private_api::SetProperties::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -171,16 +177,18 @@ bool NetworkingPrivateSetPropertiesFunction::RunAsync() {
|
| params->network_guid, std::move(properties_dict),
|
| base::Bind(&NetworkingPrivateSetPropertiesFunction::Success, this),
|
| base::Bind(&NetworkingPrivateSetPropertiesFunction::Failure, this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateSetPropertiesFunction::Success() {
|
| - SendResponse(true);
|
| + Respond(NoArguments());
|
| }
|
|
|
| void NetworkingPrivateSetPropertiesFunction::Failure(const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -190,7 +198,8 @@ NetworkingPrivateCreateNetworkFunction::
|
| ~NetworkingPrivateCreateNetworkFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateCreateNetworkFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateCreateNetworkFunction::Run() {
|
| std::unique_ptr<private_api::CreateNetwork::Params> params =
|
| private_api::CreateNetwork::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -203,17 +212,18 @@ bool NetworkingPrivateCreateNetworkFunction::RunAsync() {
|
| params->shared, std::move(properties_dict),
|
| base::Bind(&NetworkingPrivateCreateNetworkFunction::Success, this),
|
| base::Bind(&NetworkingPrivateCreateNetworkFunction::Failure, this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateCreateNetworkFunction::Success(const std::string& guid) {
|
| - results_ = private_api::CreateNetwork::Results::Create(guid);
|
| - SendResponse(true);
|
| + Respond(ArgumentList(private_api::CreateNetwork::Results::Create(guid)));
|
| }
|
|
|
| void NetworkingPrivateCreateNetworkFunction::Failure(const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -223,7 +233,8 @@ NetworkingPrivateForgetNetworkFunction::
|
| ~NetworkingPrivateForgetNetworkFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateForgetNetworkFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateForgetNetworkFunction::Run() {
|
| std::unique_ptr<private_api::ForgetNetwork::Params> params =
|
| private_api::ForgetNetwork::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -233,16 +244,18 @@ bool NetworkingPrivateForgetNetworkFunction::RunAsync() {
|
| params->network_guid,
|
| base::Bind(&NetworkingPrivateForgetNetworkFunction::Success, this),
|
| base::Bind(&NetworkingPrivateForgetNetworkFunction::Failure, this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateForgetNetworkFunction::Success() {
|
| - SendResponse(true);
|
| + Respond(NoArguments());
|
| }
|
|
|
| void NetworkingPrivateForgetNetworkFunction::Failure(const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -251,7 +264,7 @@ void NetworkingPrivateForgetNetworkFunction::Failure(const std::string& error) {
|
| NetworkingPrivateGetNetworksFunction::~NetworkingPrivateGetNetworksFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateGetNetworksFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction NetworkingPrivateGetNetworksFunction::Run() {
|
| std::unique_ptr<private_api::GetNetworks::Params> params =
|
| private_api::GetNetworks::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -269,18 +282,19 @@ bool NetworkingPrivateGetNetworksFunction::RunAsync() {
|
| network_type, configured_only, visible_only, limit,
|
| base::Bind(&NetworkingPrivateGetNetworksFunction::Success, this),
|
| base::Bind(&NetworkingPrivateGetNetworksFunction::Failure, this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateGetNetworksFunction::Success(
|
| std::unique_ptr<base::ListValue> network_list) {
|
| - SetResult(std::move(network_list));
|
| - SendResponse(true);
|
| + return Respond(OneArgument(std::move(network_list)));
|
| }
|
|
|
| void NetworkingPrivateGetNetworksFunction::Failure(const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -290,7 +304,8 @@ NetworkingPrivateGetVisibleNetworksFunction::
|
| ~NetworkingPrivateGetVisibleNetworksFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateGetVisibleNetworksFunction::Run() {
|
| std::unique_ptr<private_api::GetVisibleNetworks::Params> params =
|
| private_api::GetVisibleNetworks::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -300,8 +315,7 @@ bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() {
|
| // before its deprecation.
|
| if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
|
| source_url())) {
|
| - error_ = kPrivateOnlyError;
|
| - return false;
|
| + return RespondNow(Error(kPrivateOnlyError));
|
| }
|
|
|
| std::string network_type = private_api::ToString(params->network_type);
|
| @@ -315,19 +329,20 @@ bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() {
|
| this),
|
| base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure,
|
| this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateGetVisibleNetworksFunction::Success(
|
| std::unique_ptr<base::ListValue> network_properties_list) {
|
| - SetResult(std::move(network_properties_list));
|
| - SendResponse(true);
|
| + Respond(OneArgument(std::move(network_properties_list)));
|
| }
|
|
|
| void NetworkingPrivateGetVisibleNetworksFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -456,7 +471,7 @@ NetworkingPrivateStartConnectFunction::
|
| ~NetworkingPrivateStartConnectFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateStartConnectFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction NetworkingPrivateStartConnectFunction::Run() {
|
| std::unique_ptr<private_api::StartConnect::Params> params =
|
| private_api::StartConnect::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -466,16 +481,18 @@ bool NetworkingPrivateStartConnectFunction::RunAsync() {
|
| params->network_guid,
|
| base::Bind(&NetworkingPrivateStartConnectFunction::Success, this),
|
| base::Bind(&NetworkingPrivateStartConnectFunction::Failure, this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateStartConnectFunction::Success() {
|
| - SendResponse(true);
|
| + Respond(NoArguments());
|
| }
|
|
|
| void NetworkingPrivateStartConnectFunction::Failure(const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -485,7 +502,8 @@ NetworkingPrivateStartDisconnectFunction::
|
| ~NetworkingPrivateStartDisconnectFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateStartDisconnectFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateStartDisconnectFunction::Run() {
|
| std::unique_ptr<private_api::StartDisconnect::Params> params =
|
| private_api::StartDisconnect::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -495,17 +513,19 @@ bool NetworkingPrivateStartDisconnectFunction::RunAsync() {
|
| params->network_guid,
|
| base::Bind(&NetworkingPrivateStartDisconnectFunction::Success, this),
|
| base::Bind(&NetworkingPrivateStartDisconnectFunction::Failure, this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateStartDisconnectFunction::Success() {
|
| - SendResponse(true);
|
| + Respond(NoArguments());
|
| }
|
|
|
| void NetworkingPrivateStartDisconnectFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -515,7 +535,8 @@ NetworkingPrivateStartActivateFunction::
|
| ~NetworkingPrivateStartActivateFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateStartActivateFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateStartActivateFunction::Run() {
|
| std::unique_ptr<private_api::StartActivate::Params> params =
|
| private_api::StartActivate::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -525,16 +546,18 @@ bool NetworkingPrivateStartActivateFunction::RunAsync() {
|
| params->network_guid, params->carrier ? *params->carrier : "",
|
| base::Bind(&NetworkingPrivateStartActivateFunction::Success, this),
|
| base::Bind(&NetworkingPrivateStartActivateFunction::Failure, this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateStartActivateFunction::Success() {
|
| - SendResponse(true);
|
| + Respond(NoArguments());
|
| }
|
|
|
| void NetworkingPrivateStartActivateFunction::Failure(const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -544,15 +567,15 @@ NetworkingPrivateVerifyDestinationFunction::
|
| ~NetworkingPrivateVerifyDestinationFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateVerifyDestinationFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateVerifyDestinationFunction::Run() {
|
| // This method is private - as such, it should not be exposed through public
|
| // networking.onc API.
|
| // TODO(tbarzic): Consider exposing this via separate API.
|
| // http://crbug.com/678737
|
| if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
|
| source_url())) {
|
| - error_ = kPrivateOnlyError;
|
| - return false;
|
| + return RespondNow(Error(kPrivateOnlyError));
|
| }
|
|
|
| std::unique_ptr<private_api::VerifyDestination::Params> params =
|
| @@ -566,18 +589,20 @@ bool NetworkingPrivateVerifyDestinationFunction::RunAsync() {
|
| this),
|
| base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure,
|
| this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateVerifyDestinationFunction::Success(bool result) {
|
| - results_ = private_api::VerifyDestination::Results::Create(result);
|
| - SendResponse(true);
|
| + Respond(
|
| + ArgumentList(private_api::VerifyDestination::Results::Create(result)));
|
| }
|
|
|
| void NetworkingPrivateVerifyDestinationFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -587,15 +612,15 @@ NetworkingPrivateVerifyAndEncryptCredentialsFunction::
|
| ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateVerifyAndEncryptCredentialsFunction::Run() {
|
| // This method is private - as such, it should not be exposed through public
|
| // networking.onc API.
|
| // TODO(tbarzic): Consider exposing this via separate API.
|
| // http://crbug.com/678737
|
| if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
|
| source_url())) {
|
| - error_ = kPrivateOnlyError;
|
| - return false;
|
| + return RespondNow(Error(kPrivateOnlyError));
|
| }
|
| std::unique_ptr<private_api::VerifyAndEncryptCredentials::Params> params =
|
| private_api::VerifyAndEncryptCredentials::Params::Create(*args_);
|
| @@ -610,19 +635,21 @@ bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() {
|
| base::Bind(
|
| &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure,
|
| this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success(
|
| const std::string& result) {
|
| - results_ = private_api::VerifyAndEncryptCredentials::Results::Create(result);
|
| - SendResponse(true);
|
| + Respond(ArgumentList(
|
| + private_api::VerifyAndEncryptCredentials::Results::Create(result)));
|
| }
|
|
|
| void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -632,15 +659,15 @@ NetworkingPrivateVerifyAndEncryptDataFunction::
|
| ~NetworkingPrivateVerifyAndEncryptDataFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateVerifyAndEncryptDataFunction::Run() {
|
| // This method is private - as such, it should not be exposed through public
|
| // networking.onc API.
|
| // TODO(tbarzic): Consider exposing this via separate API.
|
| // http://crbug.com/678737
|
| if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
|
| source_url())) {
|
| - error_ = kPrivateOnlyError;
|
| - return false;
|
| + return RespondNow(Error(kPrivateOnlyError));
|
| }
|
| std::unique_ptr<private_api::VerifyAndEncryptData::Params> params =
|
| private_api::VerifyAndEncryptData::Params::Create(*args_);
|
| @@ -653,19 +680,21 @@ bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() {
|
| this),
|
| base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure,
|
| this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateVerifyAndEncryptDataFunction::Success(
|
| const std::string& result) {
|
| - results_ = private_api::VerifyAndEncryptData::Results::Create(result);
|
| - SendResponse(true);
|
| + Respond(
|
| + ArgumentList(private_api::VerifyAndEncryptData::Results::Create(result)));
|
| }
|
|
|
| void NetworkingPrivateVerifyAndEncryptDataFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -675,15 +704,15 @@ NetworkingPrivateSetWifiTDLSEnabledStateFunction::
|
| ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateSetWifiTDLSEnabledStateFunction::Run() {
|
| // This method is private - as such, it should not be exposed through public
|
| // networking.onc API.
|
| // TODO(tbarzic): Consider exposing this via separate API.
|
| // http://crbug.com/678737
|
| if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
|
| source_url())) {
|
| - error_ = kPrivateOnlyError;
|
| - return false;
|
| + return RespondNow(Error(kPrivateOnlyError));
|
| }
|
| std::unique_ptr<private_api::SetWifiTDLSEnabledState::Params> params =
|
| private_api::SetWifiTDLSEnabledState::Params::Create(*args_);
|
| @@ -696,20 +725,21 @@ bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() {
|
| this),
|
| base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure,
|
| this));
|
| -
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success(
|
| const std::string& result) {
|
| - results_ = private_api::SetWifiTDLSEnabledState::Results::Create(result);
|
| - SendResponse(true);
|
| + Respond(ArgumentList(
|
| + private_api::SetWifiTDLSEnabledState::Results::Create(result)));
|
| }
|
|
|
| void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -719,15 +749,15 @@ NetworkingPrivateGetWifiTDLSStatusFunction::
|
| ~NetworkingPrivateGetWifiTDLSStatusFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateGetWifiTDLSStatusFunction::Run() {
|
| // This method is private - as such, it should not be exposed through public
|
| // networking.onc API.
|
| // TODO(tbarzic): Consider exposing this via separate API.
|
| // http://crbug.com/678737
|
| if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
|
| source_url())) {
|
| - error_ = kPrivateOnlyError;
|
| - return false;
|
| + return RespondNow(Error(kPrivateOnlyError));
|
| }
|
| std::unique_ptr<private_api::GetWifiTDLSStatus::Params> params =
|
| private_api::GetWifiTDLSStatus::Params::Create(*args_);
|
| @@ -740,20 +770,21 @@ bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() {
|
| this),
|
| base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure,
|
| this));
|
| -
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateGetWifiTDLSStatusFunction::Success(
|
| const std::string& result) {
|
| - results_ = private_api::GetWifiTDLSStatus::Results::Create(result);
|
| - SendResponse(true);
|
| + Respond(
|
| + ArgumentList(private_api::GetWifiTDLSStatus::Results::Create(result)));
|
| }
|
|
|
| void NetworkingPrivateGetWifiTDLSStatusFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -763,7 +794,8 @@ NetworkingPrivateGetCaptivePortalStatusFunction::
|
| ~NetworkingPrivateGetCaptivePortalStatusFunction() {
|
| }
|
|
|
| -bool NetworkingPrivateGetCaptivePortalStatusFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateGetCaptivePortalStatusFunction::Run() {
|
| std::unique_ptr<private_api::GetCaptivePortalStatus::Params> params =
|
| private_api::GetCaptivePortalStatus::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -775,20 +807,21 @@ bool NetworkingPrivateGetCaptivePortalStatusFunction::RunAsync() {
|
| this),
|
| base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Failure,
|
| this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateGetCaptivePortalStatusFunction::Success(
|
| const std::string& result) {
|
| - results_ = private_api::GetCaptivePortalStatus::Results::Create(
|
| - private_api::ParseCaptivePortalStatus(result));
|
| - SendResponse(true);
|
| + Respond(ArgumentList(private_api::GetCaptivePortalStatus::Results::Create(
|
| + private_api::ParseCaptivePortalStatus(result))));
|
| }
|
|
|
| void NetworkingPrivateGetCaptivePortalStatusFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -797,7 +830,8 @@ void NetworkingPrivateGetCaptivePortalStatusFunction::Failure(
|
| NetworkingPrivateUnlockCellularSimFunction::
|
| ~NetworkingPrivateUnlockCellularSimFunction() {}
|
|
|
| -bool NetworkingPrivateUnlockCellularSimFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateUnlockCellularSimFunction::Run() {
|
| std::unique_ptr<private_api::UnlockCellularSim::Params> params =
|
| private_api::UnlockCellularSim::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -809,17 +843,19 @@ bool NetworkingPrivateUnlockCellularSimFunction::RunAsync() {
|
| this),
|
| base::Bind(&NetworkingPrivateUnlockCellularSimFunction::Failure,
|
| this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateUnlockCellularSimFunction::Success() {
|
| - SendResponse(true);
|
| + Respond(NoArguments());
|
| }
|
|
|
| void NetworkingPrivateUnlockCellularSimFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -828,7 +864,8 @@ void NetworkingPrivateUnlockCellularSimFunction::Failure(
|
| NetworkingPrivateSetCellularSimStateFunction::
|
| ~NetworkingPrivateSetCellularSimStateFunction() {}
|
|
|
| -bool NetworkingPrivateSetCellularSimStateFunction::RunAsync() {
|
| +ExtensionFunction::ResponseAction
|
| +NetworkingPrivateSetCellularSimStateFunction::Run() {
|
| std::unique_ptr<private_api::SetCellularSimState::Params> params =
|
| private_api::SetCellularSimState::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params);
|
| @@ -842,17 +879,19 @@ bool NetworkingPrivateSetCellularSimStateFunction::RunAsync() {
|
| this),
|
| base::Bind(&NetworkingPrivateSetCellularSimStateFunction::Failure,
|
| this));
|
| - return true;
|
| + // Success() or Failure() might have been called synchronously at this point.
|
| + // In that case this function has already called Respond(). Return
|
| + // AlreadyResponded() in that case.
|
| + return did_respond() ? AlreadyResponded() : RespondLater();
|
| }
|
|
|
| void NetworkingPrivateSetCellularSimStateFunction::Success() {
|
| - SendResponse(true);
|
| + Respond(NoArguments());
|
| }
|
|
|
| void NetworkingPrivateSetCellularSimStateFunction::Failure(
|
| const std::string& error) {
|
| - error_ = error;
|
| - SendResponse(false);
|
| + Respond(Error(error));
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|