Fix build break
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_win.h
blob0265624dd997a6037a8ef93085f95c5f3335dfd6
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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h"
16 #include "device/bluetooth/bluetooth_adapter.h"
17 #include "device/bluetooth/bluetooth_task_manager_win.h"
19 namespace base {
21 class SequencedTaskRunner;
23 } // namespace base
25 namespace device {
27 class BluetoothAdapterFactory;
28 class BluetoothAdapterWinTest;
29 class BluetoothDevice;
31 class BluetoothAdapterWin : public BluetoothAdapter,
32 public BluetoothTaskManagerWin::Observer {
33 public:
34 typedef base::Callback<void()> InitCallback;
36 // BluetoothAdapter override
37 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
38 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE;
39 virtual std::string GetAddress() const OVERRIDE;
40 virtual std::string GetName() const OVERRIDE;
41 virtual bool IsInitialized() const OVERRIDE;
42 virtual bool IsPresent() const OVERRIDE;
43 virtual bool IsPowered() const OVERRIDE;
44 virtual void SetPowered(
45 bool powered,
46 const base::Closure& callback,
47 const ErrorCallback& error_callback) OVERRIDE;
48 virtual bool IsDiscovering() const OVERRIDE;
50 virtual void StartDiscovering(
51 const base::Closure& callback,
52 const ErrorCallback& error_callback) OVERRIDE;
53 virtual void StopDiscovering(
54 const base::Closure& callback,
55 const ErrorCallback& error_callback) OVERRIDE;
56 virtual void ReadLocalOutOfBandPairingData(
57 const BluetoothOutOfBandPairingDataCallback& callback,
58 const ErrorCallback& error_callback) OVERRIDE;
60 // BluetoothTaskManagerWin::Observer override
61 virtual void AdapterStateChanged(
62 const BluetoothTaskManagerWin::AdapterState& state) OVERRIDE;
63 virtual void DiscoveryStarted(bool success) OVERRIDE;
64 virtual void DiscoveryStopped() OVERRIDE;
65 virtual void DevicesDiscovered(
66 const ScopedVector<BluetoothTaskManagerWin::DeviceState>& devices)
67 OVERRIDE;
69 private:
70 friend class BluetoothAdapterFactory;
71 friend class BluetoothAdapterWinTest;
73 enum DiscoveryStatus {
74 NOT_DISCOVERING,
75 DISCOVERY_STARTING,
76 DISCOVERING,
77 DISCOVERY_STOPPING
80 explicit BluetoothAdapterWin(const InitCallback& init_callback);
81 virtual ~BluetoothAdapterWin();
83 void Init();
84 void InitForTest(
85 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
86 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner);
88 void MaybePostStartDiscoveryTask();
89 void MaybePostStopDiscoveryTask();
91 InitCallback init_callback_;
92 std::string address_;
93 std::string name_;
94 bool initialized_;
95 bool powered_;
96 DiscoveryStatus discovery_status_;
98 std::vector<std::pair<base::Closure, ErrorCallback> >
99 on_start_discovery_callbacks_;
100 std::vector<base::Closure> on_stop_discovery_callbacks_;
101 size_t num_discovery_listeners_;
103 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
104 scoped_refptr<BluetoothTaskManagerWin> task_manager_;
106 base::ThreadChecker thread_checker_;
108 // List of observers interested in event notifications from us.
109 ObserverList<BluetoothAdapter::Observer> observers_;
111 // NOTE: This should remain the last member so it'll be destroyed and
112 // invalidate its weak pointers before any other members are destroyed.
113 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_;
115 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin);
118 } // namespace device
120 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_