blob: 332ff3bde71458ade01355bf2ec1d35fb2151178 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2019 The Chromium Authors
Jun Cai149002e2019-05-09 23:13:072// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Michael van Ouwerkerk4950e7172021-07-09 11:42:135#include "components/permissions/bluetooth_scanning_prompt_desktop.h"
Jun Cai149002e2019-05-09 23:13:076
Michael van Ouwerkerk19f0cea2021-06-30 11:22:167#include "components/permissions/bluetooth_scanning_prompt_controller.h"
Jun Cai149002e2019-05-09 23:13:078
Michael van Ouwerkerk4950e7172021-07-09 11:42:139namespace permissions {
10
Jun Cai149002e2019-05-09 23:13:0711BluetoothScanningPromptDesktop::BluetoothScanningPromptDesktop(
Mike Wasserman9e1196f2020-11-20 04:15:5012 content::RenderFrameHost* frame,
Michael van Ouwerkerkda035542021-07-09 10:12:3513 const content::BluetoothScanningPrompt::EventHandler& event_handler,
14 std::u16string title,
15 base::OnceCallback<
16 base::OnceClosure(std::unique_ptr<permissions::ChooserController>)>
17 show_dialog_callback) {
Mike Wasserman9e1196f2020-11-20 04:15:5018 auto controller =
Michael van Ouwerkerk19f0cea2021-06-30 11:22:1619 std::make_unique<permissions::BluetoothScanningPromptController>(
Michael van Ouwerkerkda035542021-07-09 10:12:3520 frame, event_handler, title);
Mike Wasserman9e1196f2020-11-20 04:15:5021 bluetooth_scanning_prompt_controller_ = controller->GetWeakPtr();
Michael van Ouwerkerkda035542021-07-09 10:12:3522 close_closure_runner_.ReplaceClosure(
23 std::move(show_dialog_callback).Run(std::move(controller)));
Jun Cai149002e2019-05-09 23:13:0724}
25
26BluetoothScanningPromptDesktop::~BluetoothScanningPromptDesktop() {
27 // This satisfies the WebContentsDelegate::ShowBluetoothScanningPrompt()
28 // requirement that the EventHandler can be destroyed any time after the
29 // BluetoothScanningPrompt instance.
Mike Wasserman9e1196f2020-11-20 04:15:5030 if (bluetooth_scanning_prompt_controller_)
31 bluetooth_scanning_prompt_controller_->ResetEventHandler();
Jun Cai149002e2019-05-09 23:13:0732}
33
34void BluetoothScanningPromptDesktop::AddOrUpdateDevice(
35 const std::string& device_id,
36 bool should_update_name,
Jan Wilken Dörrie3f97e292021-03-11 18:07:1437 const std::u16string& device_name) {
Mike Wasserman9e1196f2020-11-20 04:15:5038 if (bluetooth_scanning_prompt_controller_) {
39 bluetooth_scanning_prompt_controller_->AddOrUpdateDevice(
40 device_id, should_update_name, device_name);
41 }
Jun Cai149002e2019-05-09 23:13:0742}
Michael van Ouwerkerk4950e7172021-07-09 11:42:1343
44} // namespace permissions