Skip to content

Commit 8ec5ef8

Browse files
dtapuskaChromium LUCI CQ
authored andcommitted
Migrate uses of WebContentsObserver to WeakPtr
Now that WebContents has weak pointer support, migrate uses of WebContentsObserver to use it. BUG=952390 Change-Id: I9858b51409a29310b84d714c053fd37b820db788 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3145550 Reviewed-by: Rouslan Solomakhin <[email protected]> Commit-Queue: Dave Tapuska <[email protected]> Cr-Commit-Position: refs/heads/main@{#918852}
1 parent eee26ef commit 8ec5ef8

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

components/payments/content/payment_handler_host.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ void RunCallbackWithError(const std::string& error,
5656

5757
PaymentHandlerHost::PaymentHandlerHost(content::WebContents* web_contents,
5858
base::WeakPtr<Delegate> delegate)
59-
: WebContentsObserver(web_contents), delegate_(delegate) {
59+
: delegate_(delegate) {
6060
DCHECK(web_contents);
6161
DCHECK(delegate_);
62+
web_contents_ = web_contents->GetWeakPtr();
6263
}
6364

6465
PaymentHandlerHost::~PaymentHandlerHost() {}
@@ -80,7 +81,7 @@ void PaymentHandlerHost::UpdateWith(
8081
if (!change_payment_request_details_callback_)
8182
return;
8283

83-
auto* dev_tools = GetDevTools(web_contents(), sw_origin_for_logs_);
84+
auto* dev_tools = GetDevTools(web_contents_.get(), sw_origin_for_logs_);
8485
if (dev_tools) {
8586
std::map<std::string, std::string> data = {{"Error", response->error}};
8687

@@ -198,7 +199,7 @@ void PaymentHandlerHost::ChangePaymentMethod(
198199
return;
199200
}
200201

201-
auto* dev_tools = GetDevTools(web_contents(), sw_origin_for_logs_);
202+
auto* dev_tools = GetDevTools(web_contents_.get(), sw_origin_for_logs_);
202203
if (dev_tools) {
203204
dev_tools->LogBackgroundServiceEvent(
204205
registration_id_for_logs_, sw_origin_for_logs_,
@@ -228,7 +229,7 @@ void PaymentHandlerHost::ChangeShippingOption(
228229
return;
229230
}
230231

231-
auto* dev_tools = GetDevTools(web_contents(), sw_origin_for_logs_);
232+
auto* dev_tools = GetDevTools(web_contents_.get(), sw_origin_for_logs_);
232233
if (dev_tools) {
233234
dev_tools->LogBackgroundServiceEvent(
234235
registration_id_for_logs_, sw_origin_for_logs_,
@@ -257,7 +258,7 @@ void PaymentHandlerHost::ChangeShippingAddress(
257258
return;
258259
}
259260

260-
auto* dev_tools = GetDevTools(web_contents(), sw_origin_for_logs_);
261+
auto* dev_tools = GetDevTools(web_contents_.get(), sw_origin_for_logs_);
261262
if (dev_tools) {
262263
std::map<std::string, std::string> shipping_address_map;
263264
shipping_address_map.emplace("Country", shipping_address->country);

components/payments/content/payment_handler_host.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "base/callback_forward.h"
1212
#include "base/macros.h"
1313
#include "base/memory/weak_ptr.h"
14-
#include "content/public/browser/web_contents_observer.h"
1514
#include "mojo/public/cpp/bindings/pending_remote.h"
1615
#include "mojo/public/cpp/bindings/receiver.h"
1716
#include "third_party/blink/public/mojom/payments/payment_handler_host.mojom.h"
@@ -28,8 +27,7 @@ using ChangePaymentRequestDetailsCallback =
2827

2928
// Handles the communication from the payment handler renderer process to the
3029
// merchant renderer process.
31-
class PaymentHandlerHost : public mojom::PaymentHandlerHost,
32-
public content::WebContentsObserver {
30+
class PaymentHandlerHost : public mojom::PaymentHandlerHost {
3331
public:
3432
// The interface to be implemented by the object that can communicate to the
3533
// merchant's renderer process.
@@ -148,6 +146,8 @@ class PaymentHandlerHost : public mojom::PaymentHandlerHost,
148146
// logging.
149147
std::string payment_request_id_for_logs_;
150148

149+
base::WeakPtr<content::WebContents> web_contents_;
150+
151151
base::WeakPtrFactory<PaymentHandlerHost> weak_ptr_factory_{this};
152152

153153
DISALLOW_COPY_AND_ASSIGN(PaymentHandlerHost);

0 commit comments

Comments
 (0)