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/scoped_ptr.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_polling_thread_win.h" | |
15 | |
16 namespace base { | |
17 | |
18 class ThreadChecker; | |
bryeung
2012/11/28 16:26:08
no longer necessary now that you have the header i
youngki
2012/11/28 19:19:13
Done.
| |
19 | |
20 } // namespace base | |
12 | 21 |
13 namespace device { | 22 namespace device { |
14 | 23 |
15 class BluetoothAdapterFactory; | 24 class BluetoothAdapterFactory; |
16 class BluetoothAdapterWinTest; | 25 class BluetoothAdapterWinTest; |
17 class BluetoothDevice; | 26 class BluetoothDevice; |
18 | 27 |
19 class BluetoothAdapterWin : public BluetoothAdapter { | 28 class BluetoothAdapterWin : public BluetoothAdapter, |
29 private BluetoothPollingThreadWin::Observer { | |
20 public: | 30 public: |
21 // BluetoothAdapter override | 31 // BluetoothAdapter override |
22 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; | 32 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
23 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; | 33 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
24 virtual bool IsPresent() const OVERRIDE; | 34 virtual bool IsPresent() const OVERRIDE; |
25 virtual bool IsPowered() const OVERRIDE; | 35 virtual bool IsPowered() const OVERRIDE; |
26 virtual void SetPowered( | 36 virtual void SetPowered( |
27 bool powered, | 37 bool powered, |
28 const base::Closure& callback, | 38 const base::Closure& callback, |
29 const ErrorCallback& error_callback) OVERRIDE; | 39 const ErrorCallback& error_callback) OVERRIDE; |
30 virtual bool IsDiscovering() const OVERRIDE; | 40 virtual bool IsDiscovering() const OVERRIDE; |
31 virtual void SetDiscovering( | 41 virtual void SetDiscovering( |
32 bool discovering, | 42 bool discovering, |
33 const base::Closure& callback, | 43 const base::Closure& callback, |
34 const ErrorCallback& error_callback) OVERRIDE; | 44 const ErrorCallback& error_callback) OVERRIDE; |
35 virtual ConstDeviceList GetDevices() const OVERRIDE; | 45 virtual ConstDeviceList GetDevices() const OVERRIDE; |
36 virtual BluetoothDevice* GetDevice(const std::string& address) OVERRIDE; | 46 virtual BluetoothDevice* GetDevice(const std::string& address) OVERRIDE; |
37 virtual const BluetoothDevice* GetDevice( | 47 virtual const BluetoothDevice* GetDevice( |
38 const std::string& address) const OVERRIDE; | 48 const std::string& address) const OVERRIDE; |
39 virtual void ReadLocalOutOfBandPairingData( | 49 virtual void ReadLocalOutOfBandPairingData( |
40 const BluetoothOutOfBandPairingDataCallback& callback, | 50 const BluetoothOutOfBandPairingDataCallback& callback, |
41 const ErrorCallback& error_callback) OVERRIDE; | 51 const ErrorCallback& error_callback) OVERRIDE; |
42 | 52 |
53 void SetBluetoothPollingThreadForTest(BluetoothPollingThreadWin* manager); | |
54 | |
43 protected: | 55 protected: |
44 BluetoothAdapterWin(); | 56 BluetoothAdapterWin(); |
45 virtual ~BluetoothAdapterWin(); | 57 virtual ~BluetoothAdapterWin(); |
46 | 58 |
47 virtual void UpdateAdapterState(); | |
48 | |
49 private: | 59 private: |
50 friend class BluetoothAdapterFactory; | 60 friend class BluetoothAdapterFactory; |
51 friend class BluetoothAdapterWinTest; | 61 friend class BluetoothAdapterWinTest; |
52 | 62 |
53 // Obtains the default adapter info (the first bluetooth radio info found on | 63 // BluetoothPollingThreadWin::Observer override |
54 // the system) and tracks future changes to it. | 64 virtual void AdapterStateChanged( |
65 const BluetoothPollingThreadWin::AdapterState& state) OVERRIDE; | |
66 | |
67 // Starts BluetoothPollingThreadWin thread to obtain the default adapter info. | |
55 void TrackDefaultAdapter(); | 68 void TrackDefaultAdapter(); |
56 | 69 |
57 void PollAdapterState(); | |
58 | |
59 static const int kPollIntervalMs; | |
60 | |
61 bool powered_; | 70 bool powered_; |
62 | 71 |
72 // Holding scoped_ptr guarantees that BluetoothAdapterWin will always outlive | |
73 // BluetoothPollingThreadWin thread. | |
74 scoped_ptr<BluetoothPollingThreadWin> thread_; | |
bryeung
2012/11/28 16:26:08
it occurs to me that you could get an equivalently
youngki
2012/11/28 19:19:13
My only concern is testing; I was going to replace
| |
75 | |
76 base::ThreadChecker thread_checker_; | |
77 | |
63 // NOTE: This should remain the last member so it'll be destroyed and | 78 // NOTE: This should remain the last member so it'll be destroyed and |
64 // invalidate its weak pointers before any other members are destroyed. | 79 // invalidate its weak pointers before any other members are destroyed. |
65 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_; | 80 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_; |
66 | 81 |
67 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin); | 82 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin); |
68 }; | 83 }; |
69 | 84 |
70 } // namespace device | 85 } // namespace device |
71 | 86 |
72 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ | 87 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ |
OLD | NEW |