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

Side by Side Diff: chrome/browser/engagement/site_engagement_helper.h

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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ 5 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_
6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ 6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "chrome/browser/engagement/site_engagement_metrics.h" 10 #include "chrome/browser/engagement/site_engagement_metrics.h"
11 #include "chrome/browser/engagement/site_engagement_service.h" 11 #include "chrome/browser/engagement/site_engagement_service.h"
12 #include "content/public/browser/web_contents_observer.h" 12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h" 13 #include "content/public/browser/web_contents_user_data.h"
14 14
15 namespace content { 15 namespace content {
16 class NavigationHandle; 16 class NavigationHandle;
17 class WebContents; 17 class WebContents;
18 } 18 }
19 19
20 // Per-WebContents class to handle updating the site engagement scores for 20 // Per-WebContents class to handle updating the site engagement scores for
21 // origins. 21 // origins.
22 class SiteEngagementService::Helper 22 class SiteEngagementService::Helper
23 : public content::WebContentsObserver, 23 : public content::WebContentsObserver,
24 public content::WebContentsUserData<SiteEngagementService::Helper> { 24 public content::WebContentsUserData<SiteEngagementService::Helper> {
25 public: 25 public:
26 ~Helper() override; 26 ~Helper() override;
27 27
28 static void CreateForWebContents(content::WebContents* web_contents,
29 SiteEngagementService* service);
28 static void SetSecondsBetweenUserInputCheck(int seconds); 30 static void SetSecondsBetweenUserInputCheck(int seconds);
29 static void SetSecondsTrackingDelayAfterNavigation(int seconds); 31 static void SetSecondsTrackingDelayAfterNavigation(int seconds);
30 static void SetSecondsTrackingDelayAfterShow(int seconds); 32 static void SetSecondsTrackingDelayAfterShow(int seconds);
31 33
32 private: 34 private:
33 // Class to encapsulate the periodic detection of site engagement. 35 // Class to encapsulate the periodic detection of site engagement.
34 // 36 //
35 // Engagement detection begins at some constant time delta following 37 // Engagement detection begins at some constant time delta following
36 // navigation, tab activation, or media starting to play. Once engagement is 38 // navigation, tab activation, or media starting to play. Once engagement is
37 // recorded, detection is suspended for another constant time delta. For sites 39 // recorded, detection is suspended for another constant time delta. For sites
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 void MediaStoppedPlaying(const MediaPlayerId& id) override; 141 void MediaStoppedPlaying(const MediaPlayerId& id) override;
140 void WasShown() override; 142 void WasShown() override;
141 void WasHidden() override; 143 void WasHidden() override;
142 144
143 bool is_hidden_; 145 bool is_hidden_;
144 std::vector<MediaPlayerId> active_media_players_; 146 std::vector<MediaPlayerId> active_media_players_;
145 147
146 DISALLOW_COPY_AND_ASSIGN(MediaTracker); 148 DISALLOW_COPY_AND_ASSIGN(MediaTracker);
147 }; 149 };
148 150
149 explicit Helper(content::WebContents* web_contents); 151 Helper(content::WebContents* web_contents, SiteEngagementService* service);
150 friend class content::WebContentsUserData<SiteEngagementService::Helper>; 152 friend class content::WebContentsUserData<SiteEngagementService::Helper>;
151 friend class SiteEngagementHelperTest; 153 friend class SiteEngagementHelperTest;
152 154
153 // Ask the SiteEngagementService to record engagement via user input at the 155 // Ask the SiteEngagementService to record engagement via user input at the
154 // current WebContents URL. 156 // current WebContents URL.
155 void RecordUserInput(SiteEngagementMetrics::EngagementType type); 157 void RecordUserInput(SiteEngagementMetrics::EngagementType type);
156 158
157 // Ask the SiteEngagementService to record engagement via media playing at the 159 // Ask the SiteEngagementService to record engagement via media playing at the
158 // current WebContents URL. 160 // current WebContents URL.
159 void RecordMediaPlaying(bool is_hidden); 161 void RecordMediaPlaying(bool is_hidden);
160 162
161 // content::WebContentsObserver overrides. 163 // content::WebContentsObserver overrides.
162 void DidFinishNavigation(content::NavigationHandle* handle) override; 164 void DidFinishNavigation(content::NavigationHandle* handle) override;
163 void WasShown() override; 165 void WasShown() override;
164 void WasHidden() override; 166 void WasHidden() override;
165 167
166 InputTracker input_tracker_; 168 InputTracker input_tracker_;
167 MediaTracker media_tracker_; 169 MediaTracker media_tracker_;
170 SiteEngagementService* service_;
168 bool record_engagement_; 171 bool record_engagement_;
169 172
170 DISALLOW_COPY_AND_ASSIGN(Helper); 173 DISALLOW_COPY_AND_ASSIGN(Helper);
171 }; 174 };
172 175
173 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ 176 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698