Skip to content

Commit 3042f72

Browse files
dtapuskaChromium LUCI CQ
authored andcommitted
Remove LifetimeObserver which was a proxy for a WeakPtr<WebContents>
Use GetWeakPtr directly for having a reference to a WebContents. The proxy was unnecessary with the newly added method on WebContents. BUG=952390 Change-Id: Ib603d74919cb295e73b0255118d18a804c04a80b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3145471 Reviewed-by: Glenn Hartmann <[email protected]> Commit-Queue: Dave Tapuska <[email protected]> Cr-Commit-Position: refs/heads/main@{#918849}
1 parent a5c0310 commit 3042f72

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

chrome/browser/android/webapk/webapk_install_service.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "chrome/browser/android/webapk/webapk_install_service_factory.h"
1616
#include "chrome/browser/android/webapk/webapk_installer.h"
1717
#include "components/webapps/browser/android/shortcut_info.h"
18+
#include "content/public/browser/web_contents.h"
1819
#include "ui/gfx/android/java_bitmap.h"
1920

2021
// static
@@ -50,14 +51,13 @@ void WebApkInstallService::InstallAsync(
5051
ShowInstallInProgressNotification(shortcut_info, primary_icon,
5152
is_primary_icon_maskable);
5253

53-
// We pass an observer which wraps the WebContents to the callback, since the
54+
// We pass an weak ptr to a WebContents to the callback, since the
5455
// installation may take more than 10 seconds so there is a chance that the
5556
// WebContents has been destroyed before the install is finished.
56-
auto observer = std::make_unique<LifetimeObserver>(web_contents);
5757
WebApkInstaller::InstallAsync(
5858
browser_context_, shortcut_info, primary_icon, is_primary_icon_maskable,
5959
base::BindOnce(&WebApkInstallService::OnFinishedInstall,
60-
weak_ptr_factory_.GetWeakPtr(), std::move(observer),
60+
weak_ptr_factory_.GetWeakPtr(), web_contents->GetWeakPtr(),
6161
shortcut_info, primary_icon, is_primary_icon_maskable));
6262
}
6363

@@ -69,7 +69,7 @@ void WebApkInstallService::UpdateAsync(
6969
}
7070

7171
void WebApkInstallService::OnFinishedInstall(
72-
std::unique_ptr<LifetimeObserver> observer,
72+
base::WeakPtr<content::WebContents> web_contents,
7373
const webapps::ShortcutInfo& shortcut_info,
7474
const SkBitmap& primary_icon,
7575
bool is_primary_icon_maskable,
@@ -94,12 +94,11 @@ void WebApkInstallService::OnFinishedInstall(
9494
// happen if Play was busy with another install and this one is still queued
9595
// (and hence might succeed in the future).
9696
if (result == WebApkInstallResult::FAILURE) {
97-
content::WebContents* web_contents = observer->web_contents();
9897
if (!web_contents)
9998
return;
10099

101100
// TODO(https://crbug.com/861643): Support maskable icons here.
102-
ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, shortcut_info,
101+
ShortcutHelper::AddToLauncherWithSkBitmap(web_contents.get(), shortcut_info,
103102
primary_icon,
104103
/*is_icon_maskable=*/false);
105104
}

chrome/browser/android/webapk/webapk_install_service.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "base/memory/weak_ptr.h"
1717
#include "components/keyed_service/core/keyed_service.h"
1818
#include "components/webapps/browser/installable/installable_metrics.h"
19-
#include "content/public/browser/web_contents_observer.h"
2019
#include "url/gurl.h"
2120

2221
namespace base {
@@ -83,18 +82,8 @@ class WebApkInstallService : public KeyedService {
8382
FinishCallback finish_callback);
8483

8584
private:
86-
// Observes the lifetime of a WebContents.
87-
class LifetimeObserver : public content::WebContentsObserver {
88-
public:
89-
explicit LifetimeObserver(content::WebContents* web_contents)
90-
: WebContentsObserver(web_contents) {}
91-
92-
private:
93-
DISALLOW_COPY_AND_ASSIGN(LifetimeObserver);
94-
};
95-
9685
// Called once the install/update completed or failed.
97-
void OnFinishedInstall(std::unique_ptr<LifetimeObserver> observer,
86+
void OnFinishedInstall(base::WeakPtr<content::WebContents> web_contents,
9887
const webapps::ShortcutInfo& shortcut_info,
9988
const SkBitmap& primary_icon,
10089
bool is_priamry_icon_maskable,

0 commit comments

Comments
 (0)