Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_win.h
blobc1486ab8c0f86712f3d0924db083e88cfc2a5d65
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(
113 BluetoothDiscoveryFilter* discovery_filter,
114 const base::Closure& callback,
115 const DiscoverySessionErrorCallback& error_callback) override;
116 void RemoveDiscoverySession(
117 BluetoothDiscoveryFilter* discovery_filter,
118 const base::Closure& callback,
119 const DiscoverySessionErrorCallback& error_callback) override;
120 void SetDiscoveryFilter(
121 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
122 const base::Closure& callback,
123 const DiscoverySessionErrorCallback& error_callback) override;
125 void Init();
126 void InitForTest(
127 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
128 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner);
130 void MaybePostStartDiscoveryTask();
131 void MaybePostStopDiscoveryTask();
133 InitCallback init_callback_;
134 std::string address_;
135 std::string name_;
136 bool initialized_;
137 bool powered_;
138 DiscoveryStatus discovery_status_;
139 base::hash_set<std::string> discovered_devices_;
141 std::vector<std::pair<base::Closure, DiscoverySessionErrorCallback>>
142 on_start_discovery_callbacks_;
143 std::vector<base::Closure> on_stop_discovery_callbacks_;
144 size_t num_discovery_listeners_;
146 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
147 scoped_refptr<BluetoothSocketThread> socket_thread_;
148 scoped_refptr<BluetoothTaskManagerWin> task_manager_;
150 base::ThreadChecker thread_checker_;
152 // NOTE: This should remain the last member so it'll be destroyed and
153 // invalidate its weak pointers before any other members are destroyed.
154 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_;
156 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin);
159 } // namespace device
161 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_