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

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: Remove flaky input simulation tests and combine callback and timer testing Created 5 years, 2 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.
20 class SiteEngagementHelper 22 class SiteEngagementHelper
21 : public content::WebContentsObserver, 23 : public content::WebContentsObserver,
22 public content::WebContentsUserData<SiteEngagementHelper> { 24 public content::WebContentsUserData<SiteEngagementHelper> {
23 public: 25 public:
24 ~SiteEngagementHelper() override; 26 ~SiteEngagementHelper() override;
25 27
28 static void SetSecondsBetweenUserInputCheck(double seconds);
29
26 private: 30 private:
31 // Class to encapsulate the user input listening.
32 //
33 // Time on site is recorded by detecting any user input (mouse or keypress)
34 // per some discrete time unit. If there is user input, then record a positive
35 // site engagement.
36 //
37 // When input is detected, SiteEngagementHelper::RecordUserInput is called,
38 // and the input detection callbacks are paused for
39 // g_seconds_between_user_input_check. This ensures that there is minimal
40 // overhead in input listening, and that input over an extended length of time
41 // is required to continually increase the engagement score.
42 class InputTracker {
43 public:
44 explicit InputTracker(SiteEngagementHelper* helper);
45 ~InputTracker();
46
47 // Callback to handle key press events from the RenderViewHost.
48 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event);
49
50 // Callback to handle mouse events from the RenderViewHost.
51 bool HandleMouseEvent(const blink::WebMouseEvent& event);
52
53 // Register callbacks to listen for user input.
54 void StartTracking(content::RenderViewHost* host);
55
56 // Pause listening for user input, restarting listening after
57 // g_seconds_between_user_input_check seconds.
58 void PauseTracking(content::RenderViewHost* host);
59
60 // Restart listening for user input.
61 void ResumeTracking();
62
63 // Stop listening for user input.
64 void StopTracking(content::RenderViewHost* host);
65
66 // Set the timer object for testing purposes.
67 void SetTimerForTesting(scoped_ptr<base::Timer> timer);
68
69 bool callbacks_added() { return callbacks_added_; }
70
71 private:
72 SiteEngagementHelper* helper_;
73 scoped_ptr<base::Timer> pause_timer_;
74 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_;
75 content::RenderWidgetHost::MouseEventCallback mouse_event_callback_;
76 bool callbacks_added_;
77 };
78
27 explicit SiteEngagementHelper(content::WebContents* web_contents); 79 explicit SiteEngagementHelper(content::WebContents* web_contents);
28 friend class content::WebContentsUserData<SiteEngagementHelper>; 80 friend class content::WebContentsUserData<SiteEngagementHelper>;
81 friend class SiteEngagementServiceBrowserTest;
82
83 // Ask the SiteEngagementService to record engagement via user input at the
84 // current contents location.
85 void RecordUserInput();
86
87 bool ShouldRecordEngagement();
29 88
30 // content::WebContentsObserver overrides. 89 // content::WebContentsObserver overrides.
31 void DidStartNavigationToPendingEntry( 90 void DidNavigateMainFrame(
32 const GURL& url, 91 const content::LoadCommittedDetails& details,
33 content::NavigationController::ReloadType reload_type) override; 92 const content::FrameNavigateParams& params) override;
93
94 void RenderViewHostChanged(content::RenderViewHost* old_host,
95 content::RenderViewHost* new_host) override;
96
97 void WasShown() override;
98 void WasHidden() override;
99
100 InputTracker input_tracker_;
101 bool record_engagement_;
34 102
35 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper); 103 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper);
36 }; 104 };
37 105
38 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ 106 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698