refactor: add SerialChooserController::web_contents_ (#43823)

Add a `base::WeakPtr<WebContents>` field to SerialChooserController and
stop subclassing from WebContentsObserver. This follows the Observer docs:

> don't create a `WebContentsObserver` just to be able to check
> for a null `WebContentsObserver::web_contents()`.
> Use a `base::WeakPtr<WebContents>` instead.
This commit is contained in:
Charles Kerr 2024-09-24 00:38:13 -05:00 committed by GitHub
parent 9598d88b7c
commit 79627deea3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 16 deletions

View file

@ -12,7 +12,6 @@
#include "base/scoped_observation.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/serial_chooser.h"
#include "content/public/browser/web_contents_observer.h"
#include "services/device/public/mojom/serial.mojom-forward.h"
#include "shell/browser/serial/serial_chooser_context.h"
#include "third_party/blink/public/mojom/serial/serial.mojom-forward.h"
@ -32,8 +31,7 @@ class ElectronSerialDelegate;
// SerialChooserController provides data for the Serial API permission prompt.
class SerialChooserController final
: private SerialChooserContext::PortObserver,
private content::WebContentsObserver {
: private SerialChooserContext::PortObserver {
public:
SerialChooserController(
content::RenderFrameHost* render_frame_host,
@ -64,6 +62,8 @@ class SerialChooserController final
void RunCallback(device::mojom::SerialPortInfoPtr port);
void OnDeviceChosen(const std::string& port_id);
base::WeakPtr<content::WebContents> web_contents_;
std::vector<blink::mojom::SerialPortFilterPtr> filters_;
std::vector<::device::BluetoothUUID> allowed_bluetooth_service_class_ids_;
content::SerialChooser::Callback callback_;