OLD | NEW |
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 #include "third_party/WebKit/public/platform/site_engagement.mojom.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 class NavigationHandle; | 17 class NavigationHandle; |
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; | |
27 | |
28 static void SetSecondsBetweenUserInputCheck(int seconds); | 26 static void SetSecondsBetweenUserInputCheck(int seconds); |
29 static void SetSecondsTrackingDelayAfterNavigation(int seconds); | 27 static void SetSecondsTrackingDelayAfterNavigation(int seconds); |
30 static void SetSecondsTrackingDelayAfterShow(int seconds); | 28 static void SetSecondsTrackingDelayAfterShow(int seconds); |
31 | 29 |
| 30 ~Helper() override; |
| 31 |
| 32 void OnEngagementLevelChanged(const GURL& origin, |
| 33 blink::mojom::EngagementLevel level); |
| 34 |
32 private: | 35 private: |
33 // Class to encapsulate the periodic detection of site engagement. | 36 // Class to encapsulate the periodic detection of site engagement. |
34 // | 37 // |
35 // Engagement detection begins at some constant time delta following | 38 // Engagement detection begins at some constant time delta following |
36 // navigation, tab activation, or media starting to play. Once engagement is | 39 // navigation, tab activation, or media starting to play. Once engagement is |
37 // recorded, detection is suspended for another constant time delta. For sites | 40 // recorded, detection is suspended for another constant time delta. For sites |
38 // to continually record engagement, this overall design requires: | 41 // to continually record engagement, this overall design requires: |
39 // | 42 // |
40 // 1. engagement at a non-trivial time after a site loads | 43 // 1. engagement at a non-trivial time after a site loads |
41 // 2. continual engagement over a non-trivial duration of time | 44 // 2. continual engagement over a non-trivial duration of time |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 friend class SiteEngagementHelperTest; | 156 friend class SiteEngagementHelperTest; |
154 | 157 |
155 // Ask the SiteEngagementService to record engagement via user input at the | 158 // Ask the SiteEngagementService to record engagement via user input at the |
156 // current WebContents URL. | 159 // current WebContents URL. |
157 void RecordUserInput(SiteEngagementMetrics::EngagementType type); | 160 void RecordUserInput(SiteEngagementMetrics::EngagementType type); |
158 | 161 |
159 // Ask the SiteEngagementService to record engagement via media playing at the | 162 // Ask the SiteEngagementService to record engagement via media playing at the |
160 // current WebContents URL. | 163 // current WebContents URL. |
161 void RecordMediaPlaying(bool is_hidden); | 164 void RecordMediaPlaying(bool is_hidden); |
162 | 165 |
| 166 void SendEngagementLevelToFramesMatchingOrigin( |
| 167 const GURL& origin, |
| 168 blink::mojom::EngagementLevel level, |
| 169 content::RenderFrameHost* render_frame_host); |
| 170 void SendEngagementLevelToFrame(blink::mojom::EngagementLevel level, |
| 171 content::RenderFrameHost* render_frame_host); |
| 172 |
163 // content::WebContentsObserver overrides. | 173 // content::WebContentsObserver overrides. |
164 void DidFinishNavigation(content::NavigationHandle* handle) override; | 174 void DidFinishNavigation(content::NavigationHandle* handle) override; |
| 175 void ReadyToCommitNavigation(content::NavigationHandle* handle) override; |
165 void WasShown() override; | 176 void WasShown() override; |
166 void WasHidden() override; | 177 void WasHidden() override; |
167 | 178 |
168 InputTracker input_tracker_; | 179 InputTracker input_tracker_; |
169 MediaTracker media_tracker_; | 180 MediaTracker media_tracker_; |
170 SiteEngagementService* service_; | 181 SiteEngagementService* service_; |
171 | 182 |
172 DISALLOW_COPY_AND_ASSIGN(Helper); | 183 DISALLOW_COPY_AND_ASSIGN(Helper); |
173 }; | 184 }; |
174 | 185 |
175 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ | 186 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ |
OLD | NEW |