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