diff options
author | scheib <scheib@chromium.org> | 2015-04-29 14:50:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-29 21:50:53 +0000 |
commit | e4a41d6a6bc1fd7c36996dd2879738b91e5caf59 (patch) | |
tree | f7caf2efef314185af23ae86969ab7ffb0754a8d | |
parent | cc8cec894ffd7a9434557911ce0732a7af412b08 (diff) | |
download | chromium_src-e4a41d6a6bc1fd7c36996dd2879738b91e5caf59.zip chromium_src-e4a41d6a6bc1fd7c36996dd2879738b91e5caf59.tar.gz chromium_src-e4a41d6a6bc1fd7c36996dd2879738b91e5caf59.tar.bz2 |
bluetooth: Move BluetoothDispatcherHost IPC handling to UI thread.
Instead of IPC handlers posting tasks to UI thread, override
BrowserMessageFilter::OverrideThreadForMessage to have all messages
delivered to UI thread.
Also, make BluetoothDispatcherHost final.
BUG=420284
Review URL: https://codereview.chromium.org/1112033002
Cr-Commit-Position: refs/heads/master@{#327584}
-rw-r--r-- | content/browser/bluetooth/bluetooth_dispatcher_host.cc | 34 | ||||
-rw-r--r-- | content/browser/bluetooth/bluetooth_dispatcher_host.h | 18 |
2 files changed, 19 insertions, 33 deletions
diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc index fb62188..c7ddbd1 100644 --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc @@ -32,11 +32,19 @@ scoped_refptr<BluetoothDispatcherHost> BluetoothDispatcherHost::Create() { } void BluetoothDispatcherHost::OnDestruct() const { + // See class comment: UI Thread Note. BrowserThread::DeleteOnUIThread::Destruct(this); } +void BluetoothDispatcherHost::OverrideThreadForMessage( + const IPC::Message& message, + content::BrowserThread::ID* thread) { + // See class comment: UI Thread Note. + *thread = BrowserThread::UI; +} + bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); + DCHECK_CURRENTLY_ON(BrowserThread::UI); bool handled = true; IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) @@ -72,16 +80,6 @@ void BluetoothDispatcherHost::set_adapter( } void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - BrowserThread::PostTask(BrowserThread::UI, - FROM_HERE, - base::Bind( - &BluetoothDispatcherHost::OnRequestDeviceOnUI, - this, thread_id, request_id)); -} - -void BluetoothDispatcherHost::OnRequestDeviceOnUI(int thread_id, - int request_id) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); // TODO(scheib) Extend this very simple mock implementation by using // device/bluetooth/test mock adapter and related classes. @@ -148,18 +146,6 @@ void BluetoothDispatcherHost::OnConnectGATT( int thread_id, int request_id, const std::string& device_instance_id) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - BrowserThread::PostTask(BrowserThread::UI, - FROM_HERE, - base::Bind( - &BluetoothDispatcherHost::OnConnectGATTOnUI, - this, thread_id, request_id, device_instance_id)); -} - -void BluetoothDispatcherHost::OnConnectGATTOnUI( - int thread_id, - int request_id, - const std::string& device_instance_id) { DCHECK_CURRENTLY_ON(BrowserThread::UI); // TODO(ortuno): Add actual implementation of connectGATT. This needs to be // done after the "allowed devices map" is implemented. @@ -169,7 +155,7 @@ void BluetoothDispatcherHost::OnConnectGATTOnUI( void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting( const std::string& name) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); + DCHECK_CURRENTLY_ON(BrowserThread::UI); if (name == "RejectRequestDevice_NotFoundError") { bluetooth_mock_data_set_ = MockData::REJECT; bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.h b/content/browser/bluetooth/bluetooth_dispatcher_host.h index a49c759..6677f79 100644 --- a/content/browser/bluetooth/bluetooth_dispatcher_host.h +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.h @@ -14,22 +14,25 @@ namespace content { // Dispatches and sends bluetooth related messages sent to/from a child // process BluetoothDispatcher from/to the main browser process. -// Constructed on the main (UI) thread and receives IPC on the IO thread. +// // Intended to be instantiated by the RenderProcessHost and installed as // a filter on the channel. BrowserMessageFilter is refcounted and typically // lives as long as it is installed on a channel. // -// BluetoothDispatcherHost primarily operates on the UI thread because the -// BluetoothAdapter and related objects live there. An exception is made for -// Receiving IPC on the IO thread. -class BluetoothDispatcherHost : public BrowserMessageFilter, - public device::BluetoothAdapter::Observer { +// UI Thread Note: +// BluetoothDispatcherHost is constructed, operates, and destroyed on the UI +// thread because BluetoothAdapter and related objects live there. +class BluetoothDispatcherHost final + : public BrowserMessageFilter, + public device::BluetoothAdapter::Observer { public: // Creates a BluetoothDispatcherHost. static scoped_refptr<BluetoothDispatcherHost> Create(); // BrowserMessageFilter: void OnDestruct() const override; + void OverrideThreadForMessage(const IPC::Message& message, + BrowserThread::ID* thread) override; bool OnMessageReceived(const IPC::Message& message) override; protected: @@ -46,11 +49,8 @@ class BluetoothDispatcherHost : public BrowserMessageFilter, // IPC Handlers, see definitions in bluetooth_messages.h. void OnRequestDevice(int thread_id, int request_id); - void OnRequestDeviceOnUI(int thread_id, int request_id); void OnConnectGATT(int thread_id, int request_id, const std::string& device_instance_id); - void OnConnectGATTOnUI(int thread_id, int request_id, - const std::string& device_instance_id); void OnSetBluetoothMockDataSetForTesting(const std::string& name); // A BluetoothAdapter instance representing an adapter of the system. |