Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ |
| 6 | #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ |
| 7 | |
| 8 | #include <string> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 9 | #include <utility> |
| 10 | #include <vector> |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 11 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
| 13 | #include "base/memory/scoped_vector.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 14 | #include "base/memory/weak_ptr.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 15 | #include "base/threading/thread_checker.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 16 | #include "device/bluetooth/bluetooth_adapter.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 17 | #include "device/bluetooth/bluetooth_task_manager_win.h" |
| 18 | |
| 19 | namespace base { |
| 20 | |
| 21 | class SequencedTaskRunner; |
| 22 | |
| 23 | } // namespace base |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 24 | |
| 25 | namespace device { |
| 26 | |
| 27 | class BluetoothAdapterFactory; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 28 | class BluetoothAdapterWinTest; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 29 | class BluetoothDevice; |
| 30 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 31 | class BluetoothAdapterWin : public BluetoothAdapter, |
| 32 | public BluetoothTaskManagerWin::Observer { |
| 33 | public: |
| 34 | typedef base::Callback<void()> InitCallback; |
| 35 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 36 | // BluetoothAdapter override |
| 37 | virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
| 38 | virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 39 | virtual bool IsInitialized() const OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 40 | virtual bool IsPresent() const OVERRIDE; |
| 41 | virtual bool IsPowered() const OVERRIDE; |
| 42 | virtual void SetPowered( |
| 43 | bool powered, |
| 44 | const base::Closure& callback, |
| 45 | const ErrorCallback& error_callback) OVERRIDE; |
| 46 | virtual bool IsDiscovering() const OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 47 | virtual bool IsScanning() const OVERRIDE; |
| 48 | |
| 49 | virtual void StartDiscovering( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 50 | const base::Closure& callback, |
| 51 | const ErrorCallback& error_callback) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 52 | virtual void StopDiscovering( |
| 53 | const base::Closure& callback, |
| 54 | const ErrorCallback& error_callback) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 55 | virtual void ReadLocalOutOfBandPairingData( |
| 56 | const BluetoothOutOfBandPairingDataCallback& callback, |
| 57 | const ErrorCallback& error_callback) OVERRIDE; |
| 58 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 59 | // BluetoothTaskManagerWin::Observer override |
| 60 | virtual void AdapterStateChanged( |
| 61 | const BluetoothTaskManagerWin::AdapterState& state) OVERRIDE; |
| 62 | virtual void DiscoveryStarted(bool success) OVERRIDE; |
| 63 | virtual void DiscoveryStopped() OVERRIDE; |
| 64 | virtual void ScanningChanged(bool scanning) OVERRIDE; |
| 65 | virtual void DevicesDiscovered( |
| 66 | const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices) |
| 67 | OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 68 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 69 | private: |
| 70 | friend class BluetoothAdapterFactory; |
| 71 | friend class BluetoothAdapterWinTest; |
| 72 | |
| 73 | enum DiscoveryStatus { |
| 74 | NOT_DISCOVERING, |
| 75 | DISCOVERY_STARTING, |
| 76 | DISCOVERING, |
| 77 | DISCOVERY_STOPPING |
| 78 | }; |
| 79 | |
| 80 | explicit BluetoothAdapterWin(const InitCallback& init_callback); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 81 | virtual ~BluetoothAdapterWin(); |
| 82 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 83 | void TrackDefaultAdapter(); |
| 84 | void TrackTestAdapter( |
| 85 | scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 86 | scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner); |
| 87 | |
| 88 | void MaybePostStartDiscoveryTask(); |
| 89 | void MaybePostStopDiscoveryTask(); |
| 90 | |
| 91 | InitCallback init_callback_; |
| 92 | bool initialized_; |
| 93 | bool powered_; |
| 94 | DiscoveryStatus discovery_status_; |
| 95 | bool scanning_; |
| 96 | |
| 97 | std::vector<std::pair<base::Closure, ErrorCallback> > |
| 98 | on_start_discovery_callbacks_; |
| 99 | std::vector<base::Closure> on_stop_discovery_callbacks_; |
| 100 | size_t num_discovery_listeners_; |
| 101 | |
| 102 | scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 103 | scoped_refptr<BluetoothTaskManagerWin> task_manager_; |
| 104 | |
| 105 | base::ThreadChecker thread_checker_; |
| 106 | |
| 107 | // List of observers interested in event notifications from us. |
| 108 | ObserverList<BluetoothAdapter::Observer> observers_; |
| 109 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 110 | // NOTE: This should remain the last member so it'll be destroyed and |
| 111 | // invalidate its weak pointers before any other members are destroyed. |
| 112 | base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_; |
| 113 | |
| 114 | DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin); |
| 115 | }; |
| 116 | |
| 117 | } // namespace device |
| 118 | |
| 119 | #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ |