Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Unified Diff: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc

Issue 11075006: Moved bluetooth adapter files to device/bluetooth/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added IsBluetoothSupported() in bluetooth_api.cc Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 f36470b30bb7c05585aaacf61f4a6e68530c48cb..e142c07feaf3daba9dea8291a275a6d7840f89f5 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
@@ -10,44 +10,48 @@
#include <string>
+#include "base/memory/ref_counted.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h"
+#include "chrome/browser/extensions/bluetooth_event_router.h"
#include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/experimental_bluetooth.h"
#include "content/public/browser/browser_thread.h"
+#include "device/bluetooth/bluetooth_adapter.h"
+#include "device/bluetooth/bluetooth_device.h"
+#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
+#include "device/bluetooth/bluetooth_service_record.h"
+#include "device/bluetooth/bluetooth_socket.h"
+#include "device/bluetooth/bluetooth_utils.h"
#if defined(OS_CHROMEOS)
-#include "base/memory/ref_counted.h"
#include "base/safe_strerror_posix.h"
-#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
-#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
-#include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h"
-#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h"
-#include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h"
-#include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
-#include "chromeos/dbus/bluetooth_out_of_band_client.h"
-#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h"
+#endif
+
+using bluetooth::BluetoothAdapter;
+using bluetooth::BluetoothDevice;
namespace {
-chromeos::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) {
+extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) {
return profile->GetExtensionService()->bluetooth_event_router();
}
-const chromeos::BluetoothAdapter& GetAdapter(Profile* profile) {
+const BluetoothAdapter* GetAdapter(Profile* profile) {
return GetEventRouter(profile)->adapter();
}
-chromeos::BluetoothAdapter* GetMutableAdapter(Profile* profile) {
- chromeos::BluetoothAdapter* adapter =
- GetEventRouter(profile)->GetMutableAdapter();
- CHECK(adapter);
+BluetoothAdapter* GetMutableAdapter(Profile* profile) {
+ BluetoothAdapter* adapter = GetEventRouter(profile)->GetMutableAdapter();
return adapter;
}
+bool IsBluetoothSupported(Profile* profile) {
+ return GetAdapter(profile) != NULL;
+}
+
} // namespace
-#endif
namespace {
@@ -77,25 +81,35 @@ namespace Write = extensions::api::experimental_bluetooth::Write;
namespace extensions {
namespace api {
-#if defined(OS_CHROMEOS)
-
bool BluetoothIsAvailableFunction::RunImpl() {
- SetResult(Value::CreateBooleanValue(GetAdapter(profile()).IsPresent()));
+ if (!IsBluetoothSupported(profile()))
bryeung 2012/10/11 15:15:39 These should be calling SetError as well, with an
youngki 2012/10/11 16:21:18 Done.
+ return false;
+
+ SetResult(Value::CreateBooleanValue(GetAdapter(profile())->IsPresent()));
return true;
}
bool BluetoothIsPoweredFunction::RunImpl() {
- SetResult(Value::CreateBooleanValue(GetAdapter(profile()).IsPowered()));
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
+ SetResult(Value::CreateBooleanValue(GetAdapter(profile())->IsPowered()));
return true;
}
bool BluetoothGetAddressFunction::RunImpl() {
- SetResult(Value::CreateStringValue(GetAdapter(profile()).address()));
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
+ SetResult(Value::CreateStringValue(GetAdapter(profile())->address()));
return true;
}
bool BluetoothGetNameFunction::RunImpl() {
- SetResult(Value::CreateStringValue(GetAdapter(profile()).name()));
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
+ SetResult(Value::CreateStringValue(GetAdapter(profile())->name()));
return true;
}
@@ -103,7 +117,7 @@ BluetoothGetDevicesFunction::BluetoothGetDevicesFunction()
: callbacks_pending_(0) {}
void BluetoothGetDevicesFunction::DispatchDeviceSearchResult(
- const chromeos::BluetoothDevice& device) {
+ const BluetoothDevice& device) {
experimental_bluetooth::Device extension_device;
experimental_bluetooth::BluetoothDeviceToApiDevice(device, &extension_device);
GetEventRouter(profile())->DispatchDeviceEvent(
@@ -112,8 +126,7 @@ void BluetoothGetDevicesFunction::DispatchDeviceSearchResult(
}
void BluetoothGetDevicesFunction::ProvidesServiceCallback(
- const chromeos::BluetoothDevice* device,
- bool providesService) {
+ const BluetoothDevice* device, bool providesService) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
CHECK(device);
@@ -126,6 +139,9 @@ void BluetoothGetDevicesFunction::ProvidesServiceCallback(
}
bool BluetoothGetDevicesFunction::RunImpl() {
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
scoped_ptr<GetDevices::Params> params(GetDevices::Params::Create(*args_));
@@ -134,7 +150,7 @@ bool BluetoothGetDevicesFunction::RunImpl() {
std::string uuid;
if (options.uuid.get() != NULL) {
- uuid = chromeos::bluetooth_utils::CanonicalUuid(*options.uuid.get());
+ uuid = bluetooth::utils::CanonicalUuid(*options.uuid.get());
if (uuid.empty()) {
SetError(kInvalidUuid);
return false;
@@ -143,11 +159,11 @@ bool BluetoothGetDevicesFunction::RunImpl() {
CHECK_EQ(0, callbacks_pending_);
- chromeos::BluetoothAdapter::DeviceList devices =
+ BluetoothAdapter::DeviceList devices =
GetMutableAdapter(profile())->GetDevices();
- for (chromeos::BluetoothAdapter::DeviceList::iterator i = devices.begin();
+ for (BluetoothAdapter::DeviceList::iterator i = devices.begin();
i != devices.end(); ++i) {
- chromeos::BluetoothDevice* device = *i;
+ BluetoothDevice* device = *i;
CHECK(device);
if (!uuid.empty() && !(device->ProvidesServiceWithUUID(uuid)))
@@ -178,10 +194,10 @@ bool BluetoothGetDevicesFunction::RunImpl() {
void BluetoothGetServicesFunction::GetServiceRecordsCallback(
base::ListValue* services,
- const chromeos::BluetoothDevice::ServiceRecordList& records) {
- for (chromeos::BluetoothDevice::ServiceRecordList::const_iterator i =
- records.begin(); i != records.end(); ++i) {
- const chromeos::BluetoothServiceRecord& record = **i;
+ const BluetoothDevice::ServiceRecordList& records) {
+ for (BluetoothDevice::ServiceRecordList::const_iterator i = records.begin();
+ i != records.end(); ++i) {
+ const bluetooth::BluetoothServiceRecord& record = **i;
experimental_bluetooth::ServiceRecord api_record;
api_record.name = record.name();
if (!record.uuid().empty())
@@ -198,11 +214,14 @@ void BluetoothGetServicesFunction::OnErrorCallback() {
}
bool BluetoothGetServicesFunction::RunImpl() {
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
scoped_ptr<GetServices::Params> params(GetServices::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
const experimental_bluetooth::GetServicesOptions& options = params->options;
- chromeos::BluetoothDevice* device =
+ BluetoothDevice* device =
GetMutableAdapter(profile())->GetDevice(options.device_address);
if (!device) {
SetError(kInvalidDevice);
@@ -223,9 +242,9 @@ bool BluetoothGetServicesFunction::RunImpl() {
}
void BluetoothConnectFunction::ConnectToServiceCallback(
- const chromeos::BluetoothDevice* device,
+ const BluetoothDevice* device,
const std::string& service_uuid,
- scoped_refptr<chromeos::BluetoothSocket> socket) {
+ scoped_refptr<bluetooth::BluetoothSocket> socket) {
bryeung 2012/10/11 15:15:39 Should be using bluetooth::BluetoothSocket in this
youngki 2012/10/11 16:21:18 Done.
if (socket.get()) {
int socket_id = GetEventRouter(profile())->RegisterSocket(socket);
@@ -243,18 +262,21 @@ void BluetoothConnectFunction::ConnectToServiceCallback(
}
bool BluetoothConnectFunction::RunImpl() {
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
const experimental_bluetooth::ConnectOptions& options = params->options;
- std::string uuid = chromeos::bluetooth_utils::CanonicalUuid(
+ std::string uuid = bluetooth::utils::CanonicalUuid(
options.service_uuid);
if (uuid.empty()) {
SetError(kInvalidUuid);
return false;
}
- chromeos::BluetoothDevice* device =
+ BluetoothDevice* device =
GetMutableAdapter(profile())->GetDevice(options.device_address);
if (!device) {
SetError(kInvalidDevice);
@@ -276,6 +298,9 @@ bool BluetoothDisconnectFunction::RunImpl() {
return GetEventRouter(profile())->ReleaseSocket(options.socket_id);
}
+BluetoothReadFunction::BluetoothReadFunction() {}
+BluetoothReadFunction::~BluetoothReadFunction() {}
+
bool BluetoothReadFunction::Prepare() {
scoped_ptr<Read::Params> params(Read::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
@@ -292,8 +317,10 @@ bool BluetoothReadFunction::Prepare() {
}
void BluetoothReadFunction::Work() {
+ if (!socket_.get())
+ return;
+
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- CHECK(socket_.get() != NULL);
char* all_bytes = NULL;
ssize_t buffer_size = 0;
@@ -322,14 +349,19 @@ void BluetoothReadFunction::Work() {
free(all_bytes);
}
+#if defined(OS_CHROMEOS)
if (!success_)
SetError(safe_strerror(errsv));
+#endif
}
bool BluetoothReadFunction::Respond() {
return success_;
}
+BluetoothWriteFunction::BluetoothWriteFunction() {}
+BluetoothWriteFunction::~BluetoothWriteFunction() {}
+
bool BluetoothWriteFunction::Prepare() {
// TODO(bryeung): update to new-style parameter passing when ArrayBuffer
// support is added
@@ -370,8 +402,10 @@ void BluetoothWriteFunction::Work() {
success_ = (errsv == EAGAIN || errsv == EWOULDBLOCK);
}
+#if defined(OS_CHROMEOS)
if (!success_)
SetError(safe_strerror(errsv));
+#endif
}
bool BluetoothWriteFunction::Respond() {
@@ -388,6 +422,9 @@ void BluetoothSetOutOfBandPairingDataFunction::OnErrorCallback() {
}
bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() {
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
// TODO(bryeung): update to new-style parameter passing when ArrayBuffer
// support is added
DictionaryValue* options;
@@ -395,8 +432,7 @@ bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() {
std::string address;
EXTENSION_FUNCTION_VALIDATE(options->GetString("deviceAddress", &address));
- chromeos::BluetoothDevice* device =
- GetMutableAdapter(profile())->GetDevice(address);
+ BluetoothDevice* device = GetMutableAdapter(profile())->GetDevice(address);
if (!device) {
SetError(kInvalidDevice);
return false;
@@ -406,22 +442,22 @@ bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() {
DictionaryValue* data_in;
EXTENSION_FUNCTION_VALIDATE(options->GetDictionary("data", &data_in));
- chromeos::BluetoothOutOfBandPairingData data_out;
+ bluetooth::BluetoothOutOfBandPairingData data_out;
base::BinaryValue* tmp_data;
EXTENSION_FUNCTION_VALIDATE(data_in->GetBinary("hash", &tmp_data));
EXTENSION_FUNCTION_VALIDATE(
- tmp_data->GetSize() == chromeos::kBluetoothOutOfBandPairingDataSize);
+ tmp_data->GetSize() == bluetooth::kBluetoothOutOfBandPairingDataSize);
memcpy(data_out.hash,
reinterpret_cast<uint8_t*>(tmp_data->GetBuffer()),
- chromeos::kBluetoothOutOfBandPairingDataSize);
+ bluetooth::kBluetoothOutOfBandPairingDataSize);
EXTENSION_FUNCTION_VALIDATE(data_in->GetBinary("randomizer", &tmp_data));
EXTENSION_FUNCTION_VALIDATE(
- tmp_data->GetSize() == chromeos::kBluetoothOutOfBandPairingDataSize);
+ tmp_data->GetSize() == bluetooth::kBluetoothOutOfBandPairingDataSize);
memcpy(data_out.randomizer,
reinterpret_cast<uint8_t*>(tmp_data->GetBuffer()),
- chromeos::kBluetoothOutOfBandPairingDataSize);
+ bluetooth::kBluetoothOutOfBandPairingDataSize);
device->SetOutOfBandPairingData(
data_out,
@@ -441,13 +477,13 @@ bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() {
}
void BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback(
- const chromeos::BluetoothOutOfBandPairingData& data) {
+ const bluetooth::BluetoothOutOfBandPairingData& data) {
base::BinaryValue* hash = base::BinaryValue::CreateWithCopiedBuffer(
reinterpret_cast<const char*>(data.hash),
- chromeos::kBluetoothOutOfBandPairingDataSize);
+ bluetooth::kBluetoothOutOfBandPairingDataSize);
base::BinaryValue* randomizer = base::BinaryValue::CreateWithCopiedBuffer(
reinterpret_cast<const char*>(data.randomizer),
- chromeos::kBluetoothOutOfBandPairingDataSize);
+ bluetooth::kBluetoothOutOfBandPairingDataSize);
// TODO(bryeung): convert to experimental_bluetooth::OutOfBandPairingData
// when ArrayBuffer support within objects is completed.
@@ -466,6 +502,9 @@ void BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback() {
}
bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() {
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
GetMutableAdapter(profile())->ReadLocalOutOfBandPairingData(
base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback,
this),
@@ -485,6 +524,9 @@ void BluetoothStartDiscoveryFunction::OnErrorCallback() {
}
bool BluetoothStartDiscoveryFunction::RunImpl() {
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
GetEventRouter(profile())->SetSendDiscoveryEvents(true);
// If the adapter is already discovering, there is nothing else to do.
@@ -509,6 +551,9 @@ void BluetoothStopDiscoveryFunction::OnErrorCallback() {
}
bool BluetoothStopDiscoveryFunction::RunImpl() {
+ if (!IsBluetoothSupported(profile()))
+ return false;
+
GetEventRouter(profile())->SetSendDiscoveryEvents(false);
if (GetEventRouter(profile())->IsResponsibleForDiscovery()) {
GetMutableAdapter(profile())->SetDiscovering(false,
@@ -518,102 +563,5 @@ bool BluetoothStopDiscoveryFunction::RunImpl() {
return true;
}
-#else
-
-// -----------------------------------------------------------------------------
-// NIY stubs
-// -----------------------------------------------------------------------------
-bool BluetoothIsAvailableFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothIsPoweredFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothGetAddressFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothGetNameFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothGetDevicesFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothGetServicesFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothConnectFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothDisconnectFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothReadFunction::Prepare() {
- return true;
-}
-
-void BluetoothReadFunction::Work() {
-}
-
-bool BluetoothReadFunction::Respond() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothWriteFunction::Prepare() {
- return true;
-}
-
-void BluetoothWriteFunction::Work() {
-}
-
-bool BluetoothWriteFunction::Respond() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothStartDiscoveryFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothStopDiscoveryFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() {
- NOTREACHED() << "Not implemented yet";
- return false;
-}
-
-#endif
-
-BluetoothReadFunction::BluetoothReadFunction() {}
-BluetoothReadFunction::~BluetoothReadFunction() {}
-
-BluetoothWriteFunction::BluetoothWriteFunction() {}
-BluetoothWriteFunction::~BluetoothWriteFunction() {}
-
} // namespace api
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698