File: fake_bluetooth_chooser.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 (85 lines) | stat: -rw-r--r-- 3,615 bytes parent folder | download | duplicates (11)
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
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_WEB_TEST_BROWSER_FAKE_BLUETOOTH_CHOOSER_H_
#define CONTENT_WEB_TEST_BROWSER_FAKE_BLUETOOTH_CHOOSER_H_

#include <memory>

#include "content/public/browser/bluetooth_chooser.h"
#include "content/web_test/common/fake_bluetooth_chooser.mojom.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "url/origin.h"

namespace content {

// Implementation of FakeBluetoothChooser in
// src/content/web_test/common/fake_bluetooth_chooser.mojom
// to provide a method of controlling the Bluetooth chooser during a test.
// Serves as a Bluetooth chooser factory for choosers that can be manually
// controlled through the Mojo API. Only one instance of this class will exist
// while the chooser is active.
//
// The implementation details for FakeBluetoothChooser can be found in the Web
// Bluetooth Test Scanning design document.
// https://docs.google.com/document/d/1XFl_4ZAgO8ddM6U53A9AfUuZeWgJnlYD5wtbXqEpzeg
//
// Intended to only be used through the FakeBluetoothChooser Mojo interface.
class FakeBluetoothChooser : public mojom::FakeBluetoothChooser,
                             public BluetoothChooser {
 public:
  // FakeBluetoothChooserFactory will create an instance of this class when its
  // CreateFakeBluetoothChooser() method is called. It will maintain ownership
  // of the instance temporarily until the chooser is opened. When the chooser
  // is opened, ownership of this instance will shift to the caller of
  // WebContentsDelegate::RunBluetoothChooser.
  FakeBluetoothChooser(
      mojo::PendingReceiver<mojom::FakeBluetoothChooser> receiver,
      mojo::PendingAssociatedRemote<mojom::FakeBluetoothChooserClient> client);

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

  // Resets the test scan duration to timeout immediately and sends a
  // |CHOOSER_CLOSED| event to the client.
  ~FakeBluetoothChooser() override;

  // Sets the EventHandler that will handle events produced by the chooser, and
  // sends a |CHOOSER_OPENED| event to the client with the |origin|.
  void OnRunBluetoothChooser(const EventHandler& event_handler,
                             const url::Origin& origin);

  // mojom::FakeBluetoothChooser overrides:
  void SelectPeripheral(const std::string& peripheral_address) override;
  void Cancel() override;
  void Rescan() override;

  // BluetoothChooser overrides:

  void SetAdapterPresence(AdapterPresence presence) override;
  void ShowDiscoveryState(DiscoveryState state) override;
  void AddOrUpdateDevice(const std::string& device_id,
                         bool should_update_name,
                         const std::u16string& device_name,
                         bool is_gatt_connected,
                         bool is_paired,
                         int signal_strength_level) override;

 private:
  // Stores the callback function that handles chooser events.
  EventHandler event_handler_;

  mojo::Receiver<mojom::FakeBluetoothChooser> receiver_;

  // Stores the associated pointer to the client that will be receiving events
  // from FakeBluetoothChooser.
  mojo::AssociatedRemote<mojom::FakeBluetoothChooserClient> client_;
};

}  // namespace content

#endif  // CONTENT_WEB_TEST_BROWSER_FAKE_BLUETOOTH_CHOOSER_H_