Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1121)

Unified Diff: chrome/browser/engagement/site_engagement_helper.cc

Issue 2042243004: Construct the site engagement helper with a site engagement service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address reviewer comments, rebase to fix leak Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/engagement/site_engagement_helper.cc
diff --git a/chrome/browser/engagement/site_engagement_helper.cc b/chrome/browser/engagement/site_engagement_helper.cc
index 6e5f9400e4c04db18bbde4a222b3daa66ba79a9b..ac3d3210ad43ae6523ed455f5198a1af48b6f491 100644
--- a/chrome/browser/engagement/site_engagement_helper.cc
+++ b/chrome/browser/engagement/site_engagement_helper.cc
@@ -166,33 +166,23 @@ SiteEngagementService::Helper::Helper(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
input_tracker_(this, web_contents),
media_tracker_(this, web_contents),
+ service_(SiteEngagementService::Get(
+ Profile::FromBrowserContext(web_contents->GetBrowserContext()))),
record_engagement_(false) {}
void SiteEngagementService::Helper::RecordUserInput(
SiteEngagementMetrics::EngagementType type) {
TRACE_EVENT0("SiteEngagement", "RecordUserInput");
content::WebContents* contents = web_contents();
- if (contents) {
- Profile* profile =
- Profile::FromBrowserContext(contents->GetBrowserContext());
- SiteEngagementService* service = SiteEngagementService::Get(profile);
-
- // Service is null in incognito.
- if (service)
- service->HandleUserInput(contents->GetVisibleURL(), type);
- }
+ // Service is null in incognito.
+ if (contents && service_)
+ service_->HandleUserInput(contents, type);
}
void SiteEngagementService::Helper::RecordMediaPlaying(bool is_hidden) {
content::WebContents* contents = web_contents();
- if (contents) {
- Profile* profile =
- Profile::FromBrowserContext(contents->GetBrowserContext());
- SiteEngagementService* service = SiteEngagementService::Get(profile);
-
- if (service)
- service->HandleMediaPlaying(contents->GetVisibleURL(), is_hidden);
- }
+ if (contents && service_)
+ service_->HandleMediaPlaying(contents, is_hidden);
}
void SiteEngagementService::Helper::DidFinishNavigation(
@@ -224,12 +214,8 @@ void SiteEngagementService::Helper::DidFinishNavigation(
if (prerender::PrerenderContents::FromWebContents(web_contents()) != nullptr)
return;
- Profile* profile =
- Profile::FromBrowserContext(web_contents()->GetBrowserContext());
- SiteEngagementService* service = SiteEngagementService::Get(profile);
-
- if (service)
- service->HandleNavigation(handle->GetURL(), handle->GetPageTransition());
+ if (service_)
+ service_->HandleNavigation(web_contents(), handle->GetPageTransition());
input_tracker_.Start(
base::TimeDelta::FromSeconds(g_seconds_delay_after_navigation));

Powered by Google App Engine
This is Rietveld 408576698