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" |
| 10 #include "content/public/browser/render_view_host.h" |
9 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
10 #include "content/public/browser/web_contents_user_data.h" | 12 #include "content/public/browser/web_contents_user_data.h" |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 class WebContents; | 15 class WebContents; |
14 } | 16 } |
15 | 17 |
16 class GURL; | 18 class GURL; |
17 | 19 |
18 // Per-WebContents class to handle updating the site engagement scores for | 20 // Per-WebContents class to handle updating the site engagement scores for |
19 // origins as the user navigates. | 21 // origins based on the time spent on site. |
| 22 // |
| 23 // Time on site is recorded by detecting any user input (mouse or keypress) per |
| 24 // some discrete time unit. If there is user input, then record a positive site |
| 25 // engagement. |
| 26 // |
| 27 // TODO(dominickn): account for use cases where user input is not a good proxy |
| 28 // for time on site: e.g. watching videos. |
20 class SiteEngagementHelper | 29 class SiteEngagementHelper |
21 : public content::WebContentsObserver, | 30 : public content::WebContentsObserver, |
22 public content::WebContentsUserData<SiteEngagementHelper> { | 31 public content::WebContentsUserData<SiteEngagementHelper> { |
23 public: | 32 public: |
24 ~SiteEngagementHelper() override; | 33 ~SiteEngagementHelper() override; |
25 | 34 |
26 private: | 35 private: |
27 explicit SiteEngagementHelper(content::WebContents* web_contents); | 36 explicit SiteEngagementHelper(content::WebContents* web_contents); |
28 friend class content::WebContentsUserData<SiteEngagementHelper>; | 37 friend class content::WebContentsUserData<SiteEngagementHelper>; |
29 | 38 |
| 39 // Callback to register key press events from the RenderViewHost. |
| 40 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event); |
| 41 |
| 42 // Callback to register mouse events from the RenderViewHost. |
| 43 bool HandleMouseEvent(const blink::WebMouseEvent& event); |
| 44 |
| 45 // Callback that is fired at regular intervals to record site engagement based |
| 46 // on user input. |
| 47 void TimerFired(); |
| 48 |
| 49 void StartTimer(); |
| 50 |
30 // content::WebContentsObserver overrides. | 51 // content::WebContentsObserver overrides. |
31 void DidStartNavigationToPendingEntry( | 52 void RenderViewHostChanged(content::RenderViewHost* old_host, |
32 const GURL& url, | 53 content::RenderViewHost* new_host) override; |
33 content::NavigationController::ReloadType reload_type) override; | 54 |
| 55 void WasShown() override; |
| 56 |
| 57 void WasHidden() override; |
| 58 |
| 59 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_; |
| 60 content::RenderWidgetHost::MouseEventCallback mouse_event_callback_; |
| 61 |
| 62 bool user_input_recorded_; |
| 63 bool callbacks_added_; |
| 64 base::RepeatingTimer<SiteEngagementHelper> timer_; |
| 65 |
34 | 66 |
35 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper); | 67 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper); |
36 }; | 68 }; |
37 | 69 |
38 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ | 70 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ |
OLD | NEW |