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

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

Issue 1382743002: bluetooth: Add characteristicvaluechanged event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1
Patch Set: Address tkent's comments Created 5 years, 2 months 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
« no previous file with comments | « no previous file | content/browser/bluetooth/bluetooth_dispatcher_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/containers/scoped_ptr_map.h" 9 #include "base/containers/scoped_ptr_map.h"
10 #include "base/id_map.h" 10 #include "base/id_map.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 bool powered) override; 75 bool powered) override;
76 void DeviceAdded(device::BluetoothAdapter* adapter, 76 void DeviceAdded(device::BluetoothAdapter* adapter,
77 device::BluetoothDevice* device) override; 77 device::BluetoothDevice* device) override;
78 void DeviceRemoved(device::BluetoothAdapter* adapter, 78 void DeviceRemoved(device::BluetoothAdapter* adapter,
79 device::BluetoothDevice* device) override; 79 device::BluetoothDevice* device) override;
80 void GattCharacteristicValueChanged( 80 void GattCharacteristicValueChanged(
81 device::BluetoothAdapter* adapter, 81 device::BluetoothAdapter* adapter,
82 device::BluetoothGattCharacteristic* characteristic, 82 device::BluetoothGattCharacteristic* characteristic,
83 const std::vector<uint8>& value) override; 83 const std::vector<uint8>& value) override;
84 84
85 // Sends an IPC to the thread informing that a the characteristic's
86 // value changed.
87 void NotifyActiveCharacteristic(int thread_id,
88 const std::string& characteristic_instance_id,
89 const std::vector<uint8>& value);
90
85 // IPC Handlers, see definitions in bluetooth_messages.h. 91 // IPC Handlers, see definitions in bluetooth_messages.h.
86 void OnRequestDevice( 92 void OnRequestDevice(
87 int thread_id, 93 int thread_id,
88 int request_id, 94 int request_id,
89 int frame_routing_id, 95 int frame_routing_id,
90 const std::vector<content::BluetoothScanFilter>& filters, 96 const std::vector<content::BluetoothScanFilter>& filters,
91 const std::vector<device::BluetoothUUID>& optional_services); 97 const std::vector<device::BluetoothUUID>& optional_services);
92 void OnConnectGATT(int thread_id, int request_id, 98 void OnConnectGATT(int thread_id, int request_id,
93 const std::string& device_instance_id); 99 const std::string& device_instance_id);
94 void OnGetPrimaryService(int thread_id, 100 void OnGetPrimaryService(int thread_id,
(...skipping 10 matching lines...) Expand all
105 void OnWriteValue(int thread_id, 111 void OnWriteValue(int thread_id,
106 int request_id, 112 int request_id,
107 const std::string& characteristic_instance_id, 113 const std::string& characteristic_instance_id,
108 const std::vector<uint8_t>& value); 114 const std::vector<uint8_t>& value);
109 void OnStartNotifications(int thread_id, 115 void OnStartNotifications(int thread_id,
110 int request_id, 116 int request_id,
111 const std::string& characteristic_instance_id); 117 const std::string& characteristic_instance_id);
112 void OnStopNotifications(int thread_id, 118 void OnStopNotifications(int thread_id,
113 int request_id, 119 int request_id,
114 const std::string& characteristic_instance_id); 120 const std::string& characteristic_instance_id);
121 void OnRegisterCharacteristicObject(
122 int thread_id,
123 const std::string& characteristic_instance_id);
124 void OnUnregisterCharacteristicObject(
125 int thread_id,
126 const std::string& characteristic_instance_id);
115 127
116 // Callbacks for BluetoothAdapter::StartDiscoverySession. 128 // Callbacks for BluetoothAdapter::StartDiscoverySession.
117 void OnDiscoverySessionStarted( 129 void OnDiscoverySessionStarted(
118 int chooser_id, 130 int chooser_id,
119 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); 131 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
120 void OnDiscoverySessionStartedError(int chooser_id); 132 void OnDiscoverySessionStartedError(int chooser_id);
121 133
122 // BluetoothChooser::EventHandler: 134 // BluetoothChooser::EventHandler:
123 void OnBluetoothChooserEvent(int chooser_id, 135 void OnBluetoothChooserEvent(int chooser_id,
124 BluetoothChooser::Event event, 136 BluetoothChooser::Event event,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // Map of characteristic_instance_id to service_instance_id. 214 // Map of characteristic_instance_id to service_instance_id.
203 std::map<std::string, std::string> characteristic_to_service_; 215 std::map<std::string, std::string> characteristic_to_service_;
204 216
205 // Map that matches characteristic_instance_id to notify session. 217 // Map that matches characteristic_instance_id to notify session.
206 // TODO(ortuno): Also key by thread_id once support for web workers, 218 // TODO(ortuno): Also key by thread_id once support for web workers,
207 // is added: http://crbug.com/537372 219 // is added: http://crbug.com/537372
208 base::ScopedPtrMap<std::string, 220 base::ScopedPtrMap<std::string,
209 scoped_ptr<device::BluetoothGattNotifySession>> 221 scoped_ptr<device::BluetoothGattNotifySession>>
210 characteristic_id_to_notify_session_; 222 characteristic_id_to_notify_session_;
211 223
224 // Map of characteristic_instance_id to a set of thread ids.
225 // A thread_id in the set represents a BluetoothDispatcher that
226 // needs to be notified of changes to the characteristic.
227 std::map<std::string, std::set<int>> active_characteristic_threads_;
228
212 // Defines how long to scan for and how long to discover services for. 229 // Defines how long to scan for and how long to discover services for.
213 int current_delay_time_; 230 int current_delay_time_;
214 231
215 // A BluetoothAdapter instance representing an adapter of the system. 232 // A BluetoothAdapter instance representing an adapter of the system.
216 scoped_refptr<device::BluetoothAdapter> adapter_; 233 scoped_refptr<device::BluetoothAdapter> adapter_;
217 234
218 // Automatically stops Bluetooth discovery a set amount of time after it was 235 // Automatically stops Bluetooth discovery a set amount of time after it was
219 // started. We have a single timer for all of Web Bluetooth because it's 236 // started. We have a single timer for all of Web Bluetooth because it's
220 // simpler than tracking timeouts for each RequestDeviceSession individually, 237 // simpler than tracking timeouts for each RequestDeviceSession individually,
221 // and because there's no harm in extending the length of a few discovery 238 // and because there's no harm in extending the length of a few discovery
222 // sessions when other sessions are active. 239 // sessions when other sessions are active.
223 base::Timer discovery_session_timer_; 240 base::Timer discovery_session_timer_;
224 241
225 // Retain BluetoothGattConnection objects to keep connections open. 242 // Retain BluetoothGattConnection objects to keep connections open.
226 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643 243 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643
227 ScopedVector<device::BluetoothGattConnection> connections_; 244 ScopedVector<device::BluetoothGattConnection> connections_;
228 245
229 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and 246 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and
230 // because it exists and has been bound to the UI thread enforces that all 247 // because it exists and has been bound to the UI thread enforces that all
231 // copies verify they are also used on the UI thread. 248 // copies verify they are also used on the UI thread.
232 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; 249 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_;
233 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; 250 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_;
234 251
235 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); 252 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost);
236 }; 253 };
237 254
238 } // namespace content 255 } // namespace content
239 256
240 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ 257 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/bluetooth/bluetooth_dispatcher_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698