refactor: add SerialChooserController::web_contents_ (#43920)

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.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-09-24 08:26:29 -05:00 committed by GitHub
parent ae6d5c4661
commit f609d77e29
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_;