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

Unified Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 787953004: bluetooth: Use BluetoothAdapter in BluetoothDispatcherHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: virtual/override replaced Created 5 years, 11 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: content/browser/bluetooth/bluetooth_dispatcher_host.cc
diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
index ff92d932ef45ce28c8fcae7c1a8c50d75a5aa179..865a8a0c75e7c35c9dd9708201be618b7c00f980 100644
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
@@ -5,14 +5,27 @@
#include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
#include "content/common/bluetooth/bluetooth_messages.h"
+#include "device/bluetooth/bluetooth_adapter.h"
+#include "device/bluetooth/bluetooth_adapter_factory.h"
+#include "device/bluetooth/bluetooth_device.h"
+
+using device::BluetoothAdapter;
+using device::BluetoothAdapterFactory;
+using device::BluetoothDevice;
namespace content {
-BluetoothDispatcherHost::BluetoothDispatcherHost()
- : BrowserMessageFilter(BluetoothMsgStart),
- bluetooth_mock_data_set_(MockData::NOT_MOCKING),
- bluetooth_request_device_reject_type_(BluetoothError::NOT_FOUND) {
+scoped_refptr<BluetoothDispatcherHost> BluetoothDispatcherHost::Create() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ // Hold a reference to the BluetoothDispatcherHost because the callback below
+ // may run and would otherwise release the BluetoothDispatcherHost
+ // prematurely.
+ scoped_refptr<BluetoothDispatcherHost> host(new BluetoothDispatcherHost());
+ if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable())
+ BluetoothAdapterFactory::GetAdapter(
+ base::Bind(&BluetoothDispatcherHost::set_adapter, host));
+ return host;
}
bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) {
@@ -27,16 +40,45 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) {
return handled;
}
+BluetoothDispatcherHost::BluetoothDispatcherHost()
+ : BrowserMessageFilter(BluetoothMsgStart),
+ bluetooth_mock_data_set_(MockData::NOT_MOCKING),
+ bluetooth_request_device_reject_type_(BluetoothError::NOT_FOUND) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+}
+
BluetoothDispatcherHost::~BluetoothDispatcherHost() {
+ // Clear adapter, releasing observer references.
+ set_adapter(scoped_refptr<device::BluetoothAdapter>());
+}
+
+void BluetoothDispatcherHost::set_adapter(
+ scoped_refptr<device::BluetoothAdapter> adapter) {
+ if (adapter_.get())
+ adapter_->RemoveObserver(this);
+ adapter_ = adapter;
+ if (adapter_.get())
+ adapter_->AddObserver(this);
}
void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- // Mock implementation util a more complete implementation is built out.
+ // TODO(scheib) Extend this very simple mock implementation by using
+ // device/bluetooth/test mock adapter and related classes.
switch (bluetooth_mock_data_set_) {
case MockData::NOT_MOCKING: {
- Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
- BluetoothError::NOT_FOUND));
+ // TODO(scheib): Filter devices by services: crbug.com/440594
+ // TODO(scheib): Device selection UI: crbug.com/436280
+ // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed.
+ BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
+ if (devices.begin() == devices.end()) {
+ Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
+ BluetoothError::NOT_FOUND));
+ } else {
+ BluetoothDevice* device = *devices.begin();
+ Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id,
+ device->GetAddress()));
+ }
return;
}
case MockData::REJECT: {
« no previous file with comments | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698