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