File: bluetooth_internals_handler.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (117 lines) | stat: -rw-r--r-- 4,357 bytes parent folder | download | duplicates (5)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBUI_BLUETOOTH_INTERNALS_BLUETOOTH_INTERNALS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_BLUETOOTH_INTERNALS_BLUETOOTH_INTERNALS_HANDLER_H_

#include <optional>

#include "base/files/file_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "chrome/browser/ui/webui/bluetooth_internals/bluetooth_internals.mojom.h"
#include "content/public/browser/render_frame_host.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/ash/services/bluetooth_config/public/mojom/cros_bluetooth_config.mojom.h"

namespace ash {
namespace bluetooth {
class DebugLogsManager;
}  // namespace bluetooth
}  // namespace ash
#endif

// Handles API requests from chrome://bluetooth-internals page by implementing
// mojom::BluetoothInternalsHandler.
class BluetoothInternalsHandler
    : public mojom::BluetoothInternalsHandler
#if BUILDFLAG(IS_CHROMEOS)
    ,
      public ash::bluetooth_config::mojom::SystemPropertiesObserver
#endif  // BUILDFLAG(IS_CHROMEOS)
{
 public:
  explicit BluetoothInternalsHandler(
      content::RenderFrameHost* render_frame_host,
      mojo::PendingReceiver<mojom::BluetoothInternalsHandler> receiver);

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

  ~BluetoothInternalsHandler() override;

#if BUILDFLAG(IS_CHROMEOS)
  void set_debug_logs_manager(
      ash::bluetooth::DebugLogsManager* debug_logs_manager) {
    debug_logs_manager_ = debug_logs_manager;
  }
#endif

  // mojom::BluetoothInternalsHandler:
  void GetAdapter(GetAdapterCallback callback) override;
  void GetDebugLogsChangeHandler(
      GetDebugLogsChangeHandlerCallback callback) override;
  void CheckSystemPermissions(CheckSystemPermissionsCallback callback) override;
  void RequestSystemPermissions(
      RequestSystemPermissionsCallback callback) override;
  void RequestLocationServices(
      RequestLocationServicesCallback callback) override;
#if BUILDFLAG(IS_CHROMEOS)
  void RestartSystemBluetooth(RestartSystemBluetoothCallback callback) override;
#endif  // BUILDFLAG(IS_CHROMEOS)
  void StartBtsnoop(StartBtsnoopCallback callback) override;
  void IsBtsnoopFeatureEnabled(
      IsBtsnoopFeatureEnabledCallback callback) override;

 private:
  void OnGetAdapter(GetAdapterCallback callback,
                    scoped_refptr<device::BluetoothAdapter> adapter);

#if BUILDFLAG(IS_CHROMEOS)
  // bluetooth_config::mojom::SystemPropertiesObserver
  void OnPropertiesUpdated(
      ash::bluetooth_config::mojom::BluetoothSystemPropertiesPtr properties)
      override;

  void StopBtsnoop(mojom::BluetoothBtsnoop::StopCallback callback);
  void OnStartBtsnoopResp(StartBtsnoopCallback callback, bool success);
  void OnStopBtsnoopResp(mojom::BluetoothBtsnoop::StopCallback callback,
                         bool success);
  std::optional<base::FilePath> GetDownloadsPath();
#endif  // BUILDFLAG(IS_CHROMEOS)

  raw_ref<content::RenderFrameHost> render_frame_host_;
  mojo::Receiver<mojom::BluetoothInternalsHandler> receiver_;

#if BUILDFLAG(IS_CHROMEOS)
  raw_ptr<ash::bluetooth::DebugLogsManager> debug_logs_manager_ = nullptr;

  bool turning_bluetooth_off_ = false;
  bool turning_bluetooth_on_ = false;
  bool bluetooth_initial_state_ = false;

  RestartSystemBluetoothCallback restart_system_bluetooth_callback_;

  ash::bluetooth_config::mojom::BluetoothSystemState bluetooth_system_state_ =
      ash::bluetooth_config::mojom::BluetoothSystemState::kUnavailable;

  mojo::Receiver<ash::bluetooth_config::mojom::SystemPropertiesObserver>
      cros_system_properties_observer_receiver_{this};

  mojo::Remote<ash::bluetooth_config::mojom::CrosBluetoothConfig>
      remote_cros_bluetooth_config_;

  std::unique_ptr<mojom::BluetoothBtsnoop> btsnoop_;
#endif  // BUILDFLAG(IS_CHROMEOS)

  base::WeakPtrFactory<BluetoothInternalsHandler> weak_ptr_factory_{this};
};

#endif  // CHROME_BROWSER_UI_WEBUI_BLUETOOTH_INTERNALS_BLUETOOTH_INTERNALS_HANDLER_H_