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

Unified Diff: chrome/browser/engagement/site_engagement_helper.h

Issue 1388293002: Notify WebContentsObservers of user interactions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/engagement/site_engagement_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/engagement/site_engagement_helper.h
diff --git a/chrome/browser/engagement/site_engagement_helper.h b/chrome/browser/engagement/site_engagement_helper.h
index c7f9e65206c2c8dd1790fa0e15dda265a945baed..9ba18079767d2f56a099f6eaf6c4a384dd671377 100644
--- a/chrome/browser/engagement/site_engagement_helper.h
+++ b/chrome/browser/engagement/site_engagement_helper.h
@@ -8,8 +8,6 @@
#include "base/macros.h"
#include "base/timer/timer.h"
#include "chrome/browser/engagement/site_engagement_metrics.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
@@ -35,79 +33,63 @@ class SiteEngagementHelper
void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) override;
- void RenderViewHostChanged(content::RenderViewHost* old_host,
- content::RenderViewHost* new_host) override;
void WasShown() override;
void WasHidden() override;
private:
// Class to encapsulate the user input listening.
//
- // Time on site is recorded by detecting any user input (mouse or keypress)
- // per some discrete time unit. If there is user input, then record a positive
- // site engagement.
+ // Time on site is recorded by detecting any user input (mouse click,
+ // keypress, or touch gesture tap) per some discrete time unit. If there is
+ // user input, then record a positive site engagement.
//
// When input is detected, SiteEngagementHelper::RecordUserInput is called,
// and the input detection callbacks are paused for
// g_seconds_between_user_input_check. This ensures that there is minimal
// overhead in input listening, and that input over an extended length of time
// is required to continually increase the engagement score.
- class InputTracker {
+ class InputTracker : public content::WebContentsObserver {
public:
- explicit InputTracker(SiteEngagementHelper* helper);
- ~InputTracker();
-
- // Callback to handle key press events from the RenderViewHost.
- bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event);
-
- // Callback to handle mouse events from the RenderViewHost.
- bool HandleMouseEvent(const blink::WebMouseEvent& event);
+ explicit InputTracker(content::WebContents* web_contents,
+ SiteEngagementHelper* helper);
+ ~InputTracker() override;
// Begin tracking input after |initial_delay|.
- void Start(content::RenderViewHost* host, base::TimeDelta initial_delay);
+ void Start(base::TimeDelta initial_delay);
// Pause listening for user input, restarting listening after a delay.
void Pause();
- // Switches the InputTracker to another RenderViewHost, respecting the pause
- // timer state.
- void SwitchRenderViewHost(content::RenderViewHost* old_host,
- content::RenderViewHost* new_host);
-
// Stop listening for user input.
void Stop();
- // Returns whether the InputTracker has been started for a RenderViewHost.
- bool IsActive() const;
-
- // Returns whether input tracking callbacks have been added to
- // RenderViewHost.
+ // Returns whether the tracker will respond to user input via
+ // DidGetUserInteraction.
bool is_tracking() const { return is_tracking_; }
- content::RenderViewHost* host() const { return host_; }
-
// Set the timer object for testing purposes.
void SetPauseTimerForTesting(scoped_ptr<base::Timer> timer);
private:
- // Starts the timer for adding callbacks to the RenderViewHost.
+ friend class SiteEngagementHelperTest;
+
+ // Starts the timer for detecting user interaction.
void StartTimer(base::TimeDelta delay);
- // Adds/removes tracking callbacks to the RenderViewHost.
- void AddCallbacks();
- void RemoveCallbacks();
+ // Callback for StartTimer that activates the user input tracking.
+ void StartTracking();
+
+ // content::WebContentsObserver overrides.
+ void DidGetUserInteraction(const blink::WebInputEvent::Type type) override;
SiteEngagementHelper* helper_;
scoped_ptr<base::Timer> pause_timer_;
- content::RenderViewHost* host_;
- content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_;
- content::RenderWidgetHost::MouseEventCallback mouse_event_callback_;
bool is_tracking_;
};
explicit SiteEngagementHelper(content::WebContents* web_contents);
friend class content::WebContentsUserData<SiteEngagementHelper>;
- friend class SiteEngagementServiceBrowserTest;
+ friend class SiteEngagementHelperTest;
// Ask the SiteEngagementService to record engagement via user input at the
// current contents location.
« no previous file with comments | « no previous file | chrome/browser/engagement/site_engagement_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698