1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_
8 #include "base/basictypes.h"
9 #include "content/common/bluetooth/bluetooth_error.h"
10 #include "content/public/browser/browser_message_filter.h"
11 #include "device/bluetooth/bluetooth_adapter.h"
15 // Dispatches and sends bluetooth related messages sent to/from a child
16 // process BluetoothDispatcher from/to the main browser process.
17 // Constructed on the main (UI) thread and receives IPC on the IO thread.
18 // Intended to be instantiated by the RenderProcessHost and installed as
19 // a filter on the channel. BrowserMessageFilter is refcounted and typically
20 // lives as long as it is installed on a channel.
22 // BluetoothDispatcherHost primarily operates on the UI thread because the
23 // BluetoothAdapter and related objects live there. An exception is made for
24 // Receiving IPC on the IO thread.
25 class BluetoothDispatcherHost
: public BrowserMessageFilter
,
26 public device::BluetoothAdapter::Observer
{
28 // Creates a BluetoothDispatcherHost.
29 static scoped_refptr
<BluetoothDispatcherHost
> Create();
31 // BrowserMessageFilter:
32 void OnDestruct() const override
;
33 bool OnMessageReceived(const IPC::Message
& message
) override
;
36 BluetoothDispatcherHost();
37 ~BluetoothDispatcherHost() override
;
40 friend class base::DeleteHelper
<BluetoothDispatcherHost
>;
41 friend struct BrowserThread::DeleteOnThread
<BrowserThread::UI
>;
43 // Set |adapter_| to a BluetoothAdapter instance and register observers,
44 // releasing references to previous |adapter_|.
45 void set_adapter(scoped_refptr
<device::BluetoothAdapter
> adapter
);
47 // IPC Handlers, see definitions in bluetooth_messages.h.
48 void OnRequestDevice(int thread_id
, int request_id
);
49 void OnRequestDeviceOnUI(int thread_id
, int request_id
);
50 void OnConnectGATT(int thread_id
, int request_id
,
51 const std::string
& device_instance_id
);
52 void OnConnectGATTOnUI(int thread_id
, int request_id
,
53 const std::string
& device_instance_id
);
54 void OnSetBluetoothMockDataSetForTesting(const std::string
& name
);
56 // A BluetoothAdapter instance representing an adapter of the system.
57 scoped_refptr
<device::BluetoothAdapter
> adapter_
;
59 enum class MockData
{ NOT_MOCKING
, REJECT
, RESOLVE
};
60 MockData bluetooth_mock_data_set_
;
61 BluetoothError bluetooth_request_device_reject_type_
;
63 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost
);
66 } // namespace content
68 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_