 Chromium Code Reviews
 Chromium Code Reviews Issue 1382743002:
  bluetooth: Add characteristicvaluechanged event  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1
    
  
    Issue 1382743002:
  bluetooth: Add characteristicvaluechanged event  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1| 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/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 Loading... | |
| 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 void NotifyActiveCharacteristic(int thread_id, | |
| 
Jeffrey Yasskin
2015/10/15 23:00:51
Comment what this function does, since it's not a
 
ortuno
2015/10/16 01:24:21
Done.
 | |
| 86 const std::string id, | |
| 87 const std::vector<uint8> value); | |
| 
Jeffrey Yasskin
2015/10/15 23:00:51
Pass these two arguments by const&. Eventually we'
 
ortuno
2015/10/16 01:24:21
Done.
 | |
| 88 | |
| 85 // IPC Handlers, see definitions in bluetooth_messages.h. | 89 // IPC Handlers, see definitions in bluetooth_messages.h. | 
| 86 void OnRequestDevice( | 90 void OnRequestDevice( | 
| 87 int thread_id, | 91 int thread_id, | 
| 88 int request_id, | 92 int request_id, | 
| 89 int frame_routing_id, | 93 int frame_routing_id, | 
| 90 const std::vector<content::BluetoothScanFilter>& filters, | 94 const std::vector<content::BluetoothScanFilter>& filters, | 
| 91 const std::vector<device::BluetoothUUID>& optional_services); | 95 const std::vector<device::BluetoothUUID>& optional_services); | 
| 92 void OnConnectGATT(int thread_id, int request_id, | 96 void OnConnectGATT(int thread_id, int request_id, | 
| 93 const std::string& device_instance_id); | 97 const std::string& device_instance_id); | 
| 94 void OnGetPrimaryService(int thread_id, | 98 void OnGetPrimaryService(int thread_id, | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 105 void OnWriteValue(int thread_id, | 109 void OnWriteValue(int thread_id, | 
| 106 int request_id, | 110 int request_id, | 
| 107 const std::string& characteristic_instance_id, | 111 const std::string& characteristic_instance_id, | 
| 108 const std::vector<uint8_t>& value); | 112 const std::vector<uint8_t>& value); | 
| 109 void OnStartNotifications(int thread_id, | 113 void OnStartNotifications(int thread_id, | 
| 110 int request_id, | 114 int request_id, | 
| 111 const std::string& characteristic_instance_id); | 115 const std::string& characteristic_instance_id); | 
| 112 void OnStopNotifications(int thread_id, | 116 void OnStopNotifications(int thread_id, | 
| 113 int request_id, | 117 int request_id, | 
| 114 const std::string& characteristic_instance_id); | 118 const std::string& characteristic_instance_id); | 
| 119 void OnRegisterCharacteristicObject( | |
| 120 int thread_id, | |
| 121 const std::string& characteristic_instance_id); | |
| 122 void OnUnregisterCharacteristicObject( | |
| 123 int thread_id, | |
| 124 const std::string& characteristic_instance_id); | |
| 115 | 125 | 
| 116 // Callbacks for BluetoothAdapter::StartDiscoverySession. | 126 // Callbacks for BluetoothAdapter::StartDiscoverySession. | 
| 117 void OnDiscoverySessionStarted( | 127 void OnDiscoverySessionStarted( | 
| 118 int chooser_id, | 128 int chooser_id, | 
| 119 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 129 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 
| 120 void OnDiscoverySessionStartedError(int chooser_id); | 130 void OnDiscoverySessionStartedError(int chooser_id); | 
| 121 | 131 | 
| 122 // BluetoothChooser::EventHandler: | 132 // BluetoothChooser::EventHandler: | 
| 123 void OnBluetoothChooserEvent(int chooser_id, | 133 void OnBluetoothChooserEvent(int chooser_id, | 
| 124 BluetoothChooser::Event event, | 134 BluetoothChooser::Event event, | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 // Map of characteristic_instance_id to service_instance_id. | 212 // Map of characteristic_instance_id to service_instance_id. | 
| 203 std::map<std::string, std::string> characteristic_to_service_; | 213 std::map<std::string, std::string> characteristic_to_service_; | 
| 204 | 214 | 
| 205 // Map that matches characteristic_instance_id to notify session. | 215 // Map that matches characteristic_instance_id to notify session. | 
| 206 // TODO(ortuno): Also key by thread_id once support for web workers, | 216 // TODO(ortuno): Also key by thread_id once support for web workers, | 
| 207 // is added: http://crbug.com/537372 | 217 // is added: http://crbug.com/537372 | 
| 208 base::ScopedPtrMap<std::string, | 218 base::ScopedPtrMap<std::string, | 
| 209 scoped_ptr<device::BluetoothGattNotifySession>> | 219 scoped_ptr<device::BluetoothGattNotifySession>> | 
| 210 characteristic_id_to_notify_session_; | 220 characteristic_id_to_notify_session_; | 
| 211 | 221 | 
| 222 // Map of characteristic_instance_id to a set of thread ids. | |
| 223 // A thread_id in the set represents a BluetoothDispatcher that | |
| 224 // needs to be notified of changes to the characteristic. | |
| 225 std::map<std::string, std::set<int>> active_characteristic_threads_; | |
| 226 | |
| 212 // Defines how long to scan for and how long to discover services for. | 227 // Defines how long to scan for and how long to discover services for. | 
| 213 int current_delay_time_; | 228 int current_delay_time_; | 
| 214 | 229 | 
| 215 // A BluetoothAdapter instance representing an adapter of the system. | 230 // A BluetoothAdapter instance representing an adapter of the system. | 
| 216 scoped_refptr<device::BluetoothAdapter> adapter_; | 231 scoped_refptr<device::BluetoothAdapter> adapter_; | 
| 217 | 232 | 
| 218 // Automatically stops Bluetooth discovery a set amount of time after it was | 233 // 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 | 234 // started. We have a single timer for all of Web Bluetooth because it's | 
| 220 // simpler than tracking timeouts for each RequestDeviceSession individually, | 235 // simpler than tracking timeouts for each RequestDeviceSession individually, | 
| 221 // and because there's no harm in extending the length of a few discovery | 236 // and because there's no harm in extending the length of a few discovery | 
| 222 // sessions when other sessions are active. | 237 // sessions when other sessions are active. | 
| 223 base::Timer discovery_session_timer_; | 238 base::Timer discovery_session_timer_; | 
| 224 | 239 | 
| 225 // Retain BluetoothGattConnection objects to keep connections open. | 240 // Retain BluetoothGattConnection objects to keep connections open. | 
| 226 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643 | 241 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643 | 
| 227 ScopedVector<device::BluetoothGattConnection> connections_; | 242 ScopedVector<device::BluetoothGattConnection> connections_; | 
| 228 | 243 | 
| 229 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and | 244 // |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 | 245 // 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. | 246 // copies verify they are also used on the UI thread. | 
| 232 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; | 247 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; | 
| 233 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 248 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 
| 234 | 249 | 
| 235 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 250 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 
| 236 }; | 251 }; | 
| 237 | 252 | 
| 238 } // namespace content | 253 } // namespace content | 
| 239 | 254 | 
| 240 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 255 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 
| OLD | NEW |