Fix variable shadowing warnings in UDPSocketWin on VS2015
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_win.h
blob72280ee8308c5d3b7c3577a5d087ccb7712fb6c3
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_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 virtual void AddObserver(BluetoothAdapter::Observer* observer) override;
44 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) override;
45 virtual std::string GetAddress() const override;
46 virtual std::string GetName() const override;
47 virtual void SetName(const std::string& name,
48 const base::Closure& callback,
49 const ErrorCallback& error_callback) override;
50 virtual bool IsInitialized() const override;
51 virtual bool IsPresent() const override;
52 virtual bool IsPowered() const override;
53 virtual void SetPowered(
54 bool discoverable,
55 const base::Closure& callback,
56 const ErrorCallback& error_callback) override;
57 virtual bool IsDiscoverable() const override;
58 virtual void SetDiscoverable(
59 bool discoverable,
60 const base::Closure& callback,
61 const ErrorCallback& error_callback) override;
62 virtual bool IsDiscovering() const override;
63 virtual void CreateRfcommService(
64 const BluetoothUUID& uuid,
65 const ServiceOptions& options,
66 const CreateServiceCallback& callback,
67 const CreateServiceErrorCallback& error_callback) override;
68 virtual void CreateL2capService(
69 const BluetoothUUID& uuid,
70 const ServiceOptions& options,
71 const CreateServiceCallback& callback,
72 const CreateServiceErrorCallback& error_callback) override;
73 void RegisterAudioSink(
74 const BluetoothAudioSink::Options& options,
75 const AcquiredCallback& callback,
76 const BluetoothAudioSink::ErrorCallback& error_callback) override;
78 // BluetoothTaskManagerWin::Observer override
79 virtual void AdapterStateChanged(
80 const BluetoothTaskManagerWin::AdapterState& state) override;
81 virtual void DiscoveryStarted(bool success) override;
82 virtual void DiscoveryStopped() override;
83 virtual void DevicesPolled(const ScopedVector<
84 BluetoothTaskManagerWin::DeviceState>& 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 virtual void RemovePairingDelegateInternal(
96 device::BluetoothDevice::PairingDelegate* pairing_delegate) override;
98 private:
99 friend class base::DeleteHelper<BluetoothAdapterWin>;
100 friend class BluetoothAdapterWinTest;
102 enum DiscoveryStatus {
103 NOT_DISCOVERING,
104 DISCOVERY_STARTING,
105 DISCOVERING,
106 DISCOVERY_STOPPING
109 explicit BluetoothAdapterWin(const InitCallback& init_callback);
110 virtual ~BluetoothAdapterWin();
112 // BluetoothAdapter:
113 void DeleteOnCorrectThread() const override;
114 virtual void AddDiscoverySession(
115 const base::Closure& callback,
116 const ErrorCallback& error_callback) override;
117 virtual void RemoveDiscoverySession(
118 const base::Closure& callback,
119 const ErrorCallback& error_callback) override;
121 void Init();
122 void InitForTest(
123 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
124 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner);
126 void MaybePostStartDiscoveryTask();
127 void MaybePostStopDiscoveryTask();
129 InitCallback init_callback_;
130 std::string address_;
131 std::string name_;
132 bool initialized_;
133 bool powered_;
134 DiscoveryStatus discovery_status_;
135 base::hash_set<std::string> discovered_devices_;
137 std::vector<std::pair<base::Closure, ErrorCallback> >
138 on_start_discovery_callbacks_;
139 std::vector<base::Closure> on_stop_discovery_callbacks_;
140 size_t num_discovery_listeners_;
142 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
143 scoped_refptr<BluetoothSocketThread> socket_thread_;
144 scoped_refptr<BluetoothTaskManagerWin> task_manager_;
146 base::ThreadChecker thread_checker_;
148 // List of observers interested in event notifications from us.
149 ObserverList<BluetoothAdapter::Observer> observers_;
151 // NOTE: This should remain the last member so it'll be destroyed and
152 // invalidate its weak pointers before any other members are destroyed.
153 base::WeakPtrFactory<BluetoothAdapterWin> weak_ptr_factory_;
155 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterWin);
158 } // namespace device
160 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_WIN_H_