Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: device/bluetooth/bluetooth_adapter_win.h

Issue 11411130: Implemented BluetoothTaskManagerWin class. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed unnecessary lines. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
12 13
13 namespace device { 14 namespace device {
14 15
15 class BluetoothAdapterFactory; 16 class BluetoothAdapterFactory;
16 class BluetoothAdapterWinTest; 17 class BluetoothAdapterWinTest;
17 class BluetoothDevice; 18 class BluetoothDevice;
19 class BluetoothManagerWin;
18 20
19 class BluetoothAdapterWin : public BluetoothAdapter { 21 class BluetoothAdapterWin : public BluetoothAdapter {
20 public: 22 public:
21 // BluetoothAdapter override 23 // BluetoothAdapter override
22 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; 24 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
23 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; 25 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
24 virtual bool IsPresent() const OVERRIDE; 26 virtual bool IsPresent() const OVERRIDE;
25 virtual bool IsPowered() const OVERRIDE; 27 virtual bool IsPowered() const OVERRIDE;
26 virtual void SetPowered( 28 virtual void SetPowered(
27 bool powered, 29 bool powered,
28 const base::Closure& callback, 30 const base::Closure& callback,
29 const ErrorCallback& error_callback) OVERRIDE; 31 const ErrorCallback& error_callback) OVERRIDE;
30 virtual bool IsDiscovering() const OVERRIDE; 32 virtual bool IsDiscovering() const OVERRIDE;
31 virtual void SetDiscovering( 33 virtual void SetDiscovering(
32 bool discovering, 34 bool discovering,
33 const base::Closure& callback, 35 const base::Closure& callback,
34 const ErrorCallback& error_callback) OVERRIDE; 36 const ErrorCallback& error_callback) OVERRIDE;
35 virtual ConstDeviceList GetDevices() const OVERRIDE; 37 virtual ConstDeviceList GetDevices() const OVERRIDE;
36 virtual BluetoothDevice* GetDevice(const std::string& address) OVERRIDE; 38 virtual BluetoothDevice* GetDevice(const std::string& address) OVERRIDE;
37 virtual const BluetoothDevice* GetDevice( 39 virtual const BluetoothDevice* GetDevice(
38 const std::string& address) const OVERRIDE; 40 const std::string& address) const OVERRIDE;
39 virtual void ReadLocalOutOfBandPairingData( 41 virtual void ReadLocalOutOfBandPairingData(
40 const BluetoothOutOfBandPairingDataCallback& callback, 42 const BluetoothOutOfBandPairingDataCallback& callback,
41 const ErrorCallback& error_callback) OVERRIDE; 43 const ErrorCallback& error_callback) OVERRIDE;
42 44
45 // Called by BluetoothManagerWin thread to return the adapter_handle.
46 void OnAdapterHandleAvailable(HANDLE adapter_handle);
47
48 void SetBluetoothManagerForTest(BluetoothManagerWin* manager);
49
43 protected: 50 protected:
44 BluetoothAdapterWin(); 51 BluetoothAdapterWin();
45 virtual ~BluetoothAdapterWin(); 52 virtual ~BluetoothAdapterWin();
46 53
47 virtual void UpdateAdapterState(); 54 virtual void UpdateAdapterState(HANDLE adapter_handle);
48 55
49 private: 56 private:
50 friend class BluetoothAdapterFactory; 57 friend class BluetoothAdapterFactory;
51 friend class BluetoothAdapterWinTest; 58 friend class BluetoothAdapterWinTest;
52 59
53 // Obtains the default adapter info (the first bluetooth radio info found on 60 // Starts BluetoothManagerWin thread to obtain the default adapter info.
54 // the system) and tracks future changes to it.
55 void TrackDefaultAdapter(); 61 void TrackDefaultAdapter();
56 62
57 void PollAdapterState();
58
59 static const int kPollIntervalMs; 63 static const int kPollIntervalMs;
60 64
61 bool powered_; 65 bool powered_;
62 66
67 // Holding scoped_ptr guarantees that BluetoothAdapterWin will always outlive
68 // BluetoothManagerWin thread.
69 scoped_ptr<BluetoothManagerWin> manager_;
70
71 HANDLE adapter_handle_;
72
63 // NOTE: This should remain the last member so it'll be destroyed and 73 // NOTE: This should remain the last member so it'll be destroyed and
64 // invalidate its weak pointers before any other members are destroyed. 74 // invalidate its weak pointers before any other members are destroyed.
65 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_; 75 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_;
66 76
67 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin); 77 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin);
68 }; 78 };
69 79
70 } // namespace device 80 } // namespace device
71 81
72 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_ 82 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698