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 void RegisterInputCallbacks(content::RenderViewHost* host); |
| 46 |
| 47 void RemoveInputCallbacks(content::RenderViewHost* host); |
| 48 |
| 49 void StartTimer(); |
| 50 |
| 51 // Callback that is fired at regular intervals to record site engagement based |
| 52 // on user input. |
| 53 void TimerFired(); |
| 54 |
30 // content::WebContentsObserver overrides. | 55 // content::WebContentsObserver overrides. |
31 void DidStartNavigationToPendingEntry( | 56 void DidStartNavigationToPendingEntry( |
32 const GURL& url, | 57 const GURL& url, |
33 content::NavigationController::ReloadType reload_type) override; | 58 content::NavigationController::ReloadType reload_type) override; |
34 | 59 |
| 60 void RenderViewHostChanged(content::RenderViewHost* old_host, |
| 61 content::RenderViewHost* new_host) override; |
| 62 |
| 63 void WasShown() override; |
| 64 |
| 65 void WasHidden() override; |
| 66 |
| 67 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_; |
| 68 content::RenderWidgetHost::MouseEventCallback mouse_event_callback_; |
| 69 |
| 70 bool user_input_recorded_; |
| 71 bool callbacks_added_; |
| 72 bool ignore_page_; |
| 73 base::RepeatingTimer<SiteEngagementHelper> timer_; |
| 74 |
35 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper); | 75 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper); |
36 }; | 76 }; |
37 | 77 |
38 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ | 78 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ |
OLD | NEW |