Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 1 | // 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 Wennborg | 1790e6b | 2020-04-24 19:10:33 | [diff] [blame] | 7 | #include "base/check.h" |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 8 | #include "chrome/browser/ui/bluetooth/bluetooth_scanning_prompt_controller.h" |
Mike Wasserman | 9e1196f | 2020-11-20 04:15:50 | [diff] [blame] | 9 | #include "chrome/browser/ui/browser_dialogs.h" |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 10 | |
| 11 | BluetoothScanningPromptDesktop::BluetoothScanningPromptDesktop( |
Mike Wasserman | 9e1196f | 2020-11-20 04:15:50 | [diff] [blame] | 12 | 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 Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | BluetoothScanningPromptDesktop::~BluetoothScanningPromptDesktop() { |
| 22 | // This satisfies the WebContentsDelegate::ShowBluetoothScanningPrompt() |
| 23 | // requirement that the EventHandler can be destroyed any time after the |
| 24 | // BluetoothScanningPrompt instance. |
Mike Wasserman | 9e1196f | 2020-11-20 04:15:50 | [diff] [blame] | 25 | if (bluetooth_scanning_prompt_controller_) |
| 26 | bluetooth_scanning_prompt_controller_->ResetEventHandler(); |
Elly Fong-Jones | f260d67 | 2020-03-16 14:09:07 | [diff] [blame] | 27 | if (close_closure_) |
| 28 | std::move(close_closure_).Run(); |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | void BluetoothScanningPromptDesktop::AddOrUpdateDevice( |
| 32 | const std::string& device_id, |
| 33 | bool should_update_name, |
Jan Wilken Dörrie | 3f97e29 | 2021-03-11 18:07:14 | [diff] [blame^] | 34 | const std::u16string& device_name) { |
Mike Wasserman | 9e1196f | 2020-11-20 04:15:50 | [diff] [blame] | 35 | if (bluetooth_scanning_prompt_controller_) { |
| 36 | bluetooth_scanning_prompt_controller_->AddOrUpdateDevice( |
| 37 | device_id, should_update_name, device_name); |
| 38 | } |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 39 | } |