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

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: Use committed not visible URL 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..5cda08daba39331ecc44a0d740ab3be8aef1e822 100644
--- a/chrome/browser/engagement/site_engagement_helper.cc
+++ b/chrome/browser/engagement/site_engagement_helper.cc
@@ -162,37 +162,27 @@ SiteEngagementService::Helper::~Helper() {
}
}
-SiteEngagementService::Helper::Helper(content::WebContents* web_contents)
+SiteEngagementService::Helper::Helper(content::WebContents* web_contents,
+ SiteEngagementService* service)
: content::WebContentsObserver(web_contents),
input_tracker_(this, web_contents),
media_tracker_(this, web_contents),
+ service_(service),
calamity 2016/06/09 01:41:19 Can we use the web_contents->browser_context() to
dominickn 2016/06/09 03:25:47 Done.
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));
@@ -249,6 +235,17 @@ void SiteEngagementService::Helper::WasHidden() {
}
// static
+void SiteEngagementService::Helper::CreateForWebContents(
+ content::WebContents* web_contents,
+ SiteEngagementService* service) {
+ DCHECK(web_contents);
+ if (!FromWebContents(web_contents)) {
+ web_contents->SetUserData(UserDataKey(), new SiteEngagementService::Helper(
+ web_contents, service));
+ }
+}
+
+// static
void SiteEngagementService::Helper::SetSecondsBetweenUserInputCheck(
int seconds) {
g_seconds_to_pause_engagement_detection = seconds;
« no previous file with comments | « chrome/browser/engagement/site_engagement_helper.h ('k') | chrome/browser/engagement/site_engagement_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698