Commit d06a2579 authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

[Extensions] Remove AsyncExtensionFunction usage from bluetooth and related APIs

AsyncExtensionFunction is deprecated and soon will be removed.

This CL does not produce any behavior changes.

Bug: 829174
Change-Id: Ic686837c11c4f8a4047a7748f133798e24d9203a
Reviewed-on: https://chromium-review.googlesource.com/997098Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549562}
parent 8de1e07f
...@@ -324,7 +324,8 @@ EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} ...@@ -324,7 +324,8 @@ EasyUnlockPrivatePerformECDHKeyAgreementFunction() {}
EasyUnlockPrivatePerformECDHKeyAgreementFunction:: EasyUnlockPrivatePerformECDHKeyAgreementFunction::
~EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() {}
bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() { ExtensionFunction::ResponseAction
EasyUnlockPrivatePerformECDHKeyAgreementFunction::Run() {
std::unique_ptr<easy_unlock_private::PerformECDHKeyAgreement::Params> params = std::unique_ptr<easy_unlock_private::PerformECDHKeyAgreement::Params> params =
easy_unlock_private::PerformECDHKeyAgreement::Params::Create(*args_); easy_unlock_private::PerformECDHKeyAgreement::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
...@@ -333,17 +334,21 @@ bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() { ...@@ -333,17 +334,21 @@ bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() {
*params, *params,
base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData, base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData,
this)); this));
return true; // TODO(https://crbug.com/829182): Resolve this.
return did_respond() ? AlreadyResponded() : RespondLater();
} }
void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData( void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData(
const std::string& secret_key) { const std::string& secret_key) {
// TODO(tbarzic): Improve error handling. // TODO(tbarzic): Improve error handling.
if (!secret_key.empty()) { if (!secret_key.empty()) {
results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create( Respond(ArgumentList(
std::vector<char>(secret_key.begin(), secret_key.end())); easy_unlock_private::PerformECDHKeyAgreement::Results::Create(
std::vector<char>(secret_key.begin(), secret_key.end()))));
return;
} }
SendResponse(true);
Respond(NoArguments());
} }
EasyUnlockPrivateGenerateEcP256KeyPairFunction:: EasyUnlockPrivateGenerateEcP256KeyPairFunction::
...@@ -352,11 +357,13 @@ EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} ...@@ -352,11 +357,13 @@ EasyUnlockPrivateGenerateEcP256KeyPairFunction() {}
EasyUnlockPrivateGenerateEcP256KeyPairFunction:: EasyUnlockPrivateGenerateEcP256KeyPairFunction::
~EasyUnlockPrivateGenerateEcP256KeyPairFunction() {} ~EasyUnlockPrivateGenerateEcP256KeyPairFunction() {}
bool EasyUnlockPrivateGenerateEcP256KeyPairFunction::RunAsync() { ExtensionFunction::ResponseAction
EasyUnlockPrivateGenerateEcP256KeyPairFunction::Run() {
GetCryptoDelegate(browser_context())->GenerateEcP256KeyPair( GetCryptoDelegate(browser_context())->GenerateEcP256KeyPair(
base::Bind(&EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData, base::Bind(&EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData,
this)); this));
return true; // TODO(https://crbug.com/829182): Resolve this.
return did_respond() ? AlreadyResponded() : RespondLater();
} }
void EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData( void EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData(
...@@ -364,11 +371,14 @@ void EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData( ...@@ -364,11 +371,14 @@ void EasyUnlockPrivateGenerateEcP256KeyPairFunction::OnData(
const std::string& public_key) { const std::string& public_key) {
// TODO(tbarzic): Improve error handling. // TODO(tbarzic): Improve error handling.
if (!public_key.empty() && !private_key.empty()) { if (!public_key.empty() && !private_key.empty()) {
results_ = easy_unlock_private::GenerateEcP256KeyPair::Results::Create( Respond(ArgumentList(
std::vector<char>(public_key.begin(), public_key.end()), easy_unlock_private::GenerateEcP256KeyPair::Results::Create(
std::vector<char>(private_key.begin(), private_key.end())); std::vector<char>(public_key.begin(), public_key.end()),
std::vector<char>(private_key.begin(), private_key.end()))));
return;
} }
SendResponse(true);
Respond(NoArguments());
} }
EasyUnlockPrivateCreateSecureMessageFunction:: EasyUnlockPrivateCreateSecureMessageFunction::
...@@ -377,7 +387,8 @@ EasyUnlockPrivateCreateSecureMessageFunction() {} ...@@ -377,7 +387,8 @@ EasyUnlockPrivateCreateSecureMessageFunction() {}
EasyUnlockPrivateCreateSecureMessageFunction:: EasyUnlockPrivateCreateSecureMessageFunction::
~EasyUnlockPrivateCreateSecureMessageFunction() {} ~EasyUnlockPrivateCreateSecureMessageFunction() {}
bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { ExtensionFunction::ResponseAction
EasyUnlockPrivateCreateSecureMessageFunction::Run() {
std::unique_ptr<easy_unlock_private::CreateSecureMessage::Params> params = std::unique_ptr<easy_unlock_private::CreateSecureMessage::Params> params =
easy_unlock_private::CreateSecureMessage::Params::Create(*args_); easy_unlock_private::CreateSecureMessage::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
...@@ -386,17 +397,21 @@ bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { ...@@ -386,17 +397,21 @@ bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() {
*params, *params,
base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData, base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData,
this)); this));
return true; // TODO(https://crbug.com/829182): Resolve this.
return did_respond() ? AlreadyResponded() : RespondLater();
} }
void EasyUnlockPrivateCreateSecureMessageFunction::OnData( void EasyUnlockPrivateCreateSecureMessageFunction::OnData(
const std::string& message) { const std::string& message) {
// TODO(tbarzic): Improve error handling. // TODO(tbarzic): Improve error handling.
if (!message.empty()) { if (!message.empty()) {
results_ = easy_unlock_private::CreateSecureMessage::Results::Create( Respond(
std::vector<char>(message.begin(), message.end())); ArgumentList(easy_unlock_private::CreateSecureMessage::Results::Create(
std::vector<char>(message.begin(), message.end()))));
return;
} }
SendResponse(true);
Respond(NoArguments());
} }
EasyUnlockPrivateUnwrapSecureMessageFunction:: EasyUnlockPrivateUnwrapSecureMessageFunction::
...@@ -405,7 +420,8 @@ EasyUnlockPrivateUnwrapSecureMessageFunction() {} ...@@ -405,7 +420,8 @@ EasyUnlockPrivateUnwrapSecureMessageFunction() {}
EasyUnlockPrivateUnwrapSecureMessageFunction:: EasyUnlockPrivateUnwrapSecureMessageFunction::
~EasyUnlockPrivateUnwrapSecureMessageFunction() {} ~EasyUnlockPrivateUnwrapSecureMessageFunction() {}
bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { ExtensionFunction::ResponseAction
EasyUnlockPrivateUnwrapSecureMessageFunction::Run() {
std::unique_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params = std::unique_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params =
easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_); easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
...@@ -414,17 +430,21 @@ bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { ...@@ -414,17 +430,21 @@ bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() {
*params, *params,
base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData, base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData,
this)); this));
return true; // TODO(https://crbug.com/829182): Resolve this.
return did_respond() ? AlreadyResponded() : RespondLater();
} }
void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData( void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData(
const std::string& data) { const std::string& data) {
// TODO(tbarzic): Improve error handling. // TODO(tbarzic): Improve error handling.
if (!data.empty()) { if (!data.empty()) {
results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create( Respond(
std::vector<char>(data.begin(), data.end())); ArgumentList(easy_unlock_private::UnwrapSecureMessage::Results::Create(
std::vector<char>(data.begin(), data.end()))));
return;
} }
SendResponse(true);
Respond(NoArguments());
} }
EasyUnlockPrivateSetPermitAccessFunction:: EasyUnlockPrivateSetPermitAccessFunction::
...@@ -551,16 +571,16 @@ EasyUnlockPrivateGetRemoteDevicesFunction:: ...@@ -551,16 +571,16 @@ EasyUnlockPrivateGetRemoteDevicesFunction::
~EasyUnlockPrivateGetRemoteDevicesFunction() { ~EasyUnlockPrivateGetRemoteDevicesFunction() {
} }
bool EasyUnlockPrivateGetRemoteDevicesFunction::RunAsync() { ExtensionFunction::ResponseAction
EasyUnlockPrivateGetRemoteDevicesFunction::Run() {
// Check that we are inside a user profile. // Check that we are inside a user profile.
Profile* profile = Profile::FromBrowserContext(browser_context()); Profile* profile = Profile::FromBrowserContext(browser_context());
chromeos::EasyUnlockService* easy_unlock_service = chromeos::EasyUnlockService* easy_unlock_service =
chromeos::EasyUnlockService::Get(profile); chromeos::EasyUnlockService::Get(profile);
if (easy_unlock_service->GetType() != if (easy_unlock_service->GetType() !=
chromeos::EasyUnlockService::TYPE_REGULAR) { chromeos::EasyUnlockService::TYPE_REGULAR) {
SetError("This function must be called inside a user session."); return RespondNow(
SendResponse(true); Error("This function must be called inside a user session."));
return true;
} }
// Get the synced unlock key data. // Get the synced unlock key data.
...@@ -574,20 +594,14 @@ bool EasyUnlockPrivateGetRemoteDevicesFunction::RunAsync() { ...@@ -574,20 +594,14 @@ bool EasyUnlockPrivateGetRemoteDevicesFunction::RunAsync() {
expected_devices_count_ = unlock_keys.size(); expected_devices_count_ = unlock_keys.size();
remote_devices_.reset(new base::ListValue()); remote_devices_.reset(new base::ListValue());
if (expected_devices_count_ == 0) { if (expected_devices_count_ == 0)
SetResult(std::move(remote_devices_)); return RespondNow(OneArgument(std::move(remote_devices_)));
SendResponse(true);
return true;
}
// If there is a BLE unlock key, then don't return anything, so the app does // If there is a BLE unlock key, then don't return anything, so the app does
// not try the classic Bluetooth protocol. // not try the classic Bluetooth protocol.
for (const auto& unlock_key : unlock_keys) { for (const auto& unlock_key : unlock_keys) {
if (unlock_key.bluetooth_address().empty()) { if (unlock_key.bluetooth_address().empty())
SetResult(std::move(remote_devices_)); return RespondNow(OneArgument(std::move(remote_devices_)));
SendResponse(true);
return true;
}
} }
// Derive the PSKs for the user's unlock keys. // Derive the PSKs for the user's unlock keys.
...@@ -601,8 +615,7 @@ bool EasyUnlockPrivateGetRemoteDevicesFunction::RunAsync() { ...@@ -601,8 +615,7 @@ bool EasyUnlockPrivateGetRemoteDevicesFunction::RunAsync() {
&EasyUnlockPrivateGetRemoteDevicesFunction::OnPSKDerivedForDevice, &EasyUnlockPrivateGetRemoteDevicesFunction::OnPSKDerivedForDevice,
this, unlock_key)); this, unlock_key));
} }
return did_respond() ? AlreadyResponded() : RespondLater();
return true;
} }
std::string EasyUnlockPrivateGetRemoteDevicesFunction::GetUserPrivateKey() { std::string EasyUnlockPrivateGetRemoteDevicesFunction::GetUserPrivateKey() {
...@@ -656,10 +669,8 @@ void EasyUnlockPrivateGetRemoteDevicesFunction::OnPSKDerivedForDevice( ...@@ -656,10 +669,8 @@ void EasyUnlockPrivateGetRemoteDevicesFunction::OnPSKDerivedForDevice(
// If all PSKs are derived, then return from the API call. // If all PSKs are derived, then return from the API call.
PA_LOG(INFO) << "Derived PSK for " << b64_public_key << ": " PA_LOG(INFO) << "Derived PSK for " << b64_public_key << ": "
<< remote_devices_->GetSize() << "/" << expected_devices_count_; << remote_devices_->GetSize() << "/" << expected_devices_count_;
if (remote_devices_->GetSize() == expected_devices_count_) { if (remote_devices_->GetSize() == expected_devices_count_)
SetResult(std::move(remote_devices_)); Respond(OneArgument(std::move(remote_devices_)));
SendResponse(true);
}
} }
EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() { EasyUnlockPrivateGetUserInfoFunction::EasyUnlockPrivateGetUserInfoFunction() {
...@@ -759,9 +770,8 @@ EasyUnlockPrivateFindSetupConnectionFunction:: ...@@ -759,9 +770,8 @@ EasyUnlockPrivateFindSetupConnectionFunction::
void EasyUnlockPrivateFindSetupConnectionFunction:: void EasyUnlockPrivateFindSetupConnectionFunction::
OnConnectionFinderTimedOut() { OnConnectionFinderTimedOut() {
SetError("No connection found.");
connection_finder_.reset(); connection_finder_.reset();
SendResponse(false); Respond(Error("No connection found."));
} }
void EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound( void EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound(
...@@ -772,12 +782,13 @@ void EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound( ...@@ -772,12 +782,13 @@ void EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound(
int connection_id = int connection_id =
GetConnectionManager(browser_context()) GetConnectionManager(browser_context())
->AddConnection(extension(), std::move(connection), persistent); ->AddConnection(extension(), std::move(connection), persistent);
results_ = easy_unlock_private::FindSetupConnection::Results::Create( Respond(
connection_id, device_address); ArgumentList(easy_unlock_private::FindSetupConnection::Results::Create(
SendResponse(true); connection_id, device_address)));
} }
bool EasyUnlockPrivateFindSetupConnectionFunction::RunAsync() { ExtensionFunction::ResponseAction
EasyUnlockPrivateFindSetupConnectionFunction::Run() {
std::unique_ptr<easy_unlock_private::FindSetupConnection::Params> params = std::unique_ptr<easy_unlock_private::FindSetupConnection::Params> params =
easy_unlock_private::FindSetupConnection::Params::Create(*args_); easy_unlock_private::FindSetupConnection::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
...@@ -797,7 +808,8 @@ bool EasyUnlockPrivateFindSetupConnectionFunction::RunAsync() { ...@@ -797,7 +808,8 @@ bool EasyUnlockPrivateFindSetupConnectionFunction::RunAsync() {
OnConnectionFinderTimedOut, OnConnectionFinderTimedOut,
this)); this));
return true; // TODO(https://crbug.com/829182): Resolve this.
return did_respond() ? AlreadyResponded() : RespondLater();
} }
EasyUnlockPrivateSetupConnectionDisconnectFunction:: EasyUnlockPrivateSetupConnectionDisconnectFunction::
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device.h"
#include "extensions/browser/api/bluetooth/bluetooth_extension_function.h"
#include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h"
#include "extensions/browser/browser_context_keyed_api_factory.h" #include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function.h"
...@@ -74,8 +72,6 @@ class EasyUnlockPrivateAPI : public BrowserContextKeyedAPI { ...@@ -74,8 +72,6 @@ class EasyUnlockPrivateAPI : public BrowserContextKeyedAPI {
DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateAPI); DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateAPI);
}; };
// TODO(tbarzic): Replace SyncExtensionFunction/AsyncExtensionFunction overrides
// with UIThreadExtensionFunction throughout the file.
class EasyUnlockPrivateGetStringsFunction : public UIThreadExtensionFunction { class EasyUnlockPrivateGetStringsFunction : public UIThreadExtensionFunction {
public: public:
EasyUnlockPrivateGetStringsFunction(); EasyUnlockPrivateGetStringsFunction();
...@@ -94,14 +90,15 @@ class EasyUnlockPrivateGetStringsFunction : public UIThreadExtensionFunction { ...@@ -94,14 +90,15 @@ class EasyUnlockPrivateGetStringsFunction : public UIThreadExtensionFunction {
}; };
class EasyUnlockPrivatePerformECDHKeyAgreementFunction class EasyUnlockPrivatePerformECDHKeyAgreementFunction
: public AsyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
EasyUnlockPrivatePerformECDHKeyAgreementFunction(); EasyUnlockPrivatePerformECDHKeyAgreementFunction();
protected: protected:
~EasyUnlockPrivatePerformECDHKeyAgreementFunction() override; ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() override;
bool RunAsync() override; // ExtensionFunction:
ResponseAction Run() override;
private: private:
void OnData(const std::string& secret_key); void OnData(const std::string& secret_key);
...@@ -113,14 +110,15 @@ class EasyUnlockPrivatePerformECDHKeyAgreementFunction ...@@ -113,14 +110,15 @@ class EasyUnlockPrivatePerformECDHKeyAgreementFunction
}; };
class EasyUnlockPrivateGenerateEcP256KeyPairFunction class EasyUnlockPrivateGenerateEcP256KeyPairFunction
: public AsyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
EasyUnlockPrivateGenerateEcP256KeyPairFunction(); EasyUnlockPrivateGenerateEcP256KeyPairFunction();
protected: protected:
~EasyUnlockPrivateGenerateEcP256KeyPairFunction() override; ~EasyUnlockPrivateGenerateEcP256KeyPairFunction() override;
bool RunAsync() override; // ExtensionFunction:
ResponseAction Run() override;
private: private:
void OnData(const std::string& public_key, void OnData(const std::string& public_key,
...@@ -133,14 +131,15 @@ class EasyUnlockPrivateGenerateEcP256KeyPairFunction ...@@ -133,14 +131,15 @@ class EasyUnlockPrivateGenerateEcP256KeyPairFunction
}; };
class EasyUnlockPrivateCreateSecureMessageFunction class EasyUnlockPrivateCreateSecureMessageFunction
: public AsyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
EasyUnlockPrivateCreateSecureMessageFunction(); EasyUnlockPrivateCreateSecureMessageFunction();
protected: protected:
~EasyUnlockPrivateCreateSecureMessageFunction() override; ~EasyUnlockPrivateCreateSecureMessageFunction() override;
bool RunAsync() override; // ExtensionFunction:
ResponseAction Run() override;
private: private:
void OnData(const std::string& message); void OnData(const std::string& message);
...@@ -152,14 +151,15 @@ class EasyUnlockPrivateCreateSecureMessageFunction ...@@ -152,14 +151,15 @@ class EasyUnlockPrivateCreateSecureMessageFunction
}; };
class EasyUnlockPrivateUnwrapSecureMessageFunction class EasyUnlockPrivateUnwrapSecureMessageFunction
: public AsyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
EasyUnlockPrivateUnwrapSecureMessageFunction(); EasyUnlockPrivateUnwrapSecureMessageFunction();
protected: protected:
~EasyUnlockPrivateUnwrapSecureMessageFunction() override; ~EasyUnlockPrivateUnwrapSecureMessageFunction() override;
bool RunAsync() override; // ExtensionFunction:
ResponseAction Run() override;
private: private:
void OnData(const std::string& data); void OnData(const std::string& data);
...@@ -241,7 +241,7 @@ class EasyUnlockPrivateSetRemoteDevicesFunction ...@@ -241,7 +241,7 @@ class EasyUnlockPrivateSetRemoteDevicesFunction
}; };
class EasyUnlockPrivateGetRemoteDevicesFunction class EasyUnlockPrivateGetRemoteDevicesFunction
: public AsyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getRemoteDevices", DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getRemoteDevices",
EASYUNLOCKPRIVATE_GETREMOTEDEVICES) EASYUNLOCKPRIVATE_GETREMOTEDEVICES)
...@@ -259,8 +259,8 @@ class EasyUnlockPrivateGetRemoteDevicesFunction ...@@ -259,8 +259,8 @@ class EasyUnlockPrivateGetRemoteDevicesFunction
virtual std::vector<cryptauth::ExternalDeviceInfo> GetUnlockKeys(); virtual std::vector<cryptauth::ExternalDeviceInfo> GetUnlockKeys();
private: private:
// AsyncExtensionFunction: // ExtensionFunction:
bool RunAsync() override; ResponseAction Run() override;
// Callback when the PSK of a device is derived. // Callback when the PSK of a device is derived.
void OnPSKDerivedForDevice(const cryptauth::ExternalDeviceInfo& device, void OnPSKDerivedForDevice(const cryptauth::ExternalDeviceInfo& device,
...@@ -330,7 +330,7 @@ class EasyUnlockPrivateHideErrorBubbleFunction ...@@ -330,7 +330,7 @@ class EasyUnlockPrivateHideErrorBubbleFunction
}; };
class EasyUnlockPrivateFindSetupConnectionFunction class EasyUnlockPrivateFindSetupConnectionFunction
: public AsyncExtensionFunction { : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.findSetupConnection", DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.findSetupConnection",
EASYUNLOCKPRIVATE_FINDSETUPCONNECTION) EASYUNLOCKPRIVATE_FINDSETUPCONNECTION)
...@@ -339,8 +339,8 @@ class EasyUnlockPrivateFindSetupConnectionFunction ...@@ -339,8 +339,8 @@ class EasyUnlockPrivateFindSetupConnectionFunction
private: private:
~EasyUnlockPrivateFindSetupConnectionFunction() override; ~EasyUnlockPrivateFindSetupConnectionFunction() override;
// AsyncExtensionFunction: // ExtensionFunction:
bool RunAsync() override; ResponseAction Run() override;
// Called when the connection with the remote device advertising the setup // Called when the connection with the remote device advertising the setup
// service was found. // service was found.
......
...@@ -107,20 +107,20 @@ void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) { ...@@ -107,20 +107,20 @@ void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) {
namespace api { namespace api {
BluetoothGetAdapterStateFunction::~BluetoothGetAdapterStateFunction() {} BluetoothGetAdapterStateFunction::~BluetoothGetAdapterStateFunction() = default;
bool BluetoothGetAdapterStateFunction::DoWork( void BluetoothGetAdapterStateFunction::DoWork(
scoped_refptr<BluetoothAdapter> adapter) { scoped_refptr<BluetoothAdapter> adapter) {
bluetooth::AdapterState state; bluetooth::AdapterState state;
PopulateAdapterState(*adapter, &state); PopulateAdapterState(*adapter, &state);
results_ = bluetooth::GetAdapterState::Results::Create(state); Respond(ArgumentList(bluetooth::GetAdapterState::Results::Create(state)));
SendResponse(true);
return true;
} }
BluetoothGetDevicesFunction::~BluetoothGetDevicesFunction() {} BluetoothGetDevicesFunction::BluetoothGetDevicesFunction() = default;
bool BluetoothGetDevicesFunction::DoWork( BluetoothGetDevicesFunction::~BluetoothGetDevicesFunction() = default;
void BluetoothGetDevicesFunction::DoWork(
scoped_refptr<BluetoothAdapter> adapter) { scoped_refptr<BluetoothAdapter> adapter) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
...@@ -139,73 +139,64 @@ bool BluetoothGetDevicesFunction::DoWork( ...@@ -139,73 +139,64 @@ bool BluetoothGetDevicesFunction::DoWork(
device_list->Append(extension_device.ToValue()); device_list->Append(extension_device.ToValue());
} }
SetResult(std::move(device_list)); Respond(OneArgument(std::move(device_list)));
SendResponse(true);
return true;
} }
BluetoothGetDeviceFunction::~BluetoothGetDeviceFunction() {} BluetoothGetDeviceFunction::BluetoothGetDeviceFunction() = default;
BluetoothGetDeviceFunction::~BluetoothGetDeviceFunction() = default;
bool BluetoothGetDeviceFunction::CreateParams() {
params_ = GetDevice::Params::Create(*args_);
return params_ != nullptr;
}
bool BluetoothGetDeviceFunction::DoWork( void BluetoothGetDeviceFunction::DoWork(
scoped_refptr<BluetoothAdapter> adapter) { scoped_refptr<BluetoothAdapter> adapter) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::unique_ptr<GetDevice::Params> params(GetDevice::Params::Create(*args_)); BluetoothDevice* device = adapter->GetDevice(params_->device_address);
EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
BluetoothDevice* device = adapter->GetDevice(params->device_address);
if (device) { if (device) {
bluetooth::Device extension_device; bluetooth::Device extension_device;
bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device);
SetResult(extension_device.ToValue()); Respond(OneArgument(extension_device.ToValue()));
SendResponse(true);
} else { } else {
SetError(kInvalidDevice); Respond(Error(kInvalidDevice));
SendResponse(false);
} }
return false;
} }
void BluetoothStartDiscoveryFunction::OnSuccessCallback() { void BluetoothStartDiscoveryFunction::OnSuccessCallback() {
SendResponse(true); Respond(NoArguments());
} }
void BluetoothStartDiscoveryFunction::OnErrorCallback() { void BluetoothStartDiscoveryFunction::OnErrorCallback() {
SetError(kStartDiscoveryFailed); Respond(Error(kStartDiscoveryFailed));
SendResponse(false);
} }
bool BluetoothStartDiscoveryFunction::DoWork( void BluetoothStartDiscoveryFunction::DoWork(
scoped_refptr<BluetoothAdapter> adapter) { scoped_refptr<BluetoothAdapter> adapter) {
GetEventRouter(browser_context()) GetEventRouter(browser_context())
->StartDiscoverySession( ->StartDiscoverySession(
adapter.get(), GetExtensionId(), adapter.get(), GetExtensionId(),
base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this),
base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this));
return true;
} }
void BluetoothStopDiscoveryFunction::OnSuccessCallback() { void BluetoothStopDiscoveryFunction::OnSuccessCallback() {
SendResponse(true); Respond(NoArguments());
} }
void BluetoothStopDiscoveryFunction::OnErrorCallback() { void BluetoothStopDiscoveryFunction::OnErrorCallback() {
SetError(kStopDiscoveryFailed); Respond(Error(kStopDiscoveryFailed));
SendResponse(false);
} }
bool BluetoothStopDiscoveryFunction::DoWork( void BluetoothStopDiscoveryFunction::DoWork(
scoped_refptr<BluetoothAdapter> adapter) { scoped_refptr<BluetoothAdapter> adapter) {
GetEventRouter(browser_context()) GetEventRouter(browser_context())
->StopDiscoverySession( ->StopDiscoverySession(
adapter.get(), GetExtensionId(), adapter.get(), GetExtensionId(),
base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this),
base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this));
return true;
} }
} // namespace api } // namespace api
......
...@@ -75,29 +75,42 @@ class BluetoothGetAdapterStateFunction : public BluetoothExtensionFunction { ...@@ -75,29 +75,42 @@ class BluetoothGetAdapterStateFunction : public BluetoothExtensionFunction {
~BluetoothGetAdapterStateFunction() override; ~BluetoothGetAdapterStateFunction() override;
// BluetoothExtensionFunction: // BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
}; };
class BluetoothGetDevicesFunction : public BluetoothExtensionFunction { class BluetoothGetDevicesFunction : public BluetoothExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("bluetooth.getDevices", BLUETOOTH_GETDEVICES) DECLARE_EXTENSION_FUNCTION("bluetooth.getDevices", BLUETOOTH_GETDEVICES)
BluetoothGetDevicesFunction();
protected: protected:
~BluetoothGetDevicesFunction() override; ~BluetoothGetDevicesFunction() override;
// BluetoothExtensionFunction: // BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
private:
DISALLOW_COPY_AND_ASSIGN(BluetoothGetDevicesFunction);
}; };
class BluetoothGetDeviceFunction : public BluetoothExtensionFunction { class BluetoothGetDeviceFunction : public BluetoothExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("bluetooth.getDevice", BLUETOOTH_GETDEVICE) DECLARE_EXTENSION_FUNCTION("bluetooth.getDevice", BLUETOOTH_GETDEVICE)
BluetoothGetDeviceFunction();
// BluetoothExtensionFunction: // BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; bool CreateParams() override;
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
protected: protected:
~BluetoothGetDeviceFunction() override; ~BluetoothGetDeviceFunction() override;
private:
std::unique_ptr<extensions::api::bluetooth::GetDevice::Params> params_;
DISALLOW_COPY_AND_ASSIGN(BluetoothGetDeviceFunction);
}; };
class BluetoothStartDiscoveryFunction : public BluetoothExtensionFunction { class BluetoothStartDiscoveryFunction : public BluetoothExtensionFunction {
...@@ -109,7 +122,7 @@ class BluetoothStartDiscoveryFunction : public BluetoothExtensionFunction { ...@@ -109,7 +122,7 @@ class BluetoothStartDiscoveryFunction : public BluetoothExtensionFunction {
~BluetoothStartDiscoveryFunction() override {} ~BluetoothStartDiscoveryFunction() override {}
// BluetoothExtensionFunction: // BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
private: private:
void OnSuccessCallback(); void OnSuccessCallback();
...@@ -124,7 +137,7 @@ class BluetoothStopDiscoveryFunction : public BluetoothExtensionFunction { ...@@ -124,7 +137,7 @@ class BluetoothStopDiscoveryFunction : public BluetoothExtensionFunction {
~BluetoothStopDiscoveryFunction() override {} ~BluetoothStopDiscoveryFunction() override {}
// BluetoothExtensionFunction: // BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
private: private:
void OnSuccessCallback(); void OnSuccessCallback();
......
...@@ -49,16 +49,20 @@ BluetoothExtensionFunction::BluetoothExtensionFunction() { ...@@ -49,16 +49,20 @@ BluetoothExtensionFunction::BluetoothExtensionFunction() {
BluetoothExtensionFunction::~BluetoothExtensionFunction() { BluetoothExtensionFunction::~BluetoothExtensionFunction() {
} }
bool BluetoothExtensionFunction::RunAsync() { ExtensionFunction::ResponseAction BluetoothExtensionFunction::Run() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!IsBluetoothSupported(browser_context())) { EXTENSION_FUNCTION_VALIDATE(CreateParams());
SetError(kPlatformNotSupported);
return false; if (!IsBluetoothSupported(browser_context()))
} return RespondNow(Error(kPlatformNotSupported));
GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this), GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this),
browser_context()); browser_context());
return did_respond() ? AlreadyResponded() : RespondLater();
}
bool BluetoothExtensionFunction::CreateParams() {
return true; return true;
} }
......
...@@ -22,7 +22,7 @@ namespace api { ...@@ -22,7 +22,7 @@ namespace api {
// Base class for bluetooth extension functions. This class initializes // Base class for bluetooth extension functions. This class initializes
// bluetooth adapter and calls (on the UI thread) DoWork() implemented by // bluetooth adapter and calls (on the UI thread) DoWork() implemented by
// individual bluetooth extension functions. // individual bluetooth extension functions.
class BluetoothExtensionFunction : public AsyncExtensionFunction { class BluetoothExtensionFunction : public UIThreadExtensionFunction {
public: public:
BluetoothExtensionFunction(); BluetoothExtensionFunction();
...@@ -30,17 +30,19 @@ class BluetoothExtensionFunction : public AsyncExtensionFunction { ...@@ -30,17 +30,19 @@ class BluetoothExtensionFunction : public AsyncExtensionFunction {
~BluetoothExtensionFunction() override; ~BluetoothExtensionFunction() override;
// ExtensionFunction: // ExtensionFunction:
bool RunAsync() override; ResponseAction Run() override;
// Use instead of extension_id() so that this can be run from WebUI. // Use instead of extension_id() so that this can be run from WebUI.
std::string GetExtensionId(); std::string GetExtensionId();
virtual bool CreateParams();
private: private:
void RunOnAdapterReady(scoped_refptr<device::BluetoothAdapter> adapter); void RunOnAdapterReady(scoped_refptr<device::BluetoothAdapter> adapter);
// Implemented by individual bluetooth extension functions, called // Implemented by individual bluetooth extension functions, called
// automatically on the UI thread once |adapter| has been initialized. // automatically on the UI thread once |adapter| has been initialized.
virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) = 0; virtual void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) = 0;
DISALLOW_COPY_AND_ASSIGN(BluetoothExtensionFunction); DISALLOW_COPY_AND_ASSIGN(BluetoothExtensionFunction);
}; };
......
...@@ -48,6 +48,30 @@ class BluetoothPrivateAPI : public BrowserContextKeyedAPI, ...@@ -48,6 +48,30 @@ class BluetoothPrivateAPI : public BrowserContextKeyedAPI,
namespace api { namespace api {
namespace bluetooth_private {
namespace SetAdapterState {
struct Params;
} // namespace SetAdapterState
namespace SetPairingResponse {
struct Params;
} // namespace SetPairingResponse
namespace DisconnectAll {
struct Params;
} // namespace DisconnectAll
namespace ForgetDevice {
struct Params;
} // namespace ForgetDevice
namespace SetDiscoveryFilter {
struct Params;
} // namespace SetDiscoveryFilter
namespace Connect {
struct Params;
} // namespace Connect
namespace Pair {
struct Params;
} // namespace Pair
} // namespace bluetooth_private
class BluetoothPrivateSetAdapterStateFunction class BluetoothPrivateSetAdapterStateFunction
: public BluetoothExtensionFunction { : public BluetoothExtensionFunction {
public: public:
...@@ -65,7 +89,8 @@ class BluetoothPrivateSetAdapterStateFunction ...@@ -65,7 +89,8 @@ class BluetoothPrivateSetAdapterStateFunction
void SendError(); void SendError();
// BluetoothExtensionFunction overrides: // BluetoothExtensionFunction overrides:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; bool CreateParams() override;
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
// Set of expected adapter properties to be changed. // Set of expected adapter properties to be changed.
std::set<std::string> pending_properties_; std::set<std::string> pending_properties_;
...@@ -77,6 +102,8 @@ class BluetoothPrivateSetAdapterStateFunction ...@@ -77,6 +102,8 @@ class BluetoothPrivateSetAdapterStateFunction
// up state requests. // up state requests.
bool parsed_ = false; bool parsed_ = false;
std::unique_ptr<bluetooth_private::SetAdapterState::Params> params_;
DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateSetAdapterStateFunction); DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateSetAdapterStateFunction);
}; };
...@@ -87,10 +114,14 @@ class BluetoothPrivateSetPairingResponseFunction ...@@ -87,10 +114,14 @@ class BluetoothPrivateSetPairingResponseFunction
BLUETOOTHPRIVATE_SETPAIRINGRESPONSE) BLUETOOTHPRIVATE_SETPAIRINGRESPONSE)
BluetoothPrivateSetPairingResponseFunction(); BluetoothPrivateSetPairingResponseFunction();
// BluetoothExtensionFunction overrides: // BluetoothExtensionFunction overrides:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; bool CreateParams() override;
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
private: private:
~BluetoothPrivateSetPairingResponseFunction() override; ~BluetoothPrivateSetPairingResponseFunction() override;
std::unique_ptr<bluetooth_private::SetPairingResponse::Params> params_;
DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateSetPairingResponseFunction); DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateSetPairingResponseFunction);
}; };
...@@ -102,7 +133,8 @@ class BluetoothPrivateDisconnectAllFunction ...@@ -102,7 +133,8 @@ class BluetoothPrivateDisconnectAllFunction
BluetoothPrivateDisconnectAllFunction(); BluetoothPrivateDisconnectAllFunction();
// BluetoothExtensionFunction overrides: // BluetoothExtensionFunction overrides:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; bool CreateParams() override;
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
private: private:
~BluetoothPrivateDisconnectAllFunction() override; ~BluetoothPrivateDisconnectAllFunction() override;
...@@ -111,6 +143,8 @@ class BluetoothPrivateDisconnectAllFunction ...@@ -111,6 +143,8 @@ class BluetoothPrivateDisconnectAllFunction
void OnErrorCallback(scoped_refptr<device::BluetoothAdapter> adapter, void OnErrorCallback(scoped_refptr<device::BluetoothAdapter> adapter,
const std::string& device_address); const std::string& device_address);
std::unique_ptr<bluetooth_private::DisconnectAll::Params> params_;
DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateDisconnectAllFunction); DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateDisconnectAllFunction);
}; };
...@@ -121,7 +155,8 @@ class BluetoothPrivateForgetDeviceFunction : public BluetoothExtensionFunction { ...@@ -121,7 +155,8 @@ class BluetoothPrivateForgetDeviceFunction : public BluetoothExtensionFunction {
BluetoothPrivateForgetDeviceFunction(); BluetoothPrivateForgetDeviceFunction();
// BluetoothExtensionFunction overrides: // BluetoothExtensionFunction overrides:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; bool CreateParams() override;
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
private: private:
~BluetoothPrivateForgetDeviceFunction() override; ~BluetoothPrivateForgetDeviceFunction() override;
...@@ -130,6 +165,8 @@ class BluetoothPrivateForgetDeviceFunction : public BluetoothExtensionFunction { ...@@ -130,6 +165,8 @@ class BluetoothPrivateForgetDeviceFunction : public BluetoothExtensionFunction {
void OnErrorCallback(scoped_refptr<device::BluetoothAdapter> adapter, void OnErrorCallback(scoped_refptr<device::BluetoothAdapter> adapter,
const std::string& device_address); const std::string& device_address);
std::unique_ptr<bluetooth_private::ForgetDevice::Params> params_;
DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateForgetDeviceFunction); DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateForgetDeviceFunction);
}; };
...@@ -138,16 +175,22 @@ class BluetoothPrivateSetDiscoveryFilterFunction ...@@ -138,16 +175,22 @@ class BluetoothPrivateSetDiscoveryFilterFunction
public: public:
DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setDiscoveryFilter", DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setDiscoveryFilter",
BLUETOOTHPRIVATE_SETDISCOVERYFILTER) BLUETOOTHPRIVATE_SETDISCOVERYFILTER)
BluetoothPrivateSetDiscoveryFilterFunction();
protected: protected:
~BluetoothPrivateSetDiscoveryFilterFunction() override {} ~BluetoothPrivateSetDiscoveryFilterFunction() override;
// BluetoothExtensionFunction: // BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; bool CreateParams() override;
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
private: private:
void OnSuccessCallback(); void OnSuccessCallback();
void OnErrorCallback(); void OnErrorCallback();
std::unique_ptr<bluetooth_private::SetDiscoveryFilter::Params> params_;
DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateSetDiscoveryFilterFunction);
}; };
class BluetoothPrivateConnectFunction : public BluetoothExtensionFunction { class BluetoothPrivateConnectFunction : public BluetoothExtensionFunction {
...@@ -157,7 +200,8 @@ class BluetoothPrivateConnectFunction : public BluetoothExtensionFunction { ...@@ -157,7 +200,8 @@ class BluetoothPrivateConnectFunction : public BluetoothExtensionFunction {
BluetoothPrivateConnectFunction(); BluetoothPrivateConnectFunction();
// BluetoothExtensionFunction: // BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; bool CreateParams() override;
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
private: private:
~BluetoothPrivateConnectFunction() override; ~BluetoothPrivateConnectFunction() override;
...@@ -165,6 +209,8 @@ class BluetoothPrivateConnectFunction : public BluetoothExtensionFunction { ...@@ -165,6 +209,8 @@ class BluetoothPrivateConnectFunction : public BluetoothExtensionFunction {
void OnSuccessCallback(); void OnSuccessCallback();
void OnErrorCallback(device::BluetoothDevice::ConnectErrorCode error); void OnErrorCallback(device::BluetoothDevice::ConnectErrorCode error);
std::unique_ptr<bluetooth_private::Connect::Params> params_;
DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateConnectFunction); DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateConnectFunction);
}; };
...@@ -174,7 +220,8 @@ class BluetoothPrivatePairFunction : public BluetoothExtensionFunction { ...@@ -174,7 +220,8 @@ class BluetoothPrivatePairFunction : public BluetoothExtensionFunction {
BluetoothPrivatePairFunction(); BluetoothPrivatePairFunction();
// BluetoothExtensionFunction: // BluetoothExtensionFunction:
bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override; bool CreateParams() override;
void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
private: private:
~BluetoothPrivatePairFunction() override; ~BluetoothPrivatePairFunction() override;
...@@ -182,6 +229,8 @@ class BluetoothPrivatePairFunction : public BluetoothExtensionFunction { ...@@ -182,6 +229,8 @@ class BluetoothPrivatePairFunction : public BluetoothExtensionFunction {
void OnSuccessCallback(); void OnSuccessCallback();
void OnErrorCallback(device::BluetoothDevice::ConnectErrorCode error); void OnErrorCallback(device::BluetoothDevice::ConnectErrorCode error);
std::unique_ptr<bluetooth_private::Pair::Params> params_;
DISALLOW_COPY_AND_ASSIGN(BluetoothPrivatePairFunction); DISALLOW_COPY_AND_ASSIGN(BluetoothPrivatePairFunction);
}; };
......
...@@ -39,23 +39,15 @@ class BluetoothSocketEventDispatcher; ...@@ -39,23 +39,15 @@ class BluetoothSocketEventDispatcher;
// thread while providing methods to manage resources of that class. This // thread while providing methods to manage resources of that class. This
// follows the pattern of AsyncApiFunction, but does not derive from it, // follows the pattern of AsyncApiFunction, but does not derive from it,
// because BluetoothApiSocket methods must be called on the UI Thread. // because BluetoothApiSocket methods must be called on the UI Thread.
class BluetoothSocketAsyncApiFunction : public AsyncExtensionFunction { class BluetoothSocketAsyncApiFunction : public UIThreadExtensionFunction {
public: public:
BluetoothSocketAsyncApiFunction(); BluetoothSocketAsyncApiFunction();
protected: protected:
~BluetoothSocketAsyncApiFunction() override; ~BluetoothSocketAsyncApiFunction() override;
// AsyncExtensionFunction: // UIThreadExtensionFunction:
bool RunAsync() override; bool PreRunValidation(std::string* error) override;
bool PrePrepare();
bool Respond();
void AsyncWorkCompleted();
virtual bool Prepare() = 0;
virtual void Work();
virtual void AsyncWorkStart();
content::BrowserThread::ID work_thread_id() const; content::BrowserThread::ID work_thread_id() const;
...@@ -77,9 +69,7 @@ class BluetoothSocketCreateFunction : public BluetoothSocketAsyncApiFunction { ...@@ -77,9 +69,7 @@ class BluetoothSocketCreateFunction : public BluetoothSocketAsyncApiFunction {
protected: protected:
~BluetoothSocketCreateFunction() override; ~BluetoothSocketCreateFunction() override;
// BluetoothSocketAsyncApiFunction: ResponseAction Run() override;
bool Prepare() override;
void Work() override;
private: private:
std::unique_ptr<bluetooth_socket::Create::Params> params_; std::unique_ptr<bluetooth_socket::Create::Params> params_;
...@@ -94,9 +84,8 @@ class BluetoothSocketUpdateFunction : public BluetoothSocketAsyncApiFunction { ...@@ -94,9 +84,8 @@ class BluetoothSocketUpdateFunction : public BluetoothSocketAsyncApiFunction {
protected: protected:
~BluetoothSocketUpdateFunction() override; ~BluetoothSocketUpdateFunction() override;
// BluetoothSocketAsyncApiFunction: // UIThreadExtensionFunction:
bool Prepare() override; ResponseAction Run() override;
void Work() override;
private: private:
std::unique_ptr<bluetooth_socket::Update::Params> params_; std::unique_ptr<bluetooth_socket::Update::Params> params_;
...@@ -113,13 +102,11 @@ class BluetoothSocketSetPausedFunction ...@@ -113,13 +102,11 @@ class BluetoothSocketSetPausedFunction
protected: protected:
~BluetoothSocketSetPausedFunction() override; ~BluetoothSocketSetPausedFunction() override;
// BluetoothSocketAsyncApiFunction: // UIThreadExtensionFunction:
bool Prepare() override; ResponseAction Run() override;
void Work() override;
private: private:
std::unique_ptr<bluetooth_socket::SetPaused::Params> params_; std::unique_ptr<bluetooth_socket::SetPaused::Params> params_;
BluetoothSocketEventDispatcher* socket_event_dispatcher_;
}; };
class BluetoothSocketListenFunction : public BluetoothSocketAsyncApiFunction { class BluetoothSocketListenFunction : public BluetoothSocketAsyncApiFunction {
...@@ -134,14 +121,14 @@ class BluetoothSocketListenFunction : public BluetoothSocketAsyncApiFunction { ...@@ -134,14 +121,14 @@ class BluetoothSocketListenFunction : public BluetoothSocketAsyncApiFunction {
const device::BluetoothAdapter::CreateServiceCallback& callback, const device::BluetoothAdapter::CreateServiceCallback& callback,
const device::BluetoothAdapter::CreateServiceErrorCallback& const device::BluetoothAdapter::CreateServiceErrorCallback&
error_callback) = 0; error_callback) = 0;
virtual void CreateResults() = 0; virtual std::unique_ptr<base::ListValue> CreateResults() = 0;
virtual int socket_id() const = 0; virtual int socket_id() const = 0;
virtual const std::string& uuid() const = 0; virtual const std::string& uuid() const = 0;
// BluetoothSocketAsyncApiFunction: // UIThreadExtensionFunction:
bool Prepare() override; ResponseAction Run() override;
void AsyncWorkStart() override; bool PreRunValidation(std::string* error) override;
protected: protected:
~BluetoothSocketListenFunction() override; ~BluetoothSocketListenFunction() override;
...@@ -150,7 +137,7 @@ class BluetoothSocketListenFunction : public BluetoothSocketAsyncApiFunction { ...@@ -150,7 +137,7 @@ class BluetoothSocketListenFunction : public BluetoothSocketAsyncApiFunction {
virtual void OnCreateService(scoped_refptr<device::BluetoothSocket> socket); virtual void OnCreateService(scoped_refptr<device::BluetoothSocket> socket);
virtual void OnCreateServiceError(const std::string& message); virtual void OnCreateServiceError(const std::string& message);
BluetoothSocketEventDispatcher* socket_event_dispatcher_; BluetoothSocketEventDispatcher* socket_event_dispatcher_ = nullptr;
}; };
class BluetoothSocketListenUsingRfcommFunction class BluetoothSocketListenUsingRfcommFunction
...@@ -173,7 +160,7 @@ class BluetoothSocketListenUsingRfcommFunction ...@@ -173,7 +160,7 @@ class BluetoothSocketListenUsingRfcommFunction
const device::BluetoothAdapter::CreateServiceCallback& callback, const device::BluetoothAdapter::CreateServiceCallback& callback,
const device::BluetoothAdapter::CreateServiceErrorCallback& const device::BluetoothAdapter::CreateServiceErrorCallback&
error_callback) override; error_callback) override;
void CreateResults() override; std::unique_ptr<base::ListValue> CreateResults() override;
protected: protected:
~BluetoothSocketListenUsingRfcommFunction() override; ~BluetoothSocketListenUsingRfcommFunction() override;
...@@ -202,7 +189,7 @@ class BluetoothSocketListenUsingL2capFunction ...@@ -202,7 +189,7 @@ class BluetoothSocketListenUsingL2capFunction
const device::BluetoothAdapter::CreateServiceCallback& callback, const device::BluetoothAdapter::CreateServiceCallback& callback,
const device::BluetoothAdapter::CreateServiceErrorCallback& const device::BluetoothAdapter::CreateServiceErrorCallback&
error_callback) override; error_callback) override;
void CreateResults() override; std::unique_ptr<base::ListValue> CreateResults() override;
protected: protected:
~BluetoothSocketListenUsingL2capFunction() override; ~BluetoothSocketListenUsingL2capFunction() override;
...@@ -219,9 +206,9 @@ class BluetoothSocketAbstractConnectFunction : ...@@ -219,9 +206,9 @@ class BluetoothSocketAbstractConnectFunction :
protected: protected:
~BluetoothSocketAbstractConnectFunction() override; ~BluetoothSocketAbstractConnectFunction() override;
// BluetoothSocketAsyncApiFunction: // UIThreadExtensionFunction:
bool Prepare() override; bool PreRunValidation(std::string* error) override;
void AsyncWorkStart() override; ResponseAction Run() override;
// Subclasses should implement this method to connect to the service // Subclasses should implement this method to connect to the service
// registered with |uuid| on the |device|. // registered with |uuid| on the |device|.
...@@ -235,7 +222,7 @@ class BluetoothSocketAbstractConnectFunction : ...@@ -235,7 +222,7 @@ class BluetoothSocketAbstractConnectFunction :
virtual void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); virtual void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter);
std::unique_ptr<bluetooth_socket::Connect::Params> params_; std::unique_ptr<bluetooth_socket::Connect::Params> params_;
BluetoothSocketEventDispatcher* socket_event_dispatcher_; BluetoothSocketEventDispatcher* socket_event_dispatcher_ = nullptr;
}; };
class BluetoothSocketConnectFunction : class BluetoothSocketConnectFunction :
...@@ -265,9 +252,8 @@ class BluetoothSocketDisconnectFunction ...@@ -265,9 +252,8 @@ class BluetoothSocketDisconnectFunction
protected: protected:
~BluetoothSocketDisconnectFunction() override; ~BluetoothSocketDisconnectFunction() override;
// BluetoothSocketAsyncApiFunction: // UIThreadExtensionFunction:
bool Prepare() override; ResponseAction Run() override;
void AsyncWorkStart() override;
private: private:
virtual void OnSuccess(); virtual void OnSuccess();
...@@ -284,9 +270,8 @@ class BluetoothSocketCloseFunction : public BluetoothSocketAsyncApiFunction { ...@@ -284,9 +270,8 @@ class BluetoothSocketCloseFunction : public BluetoothSocketAsyncApiFunction {
protected: protected:
~BluetoothSocketCloseFunction() override; ~BluetoothSocketCloseFunction() override;
// BluetoothSocketAsyncApiFunction: // UIThreadExtensionFunction:
bool Prepare() override; ResponseAction Run() override;
void Work() override;
private: private:
std::unique_ptr<bluetooth_socket::Close::Params> params_; std::unique_ptr<bluetooth_socket::Close::Params> params_;
...@@ -301,9 +286,8 @@ class BluetoothSocketSendFunction : public BluetoothSocketAsyncApiFunction { ...@@ -301,9 +286,8 @@ class BluetoothSocketSendFunction : public BluetoothSocketAsyncApiFunction {
protected: protected:
~BluetoothSocketSendFunction() override; ~BluetoothSocketSendFunction() override;
// BluetoothSocketAsyncApiFunction: // UIThreadExtensionFunction:
bool Prepare() override; ResponseAction Run() override;
void AsyncWorkStart() override;
private: private:
void OnSuccess(int bytes_sent); void OnSuccess(int bytes_sent);
...@@ -325,9 +309,8 @@ class BluetoothSocketGetInfoFunction : public BluetoothSocketAsyncApiFunction { ...@@ -325,9 +309,8 @@ class BluetoothSocketGetInfoFunction : public BluetoothSocketAsyncApiFunction {
protected: protected:
~BluetoothSocketGetInfoFunction() override; ~BluetoothSocketGetInfoFunction() override;
// BluetoothSocketAsyncApiFunction: // UIThreadExtensionFunction:
bool Prepare() override; ResponseAction Run() override;
void Work() override;
private: private:
std::unique_ptr<bluetooth_socket::GetInfo::Params> params_; std::unique_ptr<bluetooth_socket::GetInfo::Params> params_;
...@@ -344,9 +327,8 @@ class BluetoothSocketGetSocketsFunction ...@@ -344,9 +327,8 @@ class BluetoothSocketGetSocketsFunction
protected: protected:
~BluetoothSocketGetSocketsFunction() override; ~BluetoothSocketGetSocketsFunction() override;
// BluetoothSocketAsyncApiFunction: // UIThreadExtensionFunction:
bool Prepare() override; ResponseAction Run() override;
void Work() override;
}; };
} // namespace api } // namespace api
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment