File: bluetooth_private_api.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (347 lines) | stat: -rw-r--r-- 11,551 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_
#define EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_

#include <optional>

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "device/bluetooth/bluetooth_device.h"
#include "extensions/browser/api/bluetooth/bluetooth_extension_function.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
#include "extensions/common/api/bluetooth_private.h"

namespace device {
class BluetoothAdapter;
}

namespace extensions {

// The profile-keyed service that manages the bluetoothPrivate extension API.
class BluetoothPrivateAPI : public BrowserContextKeyedAPI,
                            public EventRouter::Observer {
 public:
  static BrowserContextKeyedAPIFactory<BluetoothPrivateAPI>*
      GetFactoryInstance();

  explicit BluetoothPrivateAPI(content::BrowserContext* context);
  ~BluetoothPrivateAPI() override;

  // KeyedService implementation.
  void Shutdown() override;

  // EventRouter::Observer implementation.
  void OnListenerAdded(const EventListenerInfo& details) override;
  void OnListenerRemoved(const EventListenerInfo& details) override;

  // BrowserContextKeyedAPI implementation.
  static const char* service_name() { return "BluetoothPrivateAPI"; }
  static const bool kServiceRedirectedInIncognito = true;
  static const bool kServiceIsNULLWhileTesting = true;

 private:
  friend class BrowserContextKeyedAPIFactory<BluetoothPrivateAPI>;

  raw_ptr<content::BrowserContext> browser_context_;
};

namespace api {

namespace bluetooth_private {
namespace SetAdapterState {
struct Params;
}  // namespace SetAdapterState
namespace SetPairingResponse {
struct Params;
}  // namespace SetPairingResponse
namespace DisconnectAll {
struct Params;
}  // namespace DisconnectAll
namespace ForgetDevice {
struct Params;
}  // namespace ForgetDevice
namespace SetDiscoveryFilter {
struct Params;
}  // namespace SetDiscoveryFilter
namespace Connect {
struct Params;
}  // namespace Connect
namespace Pair {
struct Params;
}  // namespace Pair
namespace RecordPairing {
struct Params;
}  // namespace RecordPairing
namespace RecordReconnection {
struct Params;
}  // namespace RecordReconnection
namespace RecordDeviceSelection {
struct Params;
}  // namespace RecordDeviceSelection
}  // namespace bluetooth_private

class BluetoothPrivateSetAdapterStateFunction
    : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setAdapterState",
                             BLUETOOTHPRIVATE_SETADAPTERSTATE)
  BluetoothPrivateSetAdapterStateFunction();

  BluetoothPrivateSetAdapterStateFunction(
      const BluetoothPrivateSetAdapterStateFunction&) = delete;
  BluetoothPrivateSetAdapterStateFunction& operator=(
      const BluetoothPrivateSetAdapterStateFunction&) = delete;

 private:
  ~BluetoothPrivateSetAdapterStateFunction() override;

  base::OnceClosure CreatePropertySetCallback(const std::string& property_name);
  base::OnceClosure CreatePropertyErrorCallback(
      const std::string& property_name);
  void OnAdapterPropertySet(const std::string& property);
  void OnAdapterPropertyError(const std::string& property);
  void SendError();

  // BluetoothExtensionFunction overrides:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

  // Set of expected adapter properties to be changed.
  std::set<std::string> pending_properties_;

  // Set of adapter properties that were not set successfully.
  std::set<std::string> failed_properties_;

  // Whether or not the function has finished parsing the arguments and queuing
  // up state requests.
  bool parsed_ = false;

  std::optional<bluetooth_private::SetAdapterState::Params> params_;
};

class BluetoothPrivateSetPairingResponseFunction
    : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setPairingResponse",
                             BLUETOOTHPRIVATE_SETPAIRINGRESPONSE)
  BluetoothPrivateSetPairingResponseFunction();

  BluetoothPrivateSetPairingResponseFunction(
      const BluetoothPrivateSetPairingResponseFunction&) = delete;
  BluetoothPrivateSetPairingResponseFunction& operator=(
      const BluetoothPrivateSetPairingResponseFunction&) = delete;

  // BluetoothExtensionFunction overrides:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

 private:
  ~BluetoothPrivateSetPairingResponseFunction() override;

  std::optional<bluetooth_private::SetPairingResponse::Params> params_;
};

class BluetoothPrivateDisconnectAllFunction
    : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.disconnectAll",
                             BLUETOOTHPRIVATE_DISCONNECTALL)
  BluetoothPrivateDisconnectAllFunction();

  BluetoothPrivateDisconnectAllFunction(
      const BluetoothPrivateDisconnectAllFunction&) = delete;
  BluetoothPrivateDisconnectAllFunction& operator=(
      const BluetoothPrivateDisconnectAllFunction&) = delete;

  // BluetoothExtensionFunction overrides:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

 private:
  ~BluetoothPrivateDisconnectAllFunction() override;

  void OnSuccessCallback();
  void OnErrorCallback(scoped_refptr<device::BluetoothAdapter> adapter,
                       const std::string& device_address);

  std::optional<bluetooth_private::DisconnectAll::Params> params_;
};

class BluetoothPrivateForgetDeviceFunction : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.forgetDevice",
                             BLUETOOTHPRIVATE_FORGETDEVICE)
  BluetoothPrivateForgetDeviceFunction();

  BluetoothPrivateForgetDeviceFunction(
      const BluetoothPrivateForgetDeviceFunction&) = delete;
  BluetoothPrivateForgetDeviceFunction& operator=(
      const BluetoothPrivateForgetDeviceFunction&) = delete;

  // BluetoothExtensionFunction overrides:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

 private:
  ~BluetoothPrivateForgetDeviceFunction() override;

  void OnSuccessCallback();
  void OnErrorCallback(scoped_refptr<device::BluetoothAdapter> adapter,
                       const std::string& device_address);

  std::optional<bluetooth_private::ForgetDevice::Params> params_;
};

class BluetoothPrivateSetDiscoveryFilterFunction
    : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.setDiscoveryFilter",
                             BLUETOOTHPRIVATE_SETDISCOVERYFILTER)
  BluetoothPrivateSetDiscoveryFilterFunction();

  BluetoothPrivateSetDiscoveryFilterFunction(
      const BluetoothPrivateSetDiscoveryFilterFunction&) = delete;
  BluetoothPrivateSetDiscoveryFilterFunction& operator=(
      const BluetoothPrivateSetDiscoveryFilterFunction&) = delete;

 protected:
  ~BluetoothPrivateSetDiscoveryFilterFunction() override;

  // BluetoothExtensionFunction:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

 private:
  void OnSuccessCallback();
  void OnErrorCallback();

  std::optional<bluetooth_private::SetDiscoveryFilter::Params> params_;
};

class BluetoothPrivateConnectFunction : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.connect",
                             BLUETOOTHPRIVATE_CONNECT)
  BluetoothPrivateConnectFunction();

  BluetoothPrivateConnectFunction(const BluetoothPrivateConnectFunction&) =
      delete;
  BluetoothPrivateConnectFunction& operator=(
      const BluetoothPrivateConnectFunction&) = delete;

  // BluetoothExtensionFunction:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

 private:
  ~BluetoothPrivateConnectFunction() override;

  void OnConnect(
      std::optional<device::BluetoothDevice::ConnectErrorCode> error);

  std::optional<bluetooth_private::Connect::Params> params_;
};

class BluetoothPrivatePairFunction : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.pair", BLUETOOTHPRIVATE_PAIR)
  BluetoothPrivatePairFunction();

  BluetoothPrivatePairFunction(const BluetoothPrivatePairFunction&) = delete;
  BluetoothPrivatePairFunction& operator=(const BluetoothPrivatePairFunction&) =
      delete;

  // BluetoothExtensionFunction:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

 private:
  ~BluetoothPrivatePairFunction() override;

  void OnPair(
      std::optional<device::BluetoothDevice::ConnectErrorCode> error_code);

  std::optional<bluetooth_private::Pair::Params> params_;
};

class BluetoothPrivateRecordPairingFunction
    : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.recordPairing",
                             BLUETOOTHPRIVATE_RECORDPAIRING)

  BluetoothPrivateRecordPairingFunction();

  BluetoothPrivateRecordPairingFunction(
      const BluetoothPrivateRecordPairingFunction&) = delete;
  BluetoothPrivateRecordPairingFunction& operator=(
      const BluetoothPrivateRecordPairingFunction&) = delete;

 protected:
  ~BluetoothPrivateRecordPairingFunction() override;

  // BluetoothExtensionFunction:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

 private:
  std::optional<bluetooth_private::RecordPairing::Params> params_;
};

class BluetoothPrivateRecordReconnectionFunction
    : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.recordReconnection",
                             BLUETOOTHPRIVATE_RECORDRECONNECTION)

  BluetoothPrivateRecordReconnectionFunction();

  BluetoothPrivateRecordReconnectionFunction(
      const BluetoothPrivateRecordReconnectionFunction&) = delete;
  BluetoothPrivateRecordReconnectionFunction& operator=(
      const BluetoothPrivateRecordReconnectionFunction&) = delete;

 protected:
  ~BluetoothPrivateRecordReconnectionFunction() override;

  // BluetoothExtensionFunction:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

 private:
  std::optional<bluetooth_private::RecordReconnection::Params> params_;
};

class BluetoothPrivateRecordDeviceSelectionFunction
    : public BluetoothExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.recordDeviceSelection",
                             BLUETOOTHPRIVATE_RECORDDEVICESELECTION)

  BluetoothPrivateRecordDeviceSelectionFunction();

  BluetoothPrivateRecordDeviceSelectionFunction(
      const BluetoothPrivateRecordDeviceSelectionFunction&) = delete;
  BluetoothPrivateRecordDeviceSelectionFunction& operator=(
      const BluetoothPrivateRecordDeviceSelectionFunction&) = delete;

 protected:
  ~BluetoothPrivateRecordDeviceSelectionFunction() override;

  // BluetoothExtensionFunction:
  bool CreateParams() override;
  void DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;

 private:
  std::optional<bluetooth_private::RecordDeviceSelection::Params> params_;
};

}  // namespace api

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_API_BLUETOOTH_BLUETOOTH_PRIVATE_API_H_