OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/threading/thread_checker.h" |
11 #include "device/bluetooth/bluetooth_adapter.h" | 13 #include "device/bluetooth/bluetooth_adapter.h" |
| 14 #include "device/bluetooth/bluetooth_task_manager_win.h" |
12 | 15 |
13 namespace device { | 16 namespace device { |
14 | 17 |
15 class BluetoothAdapterFactory; | 18 class BluetoothAdapterFactory; |
16 class BluetoothAdapterWinTest; | 19 class BluetoothAdapterWinTest; |
17 class BluetoothDevice; | 20 class BluetoothDevice; |
18 | 21 |
19 class BluetoothAdapterWin : public BluetoothAdapter { | 22 class BluetoothAdapterWin : public BluetoothAdapter, |
| 23 public BluetoothTaskManagerWin::Observer { |
20 public: | 24 public: |
21 // BluetoothAdapter override | 25 // BluetoothAdapter override |
22 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; | 26 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
23 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; | 27 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
24 virtual bool IsPresent() const OVERRIDE; | 28 virtual bool IsPresent() const OVERRIDE; |
25 virtual bool IsPowered() const OVERRIDE; | 29 virtual bool IsPowered() const OVERRIDE; |
26 virtual void SetPowered( | 30 virtual void SetPowered( |
27 bool powered, | 31 bool powered, |
28 const base::Closure& callback, | 32 const base::Closure& callback, |
29 const ErrorCallback& error_callback) OVERRIDE; | 33 const ErrorCallback& error_callback) OVERRIDE; |
30 virtual bool IsDiscovering() const OVERRIDE; | 34 virtual bool IsDiscovering() const OVERRIDE; |
31 virtual void SetDiscovering( | 35 virtual void SetDiscovering( |
32 bool discovering, | 36 bool discovering, |
33 const base::Closure& callback, | 37 const base::Closure& callback, |
34 const ErrorCallback& error_callback) OVERRIDE; | 38 const ErrorCallback& error_callback) OVERRIDE; |
35 virtual ConstDeviceList GetDevices() const OVERRIDE; | 39 virtual ConstDeviceList GetDevices() const OVERRIDE; |
36 virtual BluetoothDevice* GetDevice(const std::string& address) OVERRIDE; | 40 virtual BluetoothDevice* GetDevice(const std::string& address) OVERRIDE; |
37 virtual const BluetoothDevice* GetDevice( | 41 virtual const BluetoothDevice* GetDevice( |
38 const std::string& address) const OVERRIDE; | 42 const std::string& address) const OVERRIDE; |
39 virtual void ReadLocalOutOfBandPairingData( | 43 virtual void ReadLocalOutOfBandPairingData( |
40 const BluetoothOutOfBandPairingDataCallback& callback, | 44 const BluetoothOutOfBandPairingDataCallback& callback, |
41 const ErrorCallback& error_callback) OVERRIDE; | 45 const ErrorCallback& error_callback) OVERRIDE; |
42 | 46 |
| 47 // BluetoothTaskManagerWin::Observer override |
| 48 virtual void AdapterStateChanged( |
| 49 const BluetoothTaskManagerWin::AdapterState& state) OVERRIDE; |
| 50 |
43 protected: | 51 protected: |
| 52 friend class BluetoothAdapterWinTest; |
| 53 |
44 BluetoothAdapterWin(); | 54 BluetoothAdapterWin(); |
45 virtual ~BluetoothAdapterWin(); | 55 virtual ~BluetoothAdapterWin(); |
46 | 56 |
47 virtual void UpdateAdapterState(); | |
48 | |
49 private: | 57 private: |
50 friend class BluetoothAdapterFactory; | 58 friend class BluetoothAdapterFactory; |
51 friend class BluetoothAdapterWinTest; | |
52 | 59 |
53 // Obtains the default adapter info (the first bluetooth radio info found on | |
54 // the system) and tracks future changes to it. | |
55 void TrackDefaultAdapter(); | 60 void TrackDefaultAdapter(); |
56 | 61 |
57 void PollAdapterState(); | |
58 | |
59 static const int kPollIntervalMs; | |
60 | |
61 bool powered_; | 62 bool powered_; |
62 | 63 |
| 64 scoped_refptr<BluetoothTaskManagerWin> task_manager_; |
| 65 |
| 66 base::ThreadChecker thread_checker_; |
| 67 |
63 // NOTE: This should remain the last member so it'll be destroyed and | 68 // NOTE: This should remain the last member so it'll be destroyed and |
64 // invalidate its weak pointers before any other members are destroyed. | 69 // invalidate its weak pointers before any other members are destroyed. |
65 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_; | 70 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_; |
66 | 71 |
67 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin); | 72 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin); |
68 }; | 73 }; |
69 | 74 |
70 } // namespace device | 75 } // namespace device |
71 | 76 |
72 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ | 77 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ |
OLD | NEW |