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

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: Created 6 years 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..c21dbc1546c39f66fe5a8755367ca0857e762e65 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,7 +40,25 @@ 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) {
@@ -35,8 +66,17 @@ void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) {
// Mock implementation util a more complete implementation is built out.
armansito 2014/12/10 00:40:04 nit: s/util/until/ ?
scheib 2014/12/10 17:54:02 Done.
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
+ BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
armansito 2014/12/10 00:40:04 I don't know what the final behavior will look lik
scheib 2014/12/10 17:54:02 Done.
+ 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