Index: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
index c983544b2bf73944862d081bf0809efc69eb54c8..bf12140535085489176ecf4723c2e94d0dd0529b 100644 |
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
@@ -43,18 +43,6 @@ extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) { |
return extensions::BluetoothAPI::Get(profile)->bluetooth_event_router(); |
} |
-const BluetoothAdapter* GetAdapter(Profile* profile) { |
- return GetEventRouter(profile)->adapter(); |
-} |
- |
-BluetoothAdapter* GetMutableAdapter(Profile* profile) { |
- return GetEventRouter(profile)->GetMutableAdapter(); |
-} |
- |
-bool IsBluetoothSupported(Profile* profile) { |
- return GetAdapter(profile) != NULL; |
-} |
- |
} // namespace |
namespace { |
@@ -121,16 +109,12 @@ void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) { |
namespace api { |
-bool BluetoothGetAdapterStateFunction::RunImpl() { |
- if (!IsBluetoothSupported(profile())) { |
- SetError(kPlatformNotSupported); |
- return false; |
- } |
- |
+void BluetoothGetAdapterStateFunction::DoWork( |
+ scoped_refptr<BluetoothAdapter> adapter) { |
bluetooth::AdapterState state; |
- PopulateAdapterState(*GetAdapter(profile()), &state); |
+ PopulateAdapterState(*adapter, &state); |
SetResult(state.ToValue().release()); |
- return true; |
+ SendResponse(true); |
} |
BluetoothGetDevicesFunction::BluetoothGetDevicesFunction() |
@@ -175,16 +159,16 @@ void BluetoothGetDevicesFunction::FinishDeviceSearch() { |
SendResponse(true); |
} |
-bool BluetoothGetDevicesFunction::RunImpl() { |
- if (!IsBluetoothSupported(profile())) { |
- SetError(kPlatformNotSupported); |
- return false; |
- } |
- |
+void BluetoothGetDevicesFunction::DoWork( |
+ scoped_refptr<BluetoothAdapter> adapter) { |
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
scoped_ptr<GetDevices::Params> params(GetDevices::Params::Create(*args_)); |
- EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
+ if (!params) { |
+ bad_message_ = true; |
+ SendResponse(false); |
+ return; |
+ } |
asargent_no_longer_on_chrome
2013/01/04 21:54:22
Instead of manually putting in the code to essenti
youngki
2013/01/04 23:44:44
Done.
|
const bluetooth::GetDevicesOptions& options = params->options; |
std::string uuid; |
@@ -192,14 +176,14 @@ bool BluetoothGetDevicesFunction::RunImpl() { |
uuid = device::bluetooth_utils::CanonicalUuid(*options.uuid.get()); |
if (uuid.empty()) { |
SetError(kInvalidUuid); |
- return false; |
+ SendResponse(false); |
+ return; |
} |
} |
CHECK_EQ(0, callbacks_pending_); |
- BluetoothAdapter::DeviceList devices = |
- GetMutableAdapter(profile())->GetDevices(); |
+ BluetoothAdapter::DeviceList devices = adapter->GetDevices(); |
for (BluetoothAdapter::DeviceList::iterator i = devices.begin(); |
i != devices.end(); ++i) { |
BluetoothDevice* device = *i; |
@@ -227,8 +211,6 @@ bool BluetoothGetDevicesFunction::RunImpl() { |
// SendResponse happens. |
if (callbacks_pending_ == -1) |
FinishDeviceSearch(); |
- |
- return true; |
} |
void BluetoothGetServicesFunction::GetServiceRecordsCallback( |
@@ -252,21 +234,21 @@ void BluetoothGetServicesFunction::OnErrorCallback() { |
SendResponse(false); |
} |
-bool BluetoothGetServicesFunction::RunImpl() { |
- if (!IsBluetoothSupported(profile())) { |
- SetError(kPlatformNotSupported); |
- return false; |
- } |
- |
+void BluetoothGetServicesFunction::DoWork( |
+ scoped_refptr<BluetoothAdapter> adapter) { |
scoped_ptr<GetServices::Params> params(GetServices::Params::Create(*args_)); |
- EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
+ if (!params) { |
+ bad_message_ = true; |
+ SendResponse(false); |
+ return; |
+ } |
const bluetooth::GetServicesOptions& options = params->options; |
- BluetoothDevice* device = |
- GetMutableAdapter(profile())->GetDevice(options.device_address); |
+ BluetoothDevice* device = adapter->GetDevice(options.device_address); |
if (!device) { |
SetError(kInvalidDevice); |
- return false; |
+ SendResponse(false); |
+ return; |
} |
ListValue* services = new ListValue; |
@@ -278,8 +260,6 @@ bool BluetoothGetServicesFunction::RunImpl() { |
services), |
base::Bind(&BluetoothGetServicesFunction::OnErrorCallback, |
this)); |
- |
- return true; |
} |
void BluetoothConnectFunction::ConnectToServiceCallback( |
@@ -301,35 +281,36 @@ void BluetoothConnectFunction::ConnectToServiceCallback( |
} |
} |
-bool BluetoothConnectFunction::RunImpl() { |
- if (!IsBluetoothSupported(profile())) { |
- SetError(kPlatformNotSupported); |
- return false; |
- } |
- |
+void BluetoothConnectFunction::DoWork(scoped_refptr<BluetoothAdapter> adapter) { |
scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); |
- EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
+ if (!params) { |
+ bad_message_ = true; |
+ SendResponse(false); |
+ return; |
+ } |
const bluetooth::ConnectOptions& options = params->options; |
BluetoothDevicePermission::CheckParam param(options.device_address); |
if (!GetExtension()->CheckAPIPermissionWithParam( |
APIPermission::kBluetoothDevice, ¶m)) { |
SetError(kDevicePermissionDenied); |
- return false; |
+ SendResponse(false); |
+ return; |
} |
std::string uuid = device::bluetooth_utils::CanonicalUuid( |
options.service_uuid); |
if (uuid.empty()) { |
SetError(kInvalidUuid); |
- return false; |
+ SendResponse(false); |
+ return; |
} |
- BluetoothDevice* device = |
- GetMutableAdapter(profile())->GetDevice(options.device_address); |
+ BluetoothDevice* device = adapter->GetDevice(options.device_address); |
if (!device) { |
SetError(kInvalidDevice); |
- return false; |
+ SendResponse(false); |
+ return; |
} |
device->ConnectToService(uuid, |
@@ -337,7 +318,6 @@ bool BluetoothConnectFunction::RunImpl() { |
this, |
device, |
uuid)); |
- return true; |
} |
bool BluetoothDisconnectFunction::RunImpl() { |
@@ -474,42 +454,49 @@ void BluetoothSetOutOfBandPairingDataFunction::OnErrorCallback() { |
SendResponse(false); |
} |
-bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() { |
- if (!IsBluetoothSupported(profile())) { |
- SetError(kPlatformNotSupported); |
- return false; |
- } |
- |
+void BluetoothSetOutOfBandPairingDataFunction::DoWork( |
+ scoped_refptr<BluetoothAdapter> adapter) { |
// TODO(bryeung): update to new-style parameter passing when ArrayBuffer |
// support is added |
DictionaryValue* options; |
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); |
std::string address; |
- EXTENSION_FUNCTION_VALIDATE(options->GetString("deviceAddress", &address)); |
+ if (!args_->GetDictionary(0, &options) || |
+ !options->GetString("deviceAddress", &address)) { |
+ bad_message_ = true; |
+ SendResponse(false); |
+ return; |
+ } |
- BluetoothDevice* device = GetMutableAdapter(profile())->GetDevice(address); |
+ BluetoothDevice* device = adapter->GetDevice(address); |
if (!device) { |
SetError(kInvalidDevice); |
- return false; |
+ SendResponse(false); |
+ return; |
} |
if (options->HasKey("data")) { |
DictionaryValue* data_in; |
- EXTENSION_FUNCTION_VALIDATE(options->GetDictionary("data", &data_in)); |
- |
device::BluetoothOutOfBandPairingData data_out; |
- |
base::BinaryValue* tmp_data; |
- EXTENSION_FUNCTION_VALIDATE(data_in->GetBinary("hash", &tmp_data)); |
- EXTENSION_FUNCTION_VALIDATE( |
- tmp_data->GetSize() == device::kBluetoothOutOfBandPairingDataSize); |
+ |
+ if (!options->GetDictionary("data", &data_in) || |
+ !data_in->GetBinary("hash", &tmp_data) || |
+ tmp_data->GetSize() != device::kBluetoothOutOfBandPairingDataSize) { |
+ bad_message_ = true; |
+ SendResponse(false); |
+ return; |
+ } |
+ |
memcpy(data_out.hash, |
reinterpret_cast<uint8_t*>(tmp_data->GetBuffer()), |
device::kBluetoothOutOfBandPairingDataSize); |
- EXTENSION_FUNCTION_VALIDATE(data_in->GetBinary("randomizer", &tmp_data)); |
- EXTENSION_FUNCTION_VALIDATE( |
- tmp_data->GetSize() == device::kBluetoothOutOfBandPairingDataSize); |
+ if (!data_in->GetBinary("randomizer", &tmp_data) || |
+ tmp_data->GetSize() != device::kBluetoothOutOfBandPairingDataSize) { |
+ bad_message_ = true; |
+ SendResponse(false); |
+ return; |
+ } |
memcpy(data_out.randomizer, |
reinterpret_cast<uint8_t*>(tmp_data->GetBuffer()), |
device::kBluetoothOutOfBandPairingDataSize); |
@@ -527,8 +514,6 @@ bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() { |
base::Bind(&BluetoothSetOutOfBandPairingDataFunction::OnErrorCallback, |
this)); |
} |
- |
- return true; |
} |
void BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback( |
@@ -556,18 +541,13 @@ void BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback() { |
SendResponse(false); |
} |
-bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() { |
- if (!IsBluetoothSupported(profile())) { |
- SetError(kPlatformNotSupported); |
- return false; |
- } |
- |
- GetMutableAdapter(profile())->ReadLocalOutOfBandPairingData( |
+void BluetoothGetLocalOutOfBandPairingDataFunction::DoWork( |
+ scoped_refptr<BluetoothAdapter> adapter) { |
+ adapter->ReadLocalOutOfBandPairingData( |
base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback, |
this), |
base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback, |
this)); |
- return true; |
} |
void BluetoothStartDiscoveryFunction::OnSuccessCallback() { |
@@ -580,24 +560,19 @@ void BluetoothStartDiscoveryFunction::OnErrorCallback() { |
SendResponse(false); |
} |
-bool BluetoothStartDiscoveryFunction::RunImpl() { |
- if (!IsBluetoothSupported(profile())) { |
- SetError(kPlatformNotSupported); |
- return false; |
- } |
- |
+void BluetoothStartDiscoveryFunction::DoWork( |
+ scoped_refptr<BluetoothAdapter> adapter) { |
GetEventRouter(profile())->SetSendDiscoveryEvents(true); |
// If the adapter is already discovering, there is nothing else to do. |
- if (GetAdapter(profile())->IsDiscovering()) { |
+ if (adapter->IsDiscovering()) { |
SendResponse(true); |
- return true; |
+ return; |
} |
- GetMutableAdapter(profile())->SetDiscovering(true, |
+ adapter->SetDiscovering(true, |
base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), |
base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); |
- return true; |
} |
void BluetoothStopDiscoveryFunction::OnSuccessCallback() { |
@@ -609,19 +584,14 @@ void BluetoothStopDiscoveryFunction::OnErrorCallback() { |
SendResponse(false); |
} |
-bool BluetoothStopDiscoveryFunction::RunImpl() { |
- if (!IsBluetoothSupported(profile())) { |
- SetError(kPlatformNotSupported); |
- return false; |
- } |
- |
+void BluetoothStopDiscoveryFunction::DoWork( |
+ scoped_refptr<BluetoothAdapter> adapter) { |
GetEventRouter(profile())->SetSendDiscoveryEvents(false); |
if (GetEventRouter(profile())->IsResponsibleForDiscovery()) { |
- GetMutableAdapter(profile())->SetDiscovering(false, |
+ adapter->SetDiscovering(false, |
base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
} |
- return true; |
} |
} // namespace api |