Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Michael van Ouwerkerk | 4950e717 | 2021-07-09 11:42:13 | [diff] [blame] | 5 | #include "components/permissions/bluetooth_scanning_prompt_desktop.h" |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 6 | |
Michael van Ouwerkerk | 19f0cea | 2021-06-30 11:22:16 | [diff] [blame] | 7 | #include "components/permissions/bluetooth_scanning_prompt_controller.h" |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 8 | |
Michael van Ouwerkerk | 4950e717 | 2021-07-09 11:42:13 | [diff] [blame] | 9 | namespace permissions { |
| 10 | |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 11 | BluetoothScanningPromptDesktop::BluetoothScanningPromptDesktop( |
Mike Wasserman | 9e1196f | 2020-11-20 04:15:50 | [diff] [blame] | 12 | content::RenderFrameHost* frame, |
Michael van Ouwerkerk | da03554 | 2021-07-09 10:12:35 | [diff] [blame] | 13 | 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 Wasserman | 9e1196f | 2020-11-20 04:15:50 | [diff] [blame] | 18 | auto controller = |
Michael van Ouwerkerk | 19f0cea | 2021-06-30 11:22:16 | [diff] [blame] | 19 | std::make_unique<permissions::BluetoothScanningPromptController>( |
Michael van Ouwerkerk | da03554 | 2021-07-09 10:12:35 | [diff] [blame] | 20 | frame, event_handler, title); |
Mike Wasserman | 9e1196f | 2020-11-20 04:15:50 | [diff] [blame] | 21 | bluetooth_scanning_prompt_controller_ = controller->GetWeakPtr(); |
Michael van Ouwerkerk | da03554 | 2021-07-09 10:12:35 | [diff] [blame] | 22 | close_closure_runner_.ReplaceClosure( |
| 23 | std::move(show_dialog_callback).Run(std::move(controller))); |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | BluetoothScanningPromptDesktop::~BluetoothScanningPromptDesktop() { |
| 27 | // This satisfies the WebContentsDelegate::ShowBluetoothScanningPrompt() |
| 28 | // requirement that the EventHandler can be destroyed any time after the |
| 29 | // BluetoothScanningPrompt instance. |
Mike Wasserman | 9e1196f | 2020-11-20 04:15:50 | [diff] [blame] | 30 | if (bluetooth_scanning_prompt_controller_) |
| 31 | bluetooth_scanning_prompt_controller_->ResetEventHandler(); |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void BluetoothScanningPromptDesktop::AddOrUpdateDevice( |
| 35 | const std::string& device_id, |
| 36 | bool should_update_name, |
Jan Wilken Dörrie | 3f97e29 | 2021-03-11 18:07:14 | [diff] [blame] | 37 | const std::u16string& device_name) { |
Mike Wasserman | 9e1196f | 2020-11-20 04:15:50 | [diff] [blame] | 38 | if (bluetooth_scanning_prompt_controller_) { |
| 39 | bluetooth_scanning_prompt_controller_->AddOrUpdateDevice( |
| 40 | device_id, should_update_name, device_name); |
| 41 | } |
Jun Cai | 149002e | 2019-05-09 23:13:07 | [diff] [blame] | 42 | } |
Michael van Ouwerkerk | 4950e717 | 2021-07-09 11:42:13 | [diff] [blame] | 43 | |
| 44 | } // namespace permissions |