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

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

Issue 1338603002: Implement a site engagement score based on time-on-site. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore unit tests to test navigations Created 5 years, 3 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"
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
35 static void SetSecondsBetweenUserInputCheck(double seconds);
36 static void DisableCallbackRegistrationForTesting();
calamity 2015/09/22 02:57:21 If these are for testing and the test class is fri
dominickn 2015/09/23 00:06:44 Done.
37
26 private: 38 private:
39 // Class to encapsulate the user input listening.
40 //
41 // User input is used to record time-on-site. When input is detected,
42 // SiteEngagementHelper::RecordUserInput is called, and the input detection
43 // callbacks are paused for a duration of gSecondsBetweenUserInputCheck. This
44 // ensures that there is minimal overhead in input listening, and that input
45 // over an extended length of time is required to continually increase the
46 // engagement score.
47 class InputTracker {
48 public:
49 explicit InputTracker(SiteEngagementHelper* helper);
50 ~InputTracker();
51
52 // Callback to handle key press events from the RenderViewHost.
53 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event);
54
55 // Callback to handle mouse events from the RenderViewHost.
56 bool HandleMouseEvent(const blink::WebMouseEvent& event);
57
58 // Register callbacks to listen for user input.
59 void StartTracking(content::RenderViewHost* host);
60
61 // Pause listening for user input, restarting listening after
62 // gSecondsBetweenUserInputCheck seconds.
63 void PauseTracking(content::RenderViewHost* host);
64
65 // Restart listening for user input.
66 void ResumeTracking();
67
68 // Stop listening for user input.
69 void StopTracking(content::RenderViewHost* host);
70
71 // Set the timer object for testing purposes.
72 void SetTimerForTesting(scoped_ptr<base::Timer> timer);
73
74 private:
75 SiteEngagementHelper* helper_;
76 scoped_ptr<base::Timer> timer_;
77 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_;
78 content::RenderWidgetHost::MouseEventCallback mouse_event_callback_;
79 bool callbacks_added_;
80 };
81
27 explicit SiteEngagementHelper(content::WebContents* web_contents); 82 explicit SiteEngagementHelper(content::WebContents* web_contents);
28 friend class content::WebContentsUserData<SiteEngagementHelper>; 83 friend class content::WebContentsUserData<SiteEngagementHelper>;
84 friend class SiteEngagementServiceBrowserTest;
85
86 // Ask the SiteEngagementService to record engagement via user input at the
87 // current contents location.
88 void RecordUserInput();
89
29 90
30 // content::WebContentsObserver overrides. 91 // content::WebContentsObserver overrides.
31 void DidStartNavigationToPendingEntry( 92 void DidNavigateMainFrame(
32 const GURL& url, 93 const content::LoadCommittedDetails& details,
33 content::NavigationController::ReloadType reload_type) override; 94 const content::FrameNavigateParams& params) override;
95
96 void RenderViewHostChanged(content::RenderViewHost* old_host,
97 content::RenderViewHost* new_host) override;
98
99 void WasShown() override;
100 void WasHidden() override;
101
102 scoped_ptr<InputTracker> tracker_;
103 bool record_engagement_;
34 104
35 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper); 105 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper);
36 }; 106 };
37 107
38 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ 108 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698