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

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

Issue 1334763002: bluetooth: Subscribe to notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-origin
Patch Set: Created 5 years, 3 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
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/id_map.h" 10 #include "base/id_map.h"
10 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
11 #include "content/public/browser/bluetooth_chooser.h" 12 #include "content/public/browser/bluetooth_chooser.h"
12 #include "content/public/browser/browser_message_filter.h" 13 #include "content/public/browser/browser_message_filter.h"
13 #include "device/bluetooth/bluetooth_adapter.h" 14 #include "device/bluetooth/bluetooth_adapter.h"
14 #include "device/bluetooth/bluetooth_gatt_connection.h" 15 #include "device/bluetooth/bluetooth_gatt_connection.h"
16 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
15 #include "device/bluetooth/bluetooth_gatt_service.h" 17 #include "device/bluetooth/bluetooth_gatt_service.h"
16 18
17 namespace device { 19 namespace device {
18 class BluetoothUUID; 20 class BluetoothUUID;
19 } 21 }
20 22
21 namespace content { 23 namespace content {
22 24
23 struct BluetoothScanFilter; 25 struct BluetoothScanFilter;
24 26
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // choosers. 65 // choosers.
64 void StopDeviceDiscovery(); 66 void StopDeviceDiscovery();
65 67
66 // BluetoothAdapter::Observer: 68 // BluetoothAdapter::Observer:
67 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, 69 void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
68 bool powered) override; 70 bool powered) override;
69 void DeviceAdded(device::BluetoothAdapter* adapter, 71 void DeviceAdded(device::BluetoothAdapter* adapter,
70 device::BluetoothDevice* device) override; 72 device::BluetoothDevice* device) override;
71 void DeviceRemoved(device::BluetoothAdapter* adapter, 73 void DeviceRemoved(device::BluetoothAdapter* adapter,
72 device::BluetoothDevice* device) override; 74 device::BluetoothDevice* device) override;
75 void GattCharacteristicValueChanged(
76 device::BluetoothAdapter* adapter,
77 device::BluetoothGattCharacteristic* characteristic,
78 const std::vector<uint8>& value) override;
73 79
74 // IPC Handlers, see definitions in bluetooth_messages.h. 80 // IPC Handlers, see definitions in bluetooth_messages.h.
75 void OnRequestDevice( 81 void OnRequestDevice(
76 int thread_id, 82 int thread_id,
77 int request_id, 83 int request_id,
78 int frame_routing_id, 84 int frame_routing_id,
79 const std::vector<content::BluetoothScanFilter>& filters, 85 const std::vector<content::BluetoothScanFilter>& filters,
80 const std::vector<device::BluetoothUUID>& optional_services); 86 const std::vector<device::BluetoothUUID>& optional_services);
81 void OnConnectGATT(int thread_id, int request_id, 87 void OnConnectGATT(int thread_id, int request_id,
82 const std::string& device_instance_id); 88 const std::string& device_instance_id);
83 void OnGetPrimaryService(int thread_id, 89 void OnGetPrimaryService(int thread_id,
84 int request_id, 90 int request_id,
85 const std::string& device_instance_id, 91 const std::string& device_instance_id,
86 const std::string& service_uuid); 92 const std::string& service_uuid);
87 void OnGetCharacteristic(int thread_id, 93 void OnGetCharacteristic(int thread_id,
88 int request_id, 94 int request_id,
89 const std::string& service_instance_id, 95 const std::string& service_instance_id,
90 const std::string& characteristic_uuid); 96 const std::string& characteristic_uuid);
91 void OnReadValue(int thread_id, 97 void OnReadValue(int thread_id,
92 int request_id, 98 int request_id,
93 const std::string& characteristic_instance_id); 99 const std::string& characteristic_instance_id);
94 void OnWriteValue(int thread_id, 100 void OnWriteValue(int thread_id,
95 int request_id, 101 int request_id,
96 const std::string& characteristic_instance_id, 102 const std::string& characteristic_instance_id,
97 const std::vector<uint8_t>& value); 103 const std::vector<uint8_t>& value);
104 void OnStartNotifications(int thread_id,
105 int request_id,
106 const std::string& characteristic_instance_id);
107 void OnStopNotifications(int thread_id,
108 int request_id,
109 const std::string& characteristic_instance_id);
98 110
99 // Callbacks for BluetoothAdapter::StartDiscoverySession. 111 // Callbacks for BluetoothAdapter::StartDiscoverySession.
100 void OnDiscoverySessionStarted( 112 void OnDiscoverySessionStarted(
101 int chooser_id, 113 int chooser_id,
102 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); 114 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
103 void OnDiscoverySessionStartedError(int chooser_id); 115 void OnDiscoverySessionStartedError(int chooser_id);
104 116
105 // BluetoothChooser::EventHandler: 117 // BluetoothChooser::EventHandler:
106 void OnBluetoothChooserEvent(int chooser_id, 118 void OnBluetoothChooserEvent(int chooser_id,
107 BluetoothChooser::Event event, 119 BluetoothChooser::Event event,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 int thread_id, 156 int thread_id,
145 int request_id, 157 int request_id,
146 device::BluetoothGattService::GattErrorCode); 158 device::BluetoothGattService::GattErrorCode);
147 159
148 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. 160 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic.
149 void OnWriteValueSuccess(int thread_id, int request_id); 161 void OnWriteValueSuccess(int thread_id, int request_id);
150 void OnWriteValueFailed(int thread_id, 162 void OnWriteValueFailed(int thread_id,
151 int request_id, 163 int request_id,
152 device::BluetoothGattService::GattErrorCode); 164 device::BluetoothGattService::GattErrorCode);
153 165
166 // Callbacks for BluetoothGattCharacteristic::StartNotifySession.
167 void OnStartNotifySessionSuccess(
168 int thread_id,
169 int request_id,
170 scoped_ptr<device::BluetoothGattNotifySession> notify_session);
171 void OnStartNotifySessionFailed(
172 int thread_id,
173 int request_id,
174 device::BluetoothGattService::GattErrorCode error_code);
175
176 // Callback for BluetoothGattNotifySession::Stop.
177 void OnStopNotifySession(int thread_id,
178 int request_id,
179 const std::string& characteristic_instance_id);
180
154 // Show help pages from the chooser dialog. 181 // Show help pages from the chooser dialog.
155 void ShowBluetoothOverviewLink(); 182 void ShowBluetoothOverviewLink();
156 void ShowBluetoothPairingLink(); 183 void ShowBluetoothPairingLink();
157 void ShowBluetoothAdapterOffLink(); 184 void ShowBluetoothAdapterOffLink();
158 185
159 int render_process_id_; 186 int render_process_id_;
160 187
161 // Maps a (thread_id,request_id) to information about its requestDevice call, 188 // Maps a (thread_id,request_id) to information about its requestDevice call,
162 // including the chooser dialog. 189 // including the chooser dialog.
163 // An entry is added to this map in OnRequestDevice, and should be removed 190 // An entry is added to this map in OnRequestDevice, and should be removed
164 // again everywhere a requestDevice() reply is sent. 191 // again everywhere a requestDevice() reply is sent.
165 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; 192 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_;
166 193
167 // Maps to get the object's parent based on it's instanceID 194 // Maps to get the object's parent based on it's instanceID
168 // Map of service_instance_id to device_instance_id. 195 // Map of service_instance_id to device_instance_id.
169 std::map<std::string, std::string> service_to_device_; 196 std::map<std::string, std::string> service_to_device_;
170 // Map of characteristic_instance_id to service_instance_id. 197 // Map of characteristic_instance_id to service_instance_id.
171 std::map<std::string, std::string> characteristic_to_service_; 198 std::map<std::string, std::string> characteristic_to_service_;
172 199
200 // Map that matches characteristic_instance_id to notify session.
201 base::ScopedPtrMap<std::string,
202 scoped_ptr<device::BluetoothGattNotifySession>>
203 characteristic_id_to_notify_session_;
204
173 // Defines how long to scan for and how long to discover services for. 205 // Defines how long to scan for and how long to discover services for.
174 int current_delay_time_; 206 int current_delay_time_;
175 207
176 // A BluetoothAdapter instance representing an adapter of the system. 208 // A BluetoothAdapter instance representing an adapter of the system.
177 scoped_refptr<device::BluetoothAdapter> adapter_; 209 scoped_refptr<device::BluetoothAdapter> adapter_;
178 210
179 // Automatically stops Bluetooth discovery a set amount of time after it was 211 // Automatically stops Bluetooth discovery a set amount of time after it was
180 // started. We have a single timer for all of Web Bluetooth because it's 212 // started. We have a single timer for all of Web Bluetooth because it's
181 // simpler than tracking timeouts for each RequestDeviceSession individually, 213 // simpler than tracking timeouts for each RequestDeviceSession individually,
182 // and because there's no harm in extending the length of a few discovery 214 // and because there's no harm in extending the length of a few discovery
183 // sessions when other sessions are active. 215 // sessions when other sessions are active.
184 base::Timer discovery_session_timer_; 216 base::Timer discovery_session_timer_;
185 217
186 // Must be last member, see base/memory/weak_ptr.h documentation 218 // Must be last member, see base/memory/weak_ptr.h documentation
187 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; 219 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_;
188 220
189 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); 221 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost);
190 }; 222 };
191 223
192 } // namespace content 224 } // namespace content
193 225
194 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ 226 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698