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

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

Issue 1427913002: Implement media playing engagement detection for the site engagement service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@user-input-event
Patch Set: Tests Created 5 years, 1 month 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" 9 #include "base/timer/timer.h"
10 #include "chrome/browser/engagement/site_engagement_metrics.h" 10 #include "chrome/browser/engagement/site_engagement_metrics.h"
(...skipping 19 matching lines...) Expand all
30 static void SetSecondsTrackingDelayAfterShow(int seconds); 30 static void SetSecondsTrackingDelayAfterShow(int seconds);
31 31
32 // content::WebContentsObserver overrides. 32 // content::WebContentsObserver overrides.
33 void DidNavigateMainFrame( 33 void DidNavigateMainFrame(
34 const content::LoadCommittedDetails& details, 34 const content::LoadCommittedDetails& details,
35 const content::FrameNavigateParams& params) override; 35 const content::FrameNavigateParams& params) override;
36 void WasShown() override; 36 void WasShown() override;
37 void WasHidden() override; 37 void WasHidden() override;
38 38
39 private: 39 private:
40 // Class to encapsulate the user input listening. 40 // Class to encapsulate the detection of site engagement.
41 // 41 //
42 // Time on site is recorded by detecting any user input (mouse click, 42 // All engagement detection begins at some constant time delta following
43 // keypress, or touch gesture tap) per some discrete time unit. If there is 43 // navigation or tab activation. Once engagement is recorded, detection is
44 // user input, then record a positive site engagement. 44 // suspended for another constant time delta. For sites to continually record
45 // engagement, this overall design requires:
45 // 46 //
46 // When input is detected, SiteEngagementHelper::RecordUserInput is called, 47 // 1. engagement at a non-trivial time after a site loads
47 // and the input detection callbacks are paused for 48 // 2. continual engagement over a non-trivial length of time
48 // g_seconds_between_user_input_check. This ensures that there is minimal 49 class EngagementTracker : public content::WebContentsObserver {
calamity 2015/11/03 04:49:46 I think the subclasses should be made into WebCont
dominickn 2015/11/03 07:03:54 Done.
49 // overhead in input listening, and that input over an extended length of time
50 // is required to continually increase the engagement score.
51 class InputTracker : public content::WebContentsObserver {
52 public: 50 public:
53 explicit InputTracker(content::WebContents* web_contents, 51 explicit EngagementTracker(content::WebContents* web_contents,
calamity 2015/11/03 04:49:46 This class is not so much a generic engagement tra
dominickn 2015/11/03 07:03:54 Great call. Done.
54 SiteEngagementHelper* helper); 52 SiteEngagementHelper* helper);
55 ~InputTracker() override; 53 ~EngagementTracker() override;
56 54
57 // Begin tracking input after |initial_delay|. 55 // Begin tracking input after |initial_delay|.
58 void Start(base::TimeDelta initial_delay); 56 void Start(base::TimeDelta initial_delay);
59 57
60 // Pause listening for user input, restarting listening after a delay. 58 // Pause listening for user input, restarting listening after a delay.
61 void Pause(); 59 void Pause();
62 60
63 // Stop listening for user input. 61 // Stop listening for user input.
64 void Stop(); 62 void Stop();
65 63
66 // Returns whether the tracker will respond to user input via 64 // Returns whether the tracker will respond to user input via
67 // DidGetUserInteraction. 65 // DidGetUserInteraction.
68 bool is_tracking() const { return is_tracking_; } 66 bool is_tracking() const { return is_tracking_; }
69 67
70 // Set the timer object for testing purposes. 68 // Set the timer object for testing purposes.
71 void SetPauseTimerForTesting(scoped_ptr<base::Timer> timer); 69 void SetPauseTimerForTesting(scoped_ptr<base::Timer> timer);
72 70
73 private: 71 protected:
74 friend class SiteEngagementHelperTest; 72 friend class SiteEngagementHelperTest;
75 73
76 // Starts the timer for detecting user interaction. 74 // Starts the timer for detecting user interaction.
calamity 2015/11/03 04:49:46 nit: Update all comments.
dominickn 2015/11/03 07:03:54 Done.
77 void StartTimer(base::TimeDelta delay); 75 void StartTimer(base::TimeDelta delay);
78 76
79 // Callback for StartTimer that activates the user input tracking. 77 // Callback for StartTimer that activates the user input tracking.
80 void StartTracking(); 78 virtual void StartTracking();
81
82 // content::WebContentsObserver overrides.
83 void DidGetUserInteraction(const blink::WebInputEvent::Type type) override;
84 79
calamity 2015/11/03 04:49:46 Data members should be private. Add accessors as n
dominickn 2015/11/03 07:03:54 Done.
85 SiteEngagementHelper* helper_; 80 SiteEngagementHelper* helper_;
86 scoped_ptr<base::Timer> pause_timer_; 81 scoped_ptr<base::Timer> pause_timer_;
87 bool is_tracking_; 82 bool is_tracking_;
88 }; 83 };
89 84
85 // Class to encapsulate time-on-site engagement. Time-on-site is recorded by
86 // detecting user input on a focused WebContents (mouse click, keypress, or
87 // touch gesture tap) over time.
calamity 2015/11/03 04:49:46 Comments for these concrete tracker classes should
dominickn 2015/11/03 07:03:54 Done.
88 class InputTracker : public EngagementTracker {
89 public:
90 explicit InputTracker(content::WebContents* web_contents,
calamity 2015/11/03 04:49:46 nit: explicit only for single argument constructor
dominickn 2015/11/03 07:03:54 Done.
91 SiteEngagementHelper* helper);
92
93 private:
94 friend class SiteEngagementHelperTest;
95
96 // content::WebContentsObserver overrides.
97 void DidGetUserInteraction(const blink::WebInputEvent::Type type) override;
98 };
99
100 // Class to encapsulate media detection. Any media playing in a WebContents
101 // (focused or not) will accumulate engagement points. Media in a hidden
102 // WebContents will accumulate engagement more slowly than in an active
103 // WebContents. Media which has been muted will also accumulate engagement
104 // more slowly.
105 class MediaTracker : public EngagementTracker {
106 public:
107 explicit MediaTracker(content::WebContents* web_contents,
108 SiteEngagementHelper* helper);
109
110 private:
111 friend class SiteEngagementHelperTest;
112
113 void StartTracking() override;
114
115 // content::WebContentsObserver overrides.
116 void MediaStartedPlaying() override;
117 void MediaPaused() override;
118 void WasShown() override;
119 void WasHidden() override;
120
121 bool is_hidden_;
122 bool is_playing_;
123 };
124
90 explicit SiteEngagementHelper(content::WebContents* web_contents); 125 explicit SiteEngagementHelper(content::WebContents* web_contents);
91 friend class content::WebContentsUserData<SiteEngagementHelper>; 126 friend class content::WebContentsUserData<SiteEngagementHelper>;
92 friend class SiteEngagementHelperTest; 127 friend class SiteEngagementHelperTest;
93 128
94 // Ask the SiteEngagementService to record engagement via user input at the 129 // Ask the SiteEngagementService to record engagement via user input at the
95 // current contents location. 130 // current WebContents URL.
96 void RecordUserInput(SiteEngagementMetrics::EngagementType type); 131 void RecordUserInput(SiteEngagementMetrics::EngagementType type);
97 132
133 // Ask the SiteEngagementService to record engagement via media playing at the
134 // current WebContents URL.
135 void RecordMediaPlaying(bool is_hidden);
136
98 InputTracker input_tracker_; 137 InputTracker input_tracker_;
138 MediaTracker media_tracker_;
99 bool record_engagement_; 139 bool record_engagement_;
100 140
101 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper); 141 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper);
102 }; 142 };
103 143
104 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ 144 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698