bluetooth_scanning_prompt_desktop.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #include "components/permissions/bluetooth_scanning_prompt_desktop.h"
  5. #include "components/permissions/bluetooth_scanning_prompt_controller.h"
  6. namespace permissions {
  7. BluetoothScanningPromptDesktop::BluetoothScanningPromptDesktop(
  8. content::RenderFrameHost* frame,
  9. const content::BluetoothScanningPrompt::EventHandler& event_handler,
  10. std::u16string title,
  11. base::OnceCallback<
  12. base::OnceClosure(std::unique_ptr<permissions::ChooserController>)>
  13. show_dialog_callback) {
  14. auto controller =
  15. std::make_unique<permissions::BluetoothScanningPromptController>(
  16. frame, event_handler, title);
  17. bluetooth_scanning_prompt_controller_ = controller->GetWeakPtr();
  18. close_closure_runner_.ReplaceClosure(
  19. std::move(show_dialog_callback).Run(std::move(controller)));
  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.
  25. if (bluetooth_scanning_prompt_controller_)
  26. bluetooth_scanning_prompt_controller_->ResetEventHandler();
  27. }
  28. void BluetoothScanningPromptDesktop::AddOrUpdateDevice(
  29. const std::string& device_id,
  30. bool should_update_name,
  31. const std::u16string& device_name) {
  32. if (bluetooth_scanning_prompt_controller_) {
  33. bluetooth_scanning_prompt_controller_->AddOrUpdateDevice(
  34. device_id, should_update_name, device_name);
  35. }
  36. }
  37. } // namespace permissions