[BackgroundSync] Hang the BackgroundSyncManager off of the StoragePartition
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_win.h
blob2b086a2f9fb78e105562f04804fd0041d859f3b7
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 <hash_set>
9 #include <set>
10 #include <string>
11 #include <utility>
12 #include <vector>
14 #include "base/containers/hash_tables.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_vector.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/threading/thread_checker.h"
19 #include "device/bluetooth/bluetooth_adapter.h"
20 #include "device/bluetooth/bluetooth_audio_sink.h"
21 #include "device/bluetooth/bluetooth_discovery_session.h"
22 #include "device/bluetooth/bluetooth_export.h"
23 #include "device/bluetooth/bluetooth_task_manager_win.h"
25 namespace base {
26 class SequencedTaskRunner;
27 class Thread;
28 } // namespace base
30 namespace device {
32 class BluetoothAdapterWinTest;
33 class BluetoothDevice;
34 class BluetoothSocketThread;
36 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterWin
37 : public BluetoothAdapter,
38 public BluetoothTaskManagerWin::Observer {
39 public:
40 static base::WeakPtr<BluetoothAdapter> CreateAdapter(
41 const InitCallback& init_callback);
43 // BluetoothAdapter:
44 virtual void AddObserver(BluetoothAdapter::Observer* observer) override;
45 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) override;
46 virtual std::string GetAddress() const override;
47 virtual std::string GetName() const override;
48 virtual void SetName(const std::string& name,
49 const base::Closure& callback,
50 const ErrorCallback& error_callback) override;
51 virtual bool IsInitialized() const override;
52 virtual bool IsPresent() const override;
53 virtual bool IsPowered() const override;
54 virtual void SetPowered(
55 bool discoverable,
56 const base::Closure& callback,
57 const ErrorCallback& error_callback) override;
58 virtual bool IsDiscoverable() const override;
59 virtual void SetDiscoverable(
60 bool discoverable,
61 const base::Closure& callback,
62 const ErrorCallback& error_callback) override;
63 virtual bool IsDiscovering() const override;
64 virtual void CreateRfcommService(
65 const BluetoothUUID& uuid,
66 const ServiceOptions& options,
67 const CreateServiceCallback& callback,
68 const CreateServiceErrorCallback& error_callback) override;
69 virtual void CreateL2capService(
70 const BluetoothUUID& uuid,
71 const ServiceOptions& options,
72 const CreateServiceCallback& callback,
73 const CreateServiceErrorCallback& error_callback) override;
74 void RegisterAudioSink(
75 const BluetoothAudioSink::Options& options,
76 const AcquiredCallback& callback,
77 const BluetoothAudioSink::ErrorCallback& error_callback) override;
79 // BluetoothTaskManagerWin::Observer override
80 virtual void AdapterStateChanged(
81 const BluetoothTaskManagerWin::AdapterState& state) override;
82 virtual void DiscoveryStarted(bool success) override;
83 virtual void DiscoveryStopped() override;
84 virtual void DevicesPolled(const ScopedVector<
85 BluetoothTaskManagerWin::DeviceState>& devices) override;
87 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner() const {
88 return ui_task_runner_;
90 const scoped_refptr<BluetoothSocketThread>& socket_thread() const {
91 return socket_thread_;
94 protected:
95 // BluetoothAdapter:
96 virtual void RemovePairingDelegateInternal(
97 device::BluetoothDevice::PairingDelegate* pairing_delegate) override;
99 private:
100 friend class base::DeleteHelper<BluetoothAdapterWin>;
101 friend class BluetoothAdapterWinTest;
103 enum DiscoveryStatus {
104 NOT_DISCOVERING,
105 DISCOVERY_STARTING,
106 DISCOVERING,
107 DISCOVERY_STOPPING
110 explicit BluetoothAdapterWin(const InitCallback& init_callback);
111 virtual ~BluetoothAdapterWin();
113 // BluetoothAdapter:
114 void DeleteOnCorrectThread() const override;
115 virtual void AddDiscoverySession(
116 BluetoothDiscoveryFilter* discovery_filter,
117 const base::Closure& callback,
118 const ErrorCallback& error_callback) override;
119 virtual void RemoveDiscoverySession(
120 BluetoothDiscoveryFilter* discovery_filter,
121 const base::Closure& callback,
122 const ErrorCallback& error_callback) override;
123 virtual void SetDiscoveryFilter(
124 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
125 const base::Closure& callback,
126 const ErrorCallback& error_callback) override;
128 void Init();
129 void InitForTest(
130 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
131 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner);
133 void MaybePostStartDiscoveryTask();
134 void MaybePostStopDiscoveryTask();
136 InitCallback init_callback_;
137 std::string address_;
138 std::string name_;
139 bool initialized_;
140 bool powered_;
141 DiscoveryStatus discovery_status_;
142 base::hash_set<std::string> discovered_devices_;
144 std::vector<std::pair<base::Closure, ErrorCallback> >
145 on_start_discovery_callbacks_;
146 std::vector<base::Closure> on_stop_discovery_callbacks_;
147 size_t num_discovery_listeners_;
149 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
150 scoped_refptr<BluetoothSocketThread> socket_thread_;
151 scoped_refptr<BluetoothTaskManagerWin> task_manager_;
153 base::ThreadChecker thread_checker_;
155 // List of observers interested in event notifications from us.
156 ObserverList<BluetoothAdapter::Observer> observers_;
158 // NOTE: This should remain the last member so it'll be destroyed and
159 // invalidate its weak pointers before any other members are destroyed.
160 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_;
162 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin);
165 } // namespace device
167 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_