Process Alt-Svc headers.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_win.h
blobc3920957e4cac40609a6168da41629658ed9c59d
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 <set>
9 #include <string>
10 #include <utility>
11 #include <vector>
13 #include "base/containers/hash_tables.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/threading/thread_checker.h"
18 #include "device/bluetooth/bluetooth_adapter.h"
19 #include "device/bluetooth/bluetooth_audio_sink.h"
20 #include "device/bluetooth/bluetooth_discovery_session.h"
21 #include "device/bluetooth/bluetooth_export.h"
22 #include "device/bluetooth/bluetooth_task_manager_win.h"
24 namespace base {
25 class SequencedTaskRunner;
26 class Thread;
27 } // namespace base
29 namespace device {
31 class BluetoothAdapterWinTest;
32 class BluetoothDevice;
33 class BluetoothSocketThread;
35 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterWin
36 : public BluetoothAdapter,
37 public BluetoothTaskManagerWin::Observer {
38 public:
39 static base::WeakPtr<BluetoothAdapter> CreateAdapter(
40 const InitCallback& init_callback);
42 // BluetoothAdapter:
43 std::string GetAddress() const override;
44 std::string GetName() const override;
45 void SetName(const std::string& name,
46 const base::Closure& callback,
47 const ErrorCallback& error_callback) override;
48 bool IsInitialized() const override;
49 bool IsPresent() const override;
50 bool IsPowered() const override;
51 void SetPowered(bool discoverable,
52 const base::Closure& callback,
53 const ErrorCallback& error_callback) override;
54 bool IsDiscoverable() const override;
55 void SetDiscoverable(bool discoverable,
56 const base::Closure& callback,
57 const ErrorCallback& error_callback) override;
58 bool IsDiscovering() const override;
59 void CreateRfcommService(
60 const BluetoothUUID& uuid,
61 const ServiceOptions& options,
62 const CreateServiceCallback& callback,
63 const CreateServiceErrorCallback& error_callback) override;
64 void CreateL2capService(
65 const BluetoothUUID& uuid,
66 const ServiceOptions& options,
67 const CreateServiceCallback& callback,
68 const CreateServiceErrorCallback& error_callback) override;
69 void RegisterAudioSink(
70 const BluetoothAudioSink::Options& options,
71 const AcquiredCallback& callback,
72 const BluetoothAudioSink::ErrorCallback& error_callback) override;
73 void RegisterAdvertisement(
74 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
75 const CreateAdvertisementCallback& callback,
76 const CreateAdvertisementErrorCallback& error_callback) override;
78 // BluetoothTaskManagerWin::Observer override
79 void AdapterStateChanged(
80 const BluetoothTaskManagerWin::AdapterState& state) override;
81 void DiscoveryStarted(bool success) override;
82 void DiscoveryStopped() override;
83 void DevicesPolled(const ScopedVector<BluetoothTaskManagerWin::DeviceState>&
84 devices) override;
86 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner() const {
87 return ui_task_runner_;
89 const scoped_refptr<BluetoothSocketThread>& socket_thread() const {
90 return socket_thread_;
93 protected:
94 // BluetoothAdapter:
95 void RemovePairingDelegateInternal(
96 device::BluetoothDevice::PairingDelegate* pairing_delegate) override;
98 private:
99 friend class BluetoothAdapterWinTest;
101 enum DiscoveryStatus {
102 NOT_DISCOVERING,
103 DISCOVERY_STARTING,
104 DISCOVERING,
105 DISCOVERY_STOPPING
108 explicit BluetoothAdapterWin(const InitCallback& init_callback);
109 ~BluetoothAdapterWin() override;
111 // BluetoothAdapter:
112 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter,
113 const base::Closure& callback,
114 const ErrorCallback& error_callback) override;
115 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter,
116 const base::Closure& callback,
117 const ErrorCallback& error_callback) override;
118 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
119 const base::Closure& callback,
120 const ErrorCallback& error_callback) override;
122 void Init();
123 void InitForTest(
124 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
125 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner);
127 void MaybePostStartDiscoveryTask();
128 void MaybePostStopDiscoveryTask();
130 InitCallback init_callback_;
131 std::string address_;
132 std::string name_;
133 bool initialized_;
134 bool powered_;
135 DiscoveryStatus discovery_status_;
136 base::hash_set<std::string> discovered_devices_;
138 std::vector<std::pair<base::Closure, ErrorCallback> >
139 on_start_discovery_callbacks_;
140 std::vector<base::Closure> on_stop_discovery_callbacks_;
141 size_t num_discovery_listeners_;
143 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
144 scoped_refptr<BluetoothSocketThread> socket_thread_;
145 scoped_refptr<BluetoothTaskManagerWin> task_manager_;
147 base::ThreadChecker thread_checker_;
149 // NOTE: This should remain the last member so it'll be destroyed and
150 // invalidate its weak pointers before any other members are destroyed.
151 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_;
153 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin);
156 } // namespace device
158 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_