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/public/browser/browser_message_filter.h" | 10 #include "content/public/browser/browser_message_filter.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // a filter on the channel. BrowserMessageFilter is refcounted and typically | 27 // a filter on the channel. BrowserMessageFilter is refcounted and typically |
28 // lives as long as it is installed on a channel. | 28 // lives as long as it is installed on a channel. |
29 // | 29 // |
30 // UI Thread Note: | 30 // UI Thread Note: |
31 // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI | 31 // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI |
32 // thread because BluetoothAdapter and related objects live there. | 32 // thread because BluetoothAdapter and related objects live there. |
33 class CONTENT_EXPORT BluetoothDispatcherHost final | 33 class CONTENT_EXPORT BluetoothDispatcherHost final |
34 : public BrowserMessageFilter, | 34 : public BrowserMessageFilter, |
35 public device::BluetoothAdapter::Observer { | 35 public device::BluetoothAdapter::Observer { |
36 public: | 36 public: |
37 BluetoothDispatcherHost(); | 37 BluetoothDispatcherHost(int render_process_id); |
38 // BrowserMessageFilter: | 38 // BrowserMessageFilter: |
39 void OnDestruct() const override; | 39 void OnDestruct() const override; |
40 void OverrideThreadForMessage(const IPC::Message& message, | 40 void OverrideThreadForMessage(const IPC::Message& message, |
41 BrowserThread::ID* thread) override; | 41 BrowserThread::ID* thread) override; |
42 bool OnMessageReceived(const IPC::Message& message) override; | 42 bool OnMessageReceived(const IPC::Message& message) override; |
43 | 43 |
44 void SetBluetoothAdapterForTesting( | 44 void SetBluetoothAdapterForTesting( |
45 scoped_refptr<device::BluetoothAdapter> mock_adapter); | 45 scoped_refptr<device::BluetoothAdapter> mock_adapter); |
46 | 46 |
47 protected: | 47 protected: |
48 ~BluetoothDispatcherHost() override; | 48 ~BluetoothDispatcherHost() override; |
49 | 49 |
50 private: | 50 private: |
51 friend class base::DeleteHelper<BluetoothDispatcherHost>; | 51 friend class base::DeleteHelper<BluetoothDispatcherHost>; |
52 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 52 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
53 | 53 |
54 struct RequestDeviceSession; | 54 struct RequestDeviceSession; |
55 | 55 |
56 // Set |adapter_| to a BluetoothAdapter instance and register observers, | 56 // Set |adapter_| to a BluetoothAdapter instance and register observers, |
57 // releasing references to previous |adapter_|. | 57 // releasing references to previous |adapter_|. |
58 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); | 58 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); |
59 | 59 |
60 // IPC Handlers, see definitions in bluetooth_messages.h. | 60 // IPC Handlers, see definitions in bluetooth_messages.h. |
61 void OnRequestDevice( | 61 void OnRequestDevice( |
62 int thread_id, | 62 int thread_id, |
63 int request_id, | 63 int request_id, |
| 64 int routing_id, |
64 const std::vector<content::BluetoothScanFilter>& filters, | 65 const std::vector<content::BluetoothScanFilter>& filters, |
65 const std::vector<device::BluetoothUUID>& optional_services); | 66 const std::vector<device::BluetoothUUID>& optional_services); |
66 void OnConnectGATT(int thread_id, int request_id, | 67 void OnConnectGATT(int thread_id, int request_id, |
67 const std::string& device_instance_id); | 68 const std::string& device_instance_id); |
68 void OnGetPrimaryService(int thread_id, | 69 void OnGetPrimaryService(int thread_id, |
69 int request_id, | 70 int request_id, |
70 const std::string& device_instance_id, | 71 const std::string& device_instance_id, |
71 const std::string& service_uuid); | 72 const std::string& service_uuid); |
72 void OnGetCharacteristic(int thread_id, | 73 void OnGetCharacteristic(int thread_id, |
73 int request_id, | 74 int request_id, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 int thread_id, | 127 int thread_id, |
127 int request_id, | 128 int request_id, |
128 device::BluetoothGattService::GattErrorCode); | 129 device::BluetoothGattService::GattErrorCode); |
129 | 130 |
130 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. | 131 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. |
131 void OnWriteValueSuccess(int thread_id, int request_id); | 132 void OnWriteValueSuccess(int thread_id, int request_id); |
132 void OnWriteValueFailed(int thread_id, | 133 void OnWriteValueFailed(int thread_id, |
133 int request_id, | 134 int request_id, |
134 device::BluetoothGattService::GattErrorCode); | 135 device::BluetoothGattService::GattErrorCode); |
135 | 136 |
| 137 int render_process_id_; |
| 138 |
136 // Maps a (thread_id,request_id) to information about its requestDevice call, | 139 // Maps a (thread_id,request_id) to information about its requestDevice call, |
137 // including the chooser dialog. | 140 // including the chooser dialog. |
138 // An entry is added to this map in OnRequestDevice, and should be removed | 141 // An entry is added to this map in OnRequestDevice, and should be removed |
139 // again everywhere a requestDevice() reply is sent. | 142 // again everywhere a requestDevice() reply is sent. |
140 std::map<std::pair<int, int>, RequestDeviceSession> request_device_sessions_; | 143 std::map<std::pair<int, int>, RequestDeviceSession> request_device_sessions_; |
141 | 144 |
142 // Maps to get the object's parent based on it's instanceID | 145 // Maps to get the object's parent based on it's instanceID |
143 // Map of service_instance_id to device_instance_id. | 146 // Map of service_instance_id to device_instance_id. |
144 std::map<std::string, std::string> service_to_device_; | 147 std::map<std::string, std::string> service_to_device_; |
145 // Map of characteristic_instance_id to service_instance_id. | 148 // Map of characteristic_instance_id to service_instance_id. |
146 std::map<std::string, std::string> characteristic_to_service_; | 149 std::map<std::string, std::string> characteristic_to_service_; |
147 | 150 |
148 // Defines how long to scan for and how long to discover services for. | 151 // Defines how long to scan for and how long to discover services for. |
149 int current_delay_time_; | 152 int current_delay_time_; |
150 | 153 |
151 // A BluetoothAdapter instance representing an adapter of the system. | 154 // A BluetoothAdapter instance representing an adapter of the system. |
152 scoped_refptr<device::BluetoothAdapter> adapter_; | 155 scoped_refptr<device::BluetoothAdapter> adapter_; |
153 | 156 |
154 // Must be last member, see base/memory/weak_ptr.h documentation | 157 // Must be last member, see base/memory/weak_ptr.h documentation |
155 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 158 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |
156 | 159 |
157 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 160 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); |
158 }; | 161 }; |
159 | 162 |
160 } // namespace content | 163 } // namespace content |
161 | 164 |
162 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 165 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
OLD | NEW |