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 EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_ |
6 #define EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_ | 6 #define EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "device/bluetooth/bluetooth_advertisement.h" | |
10 #include "extensions/browser/api/api_resource_manager.h" | |
9 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event _router.h" | 11 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event _router.h" |
10 #include "extensions/browser/browser_context_keyed_api_factory.h" | 12 #include "extensions/browser/browser_context_keyed_api_factory.h" |
11 #include "extensions/browser/extension_function.h" | 13 #include "extensions/browser/extension_function.h" |
12 #include "extensions/browser/extension_function_histogram_value.h" | 14 #include "extensions/browser/extension_function_histogram_value.h" |
13 | 15 |
14 namespace extensions { | 16 namespace extensions { |
15 | 17 |
18 class BluetoothApiAdvertisement; | |
16 class BluetoothLowEnergyEventRouter; | 19 class BluetoothLowEnergyEventRouter; |
17 | 20 |
18 // The profile-keyed service that manages the bluetoothLowEnergy extension API. | 21 // The profile-keyed service that manages the bluetoothLowEnergy extension API. |
19 class BluetoothLowEnergyAPI : public BrowserContextKeyedAPI { | 22 class BluetoothLowEnergyAPI : public BrowserContextKeyedAPI { |
20 public: | 23 public: |
21 static BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>* | 24 static BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>* |
22 GetFactoryInstance(); | 25 GetFactoryInstance(); |
23 | 26 |
24 // Convenience method to get the BluetoothLowEnergy API for a browser context. | 27 // Convenience method to get the BluetoothLowEnergy API for a browser context. |
25 static BluetoothLowEnergyAPI* Get(content::BrowserContext* context); | 28 static BluetoothLowEnergyAPI* Get(content::BrowserContext* context); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 private: | 325 private: |
323 // Success and error callbacks, called by | 326 // Success and error callbacks, called by |
324 // BluetoothLowEnergyEventRouter::WriteDescriptorValue. | 327 // BluetoothLowEnergyEventRouter::WriteDescriptorValue. |
325 void SuccessCallback(); | 328 void SuccessCallback(); |
326 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status); | 329 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status); |
327 | 330 |
328 // The instance ID of the requested descriptor. | 331 // The instance ID of the requested descriptor. |
329 std::string instance_id_; | 332 std::string instance_id_; |
330 }; | 333 }; |
331 | 334 |
335 class BluetoothLowEnergyAdvertisementFunction | |
336 : public BluetoothLowEnergyExtensionFunction { | |
337 public: | |
338 BluetoothLowEnergyAdvertisementFunction(); | |
339 | |
340 protected: | |
341 ~BluetoothLowEnergyAdvertisementFunction() override; | |
342 | |
343 // Takes ownership. | |
344 int AddAdvertisement(BluetoothApiAdvertisement* advertisement); | |
345 BluetoothApiAdvertisement* GetAdvertisement(int advertisement_id); | |
346 void RemoveAdvertisement(int advertisement_id); | |
347 | |
348 // ExtensionFunction override. | |
349 bool RunAsync() override; | |
350 | |
351 private: | |
352 void Initialize(); | |
353 | |
354 ApiResourceManager<BluetoothApiAdvertisement>* advertisements_manager_; | |
355 | |
356 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyAdvertisementFunction); | |
357 }; | |
358 | |
332 class BluetoothLowEnergyRegisterAdvertisementFunction | 359 class BluetoothLowEnergyRegisterAdvertisementFunction |
333 : public BluetoothLowEnergyExtensionFunction { | 360 : public BluetoothLowEnergyAdvertisementFunction { |
armansito
2015/05/08 22:46:13
I'm trying to understand why this base class is ne
rkc
2015/05/11 21:59:35
Explained offline.
| |
334 public: | 361 public: |
335 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.registerAdvertisement", | 362 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.registerAdvertisement", |
336 BLUETOOTHLOWENERGY_REGISTERADVERTISEMENT); | 363 BLUETOOTHLOWENERGY_REGISTERADVERTISEMENT); |
337 | 364 |
338 protected: | 365 protected: |
339 ~BluetoothLowEnergyRegisterAdvertisementFunction() override {} | 366 ~BluetoothLowEnergyRegisterAdvertisementFunction() override {} |
340 | 367 |
341 // BluetoothLowEnergyExtensionFunction override. | 368 // BluetoothLowEnergyExtensionFunction override. |
342 bool DoWork() override; | 369 bool DoWork() override; |
343 | 370 |
344 private: | 371 private: |
345 // Success and error callbacks, called by | 372 void SuccessCallback(scoped_refptr<device::BluetoothAdvertisement>); |
346 // BluetoothLowEnergyEventRouter::WriteDescriptorValue. | 373 void ErrorCallback(device::BluetoothAdvertisement::ErrorCode status); |
347 void SuccessCallback(); | |
348 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status); | |
349 | 374 |
350 // The instance ID of the requested descriptor. | 375 // The instance ID of the requested descriptor. |
351 std::string instance_id_; | 376 std::string instance_id_; |
352 }; | 377 }; |
353 | 378 |
354 class BluetoothLowEnergyUnregisterAdvertisementFunction | 379 class BluetoothLowEnergyUnregisterAdvertisementFunction |
355 : public BluetoothLowEnergyExtensionFunction { | 380 : public BluetoothLowEnergyAdvertisementFunction { |
356 public: | 381 public: |
357 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.unregisterAdvertisement", | 382 DECLARE_EXTENSION_FUNCTION("bluetoothLowEnergy.unregisterAdvertisement", |
358 BLUETOOTHLOWENERGY_UNREGISTERADVERTISEMENT); | 383 BLUETOOTHLOWENERGY_UNREGISTERADVERTISEMENT); |
359 | 384 |
360 protected: | 385 protected: |
361 ~BluetoothLowEnergyUnregisterAdvertisementFunction() override {} | 386 ~BluetoothLowEnergyUnregisterAdvertisementFunction() override {} |
362 | 387 |
363 // BluetoothLowEnergyExtensionFunction override. | 388 // BluetoothLowEnergyExtensionFunction override. |
364 bool DoWork() override; | 389 bool DoWork() override; |
365 | 390 |
366 private: | 391 private: |
367 // Success and error callbacks, called by | 392 void SuccessCallback(int advertisement_id); |
368 // BluetoothLowEnergyEventRouter::WriteDescriptorValue. | 393 void ErrorCallback(int advertisement_id, |
369 void SuccessCallback(); | 394 device::BluetoothAdvertisement::ErrorCode status); |
370 void ErrorCallback(BluetoothLowEnergyEventRouter::Status status); | |
371 | 395 |
372 // The instance ID of the requested descriptor. | 396 // The instance ID of the requested descriptor. |
373 std::string instance_id_; | 397 std::string instance_id_; |
374 }; | 398 }; |
375 | 399 |
376 } // namespace core_api | 400 } // namespace core_api |
377 } // namespace extensions | 401 } // namespace extensions |
378 | 402 |
379 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_ H_ | 403 #endif // EXTENSIONS_BROWSER_API_BLUETOOTH_LOW_ENERGY_BLUETOOTH_LOW_ENERGY_API_ H_ |
OLD | NEW |