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_
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"
21 class SequencedTaskRunner
;
27 class BluetoothAdapterFactory
;
28 class BluetoothAdapterWinTest
;
29 class BluetoothDevice
;
31 class BluetoothAdapterWin
: public BluetoothAdapter
,
32 public BluetoothTaskManagerWin::Observer
{
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(
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
)
70 friend class BluetoothAdapterFactory
;
71 friend class BluetoothAdapterWinTest
;
73 enum DiscoveryStatus
{
80 explicit BluetoothAdapterWin(const InitCallback
& init_callback
);
81 virtual ~BluetoothAdapterWin();
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_
;
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_