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

Side by Side Diff: content/browser/bluetooth/bluetooth_dispatcher_host.h

Issue 1502663003: bluetooth: Implement allowed devices map (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Forgot test file Created 5 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 unified diff | Download patch
OLDNEW
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 <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/id_map.h" 11 #include "base/id_map.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
14 #include "content/public/browser/bluetooth_chooser.h" 15 #include "content/public/browser/bluetooth_chooser.h"
15 #include "content/public/browser/browser_message_filter.h" 16 #include "content/public/browser/browser_message_filter.h"
16 #include "device/bluetooth/bluetooth_adapter.h" 17 #include "device/bluetooth/bluetooth_adapter.h"
17 #include "device/bluetooth/bluetooth_gatt_connection.h" 18 #include "device/bluetooth/bluetooth_gatt_connection.h"
18 #include "device/bluetooth/bluetooth_gatt_notify_session.h" 19 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
19 #include "device/bluetooth/bluetooth_gatt_service.h" 20 #include "device/bluetooth/bluetooth_gatt_service.h"
20 21
21 namespace device { 22 namespace device {
22 class BluetoothUUID; 23 class BluetoothUUID;
23 } 24 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 // IPC Handlers, see definitions in bluetooth_messages.h. 97 // IPC Handlers, see definitions in bluetooth_messages.h.
97 void OnRequestDevice( 98 void OnRequestDevice(
98 int thread_id, 99 int thread_id,
99 int request_id, 100 int request_id,
100 int frame_routing_id, 101 int frame_routing_id,
101 const std::vector<content::BluetoothScanFilter>& filters, 102 const std::vector<content::BluetoothScanFilter>& filters,
102 const std::vector<device::BluetoothUUID>& optional_services); 103 const std::vector<device::BluetoothUUID>& optional_services);
103 void OnConnectGATT(int thread_id, 104 void OnConnectGATT(int thread_id,
104 int request_id, 105 int request_id,
106 int frame_routing_id,
105 const std::string& device_id); 107 const std::string& device_id);
106 void OnGetPrimaryService(int thread_id, 108 void OnGetPrimaryService(int thread_id,
107 int request_id, 109 int request_id,
110 int frame_routing_id,
108 const std::string& device_id, 111 const std::string& device_id,
109 const std::string& service_uuid); 112 const std::string& service_uuid);
110 void OnGetCharacteristic(int thread_id, 113 void OnGetCharacteristic(int thread_id,
111 int request_id, 114 int request_id,
115 int frame_routing_id,
112 const std::string& service_instance_id, 116 const std::string& service_instance_id,
113 const std::string& characteristic_uuid); 117 const std::string& characteristic_uuid);
114 void OnReadValue(int thread_id, 118 void OnReadValue(int thread_id,
115 int request_id, 119 int request_id,
120 int frame_routing_id,
116 const std::string& characteristic_instance_id); 121 const std::string& characteristic_instance_id);
117 void OnWriteValue(int thread_id, 122 void OnWriteValue(int thread_id,
118 int request_id, 123 int request_id,
124 int frame_routing_id,
119 const std::string& characteristic_instance_id, 125 const std::string& characteristic_instance_id,
120 const std::vector<uint8_t>& value); 126 const std::vector<uint8_t>& value);
121 void OnStartNotifications(int thread_id, 127 void OnStartNotifications(int thread_id,
122 int request_id, 128 int request_id,
129 int frame_routing_id,
123 const std::string& characteristic_instance_id); 130 const std::string& characteristic_instance_id);
124 void OnStopNotifications(int thread_id, 131 void OnStopNotifications(int thread_id,
125 int request_id, 132 int request_id,
133 int frame_routing_id,
126 const std::string& characteristic_instance_id); 134 const std::string& characteristic_instance_id);
127 void OnRegisterCharacteristicObject( 135 void OnRegisterCharacteristicObject(
128 int thread_id, 136 int thread_id,
137 int frame_routing_id,
129 const std::string& characteristic_instance_id); 138 const std::string& characteristic_instance_id);
130 void OnUnregisterCharacteristicObject( 139 void OnUnregisterCharacteristicObject(
131 int thread_id, 140 int thread_id,
141 int frame_routing_id,
132 const std::string& characteristic_instance_id); 142 const std::string& characteristic_instance_id);
133 143
134 // Callbacks for BluetoothAdapter::StartDiscoverySession. 144 // Callbacks for BluetoothAdapter::StartDiscoverySession.
135 void OnDiscoverySessionStarted( 145 void OnDiscoverySessionStarted(
136 int chooser_id, 146 int chooser_id,
137 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); 147 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
138 void OnDiscoverySessionStartedError(int chooser_id); 148 void OnDiscoverySessionStartedError(int chooser_id);
139 149
140 // BluetoothChooser::EventHandler: 150 // BluetoothChooser::EventHandler:
141 void OnBluetoothChooserEvent(int chooser_id, 151 void OnBluetoothChooserEvent(int chooser_id,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 const std::string& characteristic_instance_id); 211 const std::string& characteristic_instance_id);
202 212
203 // Functions to query the platform cache for the bluetooth object. 213 // Functions to query the platform cache for the bluetooth object.
204 // result.outcome == CacheQueryOutcome::SUCCESS if the object was found in the 214 // result.outcome == CacheQueryOutcome::SUCCESS if the object was found in the
205 // cache. Otherwise result.outcome that can used to record the outcome and 215 // cache. Otherwise result.outcome that can used to record the outcome and
206 // result.error will contain the error that should be send to the renderer. 216 // result.error will contain the error that should be send to the renderer.
207 // One of the possible outcomes is BAD_RENDERER. In this case the outcome 217 // One of the possible outcomes is BAD_RENDERER. In this case the outcome
208 // was already recorded and since there renderer crashed there is no need to 218 // was already recorded and since there renderer crashed there is no need to
209 // send a response. 219 // send a response.
210 220
211 // Queries the platform cache for a Device with |device_id|. Fills in the 221 // Queries the platform cache for a Device with |device_id| for |origin|.
212 // |outcome| field and the |device| field if successful. 222 // Fills in the |outcome| field and the |device| field if successful.
213 CacheQueryResult QueryCacheForDevice(const std::string& device_id); 223 CacheQueryResult QueryCacheForDevice(const std::string& origin,
224 const std::string& device_id);
214 // Queries the platform cache for a Service with |service_instance_id|. Fills 225 // Queries the platform cache for a Service with |service_instance_id|. Fills
215 // in the |outcome| field, and |device| and |service| fields if successful. 226 // in the |outcome| field, and |device| and |service| fields if successful.
216 CacheQueryResult QueryCacheForService(const std::string& service_instance_id); 227 CacheQueryResult QueryCacheForService(const std::string& origin,
228 const std::string& service_instance_id);
217 // Queries the platform cache for a characteristic with 229 // Queries the platform cache for a characteristic with
218 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, 230 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|,
219 // |service| and |characteristic| fields if successful. 231 // |service| and |characteristic| fields if successful.
220 CacheQueryResult QueryCacheForCharacteristic( 232 CacheQueryResult QueryCacheForCharacteristic(
233 const std::string& origin,
221 const std::string& characteristic_instance_id); 234 const std::string& characteristic_instance_id);
222 235
223 // Returns true if all services have been discovered for the device. 236 // Returns true if all services have been discovered for the device.
224 // When the host gets a ServiceChanged indication, it automatically 237 // When the host gets a ServiceChanged indication, it automatically
225 // re-discovers services, and only forwards the ServiceChanged event to this 238 // re-discovers services, and only forwards the ServiceChanged event to this
226 // class when it's done re-discovering. 239 // class when it's done re-discovering.
227 bool IsServicesDiscoveryCompleteForDevice(const std::string& device_id); 240 bool IsServicesDiscoveryCompleteForDevice(const std::string& device_address);
228 241
229 // Adds the PrimaryServicesRequest to the vector of pending services requests 242 // Adds the PrimaryServicesRequest to the vector of pending services requests
230 // for that device. 243 // for that device.
231 void AddToPendingPrimaryServicesRequest( 244 void AddToPendingPrimaryServicesRequest(
232 const std::string& device_id, 245 const std::string& device_address,
233 const PrimaryServicesRequest& request); 246 const PrimaryServicesRequest& request);
234 247
248 // Returns the origin for the frame with "frame_rounting_id" in this process.
Jeffrey Yasskin 2016/01/06 00:47:57 sp: rounting
Jeffrey Yasskin 2016/01/06 00:47:57 s/this process/render_process_id_/
ortuno 2016/01/13 01:41:44 Done. On 2016/01/06 at 00:47:57, Jeffrey Yasskin
249 std::string GetOrigin(int frame_routing_id);
250
235 // Show help pages from the chooser dialog. 251 // Show help pages from the chooser dialog.
236 void ShowBluetoothOverviewLink(); 252 void ShowBluetoothOverviewLink();
237 void ShowBluetoothPairingLink(); 253 void ShowBluetoothPairingLink();
238 void ShowBluetoothAdapterOffLink(); 254 void ShowBluetoothAdapterOffLink();
239 void ShowNeedLocationLink(); 255 void ShowNeedLocationLink();
240 256
241 int render_process_id_; 257 int render_process_id_;
242 258
243 // Maps a (thread_id,request_id) to information about its requestDevice call, 259 // Maps a (thread_id,request_id) to information about its requestDevice call,
244 // including the chooser dialog. 260 // including the chooser dialog.
245 // An entry is added to this map in OnRequestDevice, and should be removed 261 // An entry is added to this map in OnRequestDevice, and should be removed
246 // again everywhere a requestDevice() reply is sent. 262 // again everywhere a requestDevice() reply is sent.
247 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; 263 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_;
248 264
265 BluetoothAllowedDevicesMap allowed_devices_map_;
266
249 // Maps to get the object's parent based on it's instanceID 267 // Maps to get the object's parent based on it's instanceID
250 // Map of service_instance_id to device_id. 268 // Map of service_instance_id to device_address.
251 std::map<std::string, std::string> service_to_device_; 269 std::map<std::string, std::string> service_to_device_;
252 // Map of characteristic_instance_id to service_instance_id. 270 // Map of characteristic_instance_id to service_instance_id.
253 std::map<std::string, std::string> characteristic_to_service_; 271 std::map<std::string, std::string> characteristic_to_service_;
254 272
255 // Map that matches characteristic_instance_id to notify session. 273 // Map that matches characteristic_instance_id to notify session.
256 // TODO(ortuno): Also key by thread_id once support for web workers, 274 // TODO(ortuno): Also key by thread_id once support for web workers,
257 // is added: http://crbug.com/537372 275 // is added: http://crbug.com/537372
258 std::map<std::string, scoped_ptr<device::BluetoothGattNotifySession>> 276 std::map<std::string, scoped_ptr<device::BluetoothGattNotifySession>>
259 characteristic_id_to_notify_session_; 277 characteristic_id_to_notify_session_;
260 278
(...skipping 15 matching lines...) Expand all
276 // sessions when other sessions are active. 294 // sessions when other sessions are active.
277 base::Timer discovery_session_timer_; 295 base::Timer discovery_session_timer_;
278 296
279 // Retain BluetoothGattConnection objects to keep connections open. 297 // Retain BluetoothGattConnection objects to keep connections open.
280 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643 298 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643
281 ScopedVector<device::BluetoothGattConnection> connections_; 299 ScopedVector<device::BluetoothGattConnection> connections_;
282 300
283 // Keeps track of which devices have had their services discovered. 301 // Keeps track of which devices have had their services discovered.
284 std::set<std::string> devices_with_discovered_services_; 302 std::set<std::string> devices_with_discovered_services_;
285 303
286 // Map of device_id's to primary-services requests that need responses when 304 // Map of device_address's to primary-services requests that need responses
287 // that device's service discovery completes. 305 // when that device's service discovery completes.
288 std::map<std::string, std::vector<PrimaryServicesRequest>> 306 std::map<std::string, std::vector<PrimaryServicesRequest>>
289 pending_primary_services_requests_; 307 pending_primary_services_requests_;
290 308
291 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and 309 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and
292 // because it exists and has been bound to the UI thread enforces that all 310 // because it exists and has been bound to the UI thread enforces that all
293 // copies verify they are also used on the UI thread. 311 // copies verify they are also used on the UI thread.
294 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; 312 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_;
295 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; 313 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_;
296 314
297 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); 315 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost);
298 }; 316 };
299 317
300 } // namespace content 318 } // namespace content
301 319
302 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ 320 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698