OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "content/common/bluetooth/bluetooth_error.h" | 10 #include "content/common/bluetooth/bluetooth_error.h" |
11 #include "content/public/browser/browser_message_filter.h" | 11 #include "content/public/browser/browser_message_filter.h" |
12 #include "device/bluetooth/bluetooth_adapter.h" | 12 #include "device/bluetooth/bluetooth_adapter.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 // Dispatches and sends bluetooth related messages sent to/from a child | 16 // Dispatches and sends bluetooth related messages sent to/from a child |
17 // process BluetoothDispatcher from/to the main browser process. | 17 // process BluetoothDispatcher from/to the main browser process. |
18 // | 18 // |
19 // Intended to be instantiated by the RenderProcessHost and installed as | 19 // Intended to be instantiated by the RenderProcessHost and installed as |
20 // a filter on the channel. BrowserMessageFilter is refcounted and typically | 20 // a filter on the channel. BrowserMessageFilter is refcounted and typically |
21 // lives as long as it is installed on a channel. | 21 // lives as long as it is installed on a channel. |
22 // | 22 // |
23 // UI Thread Note: | 23 // UI Thread Note: |
24 // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI | 24 // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI |
25 // thread because BluetoothAdapter and related objects live there. | 25 // thread because BluetoothAdapter and related objects live there. |
26 class CONTENT_EXPORT BluetoothDispatcherHost final | 26 class BluetoothDispatcherHost final |
27 : public BrowserMessageFilter, | 27 : public BrowserMessageFilter, |
28 public device::BluetoothAdapter::Observer { | 28 public device::BluetoothAdapter::Observer { |
29 public: | 29 public: |
30 BluetoothDispatcherHost(); | 30 BluetoothDispatcherHost(); |
31 // BrowserMessageFilter: | 31 // BrowserMessageFilter: |
32 void OnDestruct() const override; | 32 void OnDestruct() const override; |
33 void OverrideThreadForMessage(const IPC::Message& message, | 33 void OverrideThreadForMessage(const IPC::Message& message, |
34 BrowserThread::ID* thread) override; | 34 BrowserThread::ID* thread) override; |
35 bool OnMessageReceived(const IPC::Message& message) override; | 35 bool OnMessageReceived(const IPC::Message& message) override; |
36 | 36 |
37 void SetBluetoothAdapterForTesting(const std::string& name); | |
38 | |
39 protected: | 37 protected: |
40 ~BluetoothDispatcherHost() override; | 38 ~BluetoothDispatcherHost() override; |
41 | 39 |
42 private: | 40 private: |
43 friend class base::DeleteHelper<BluetoothDispatcherHost>; | 41 friend class base::DeleteHelper<BluetoothDispatcherHost>; |
44 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 42 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
45 | 43 |
46 // Set |adapter_| to a BluetoothAdapter instance and register observers, | 44 // Set |adapter_| to a BluetoothAdapter instance and register observers, |
47 // releasing references to previous |adapter_|. | 45 // releasing references to previous |adapter_|. |
48 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); | 46 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); |
49 | 47 |
50 // IPC Handlers, see definitions in bluetooth_messages.h. | 48 // IPC Handlers, see definitions in bluetooth_messages.h. |
51 void OnRequestDevice(int thread_id, int request_id); | 49 void OnRequestDevice(int thread_id, int request_id); |
52 void OnConnectGATT(int thread_id, int request_id, | 50 void OnConnectGATT(int thread_id, int request_id, |
53 const std::string& device_instance_id); | 51 const std::string& device_instance_id); |
| 52 void OnSetBluetoothMockDataSetForTesting(const std::string& name); |
54 | 53 |
55 // Callbacks for BluetoothAdapter::StartDiscoverySession. | 54 // Callbacks for BluetoothAdapter::StartDiscoverySession. |
56 void OnDiscoverySessionStarted( | 55 void OnDiscoverySessionStarted( |
57 int thread_id, | 56 int thread_id, |
58 int request_id, | 57 int request_id, |
59 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 58 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
60 void OnDiscoverySessionStartedError(int thread_id, int request_id); | 59 void OnDiscoverySessionStartedError(int thread_id, int request_id); |
61 | 60 |
62 // Stop in progress discovery session. | 61 // Stop in progress discovery session. |
63 void StopDiscoverySession( | 62 void StopDiscoverySession( |
(...skipping 14 matching lines...) Expand all Loading... |
78 | 77 |
79 // Must be last member, see base/memory/weak_ptr.h documentation | 78 // Must be last member, see base/memory/weak_ptr.h documentation |
80 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 79 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |
81 | 80 |
82 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 81 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); |
83 }; | 82 }; |
84 | 83 |
85 } // namespace content | 84 } // namespace content |
86 | 85 |
87 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 86 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
OLD | NEW |