blob: 6bf1e605f0672302e93e9a8dcf8fc3ec7ff08b6a [file] [log] [blame]
Jun Cai149002e2019-05-09 23:13:071// Copyright 2019 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.
4
5#include "chrome/browser/ui/bluetooth/bluetooth_scanning_prompt_desktop.h"
6
Hans Wennborg1790e6b2020-04-24 19:10:337#include "base/check.h"
Jun Cai149002e2019-05-09 23:13:078#include "chrome/browser/ui/bluetooth/bluetooth_scanning_prompt_controller.h"
Mike Wasserman9e1196f2020-11-20 04:15:509#include "chrome/browser/ui/browser_dialogs.h"
Jun Cai149002e2019-05-09 23:13:0710
11BluetoothScanningPromptDesktop::BluetoothScanningPromptDesktop(
Mike Wasserman9e1196f2020-11-20 04:15:5012 content::RenderFrameHost* frame,
13 const content::BluetoothScanningPrompt::EventHandler& event_handler) {
14 auto controller =
15 std::make_unique<BluetoothScanningPromptController>(frame, event_handler);
16 bluetooth_scanning_prompt_controller_ = controller->GetWeakPtr();
17 close_closure_ =
18 chrome::ShowDeviceChooserDialog(frame, std::move(controller));
Jun Cai149002e2019-05-09 23:13:0719}
20
21BluetoothScanningPromptDesktop::~BluetoothScanningPromptDesktop() {
22 // This satisfies the WebContentsDelegate::ShowBluetoothScanningPrompt()
23 // requirement that the EventHandler can be destroyed any time after the
24 // BluetoothScanningPrompt instance.
Mike Wasserman9e1196f2020-11-20 04:15:5025 if (bluetooth_scanning_prompt_controller_)
26 bluetooth_scanning_prompt_controller_->ResetEventHandler();
Elly Fong-Jonesf260d672020-03-16 14:09:0727 if (close_closure_)
28 std::move(close_closure_).Run();
Jun Cai149002e2019-05-09 23:13:0729}
30
31void BluetoothScanningPromptDesktop::AddOrUpdateDevice(
32 const std::string& device_id,
33 bool should_update_name,
Jan Wilken Dörrie3f97e292021-03-11 18:07:1434 const std::u16string& device_name) {
Mike Wasserman9e1196f2020-11-20 04:15:5035 if (bluetooth_scanning_prompt_controller_) {
36 bluetooth_scanning_prompt_controller_->AddOrUpdateDevice(
37 device_id, should_update_name, device_name);
38 }
Jun Cai149002e2019-05-09 23:13:0739}