| 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" | 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 // Switches the InputTracker to another RenderViewHost, respecting the pause | 72 // Switches the InputTracker to another RenderViewHost, respecting the pause |
| 73 // timer state. | 73 // timer state. |
| 74 void SwitchRenderViewHost(content::RenderViewHost* old_host, | 74 void SwitchRenderViewHost(content::RenderViewHost* old_host, |
| 75 content::RenderViewHost* new_host); | 75 content::RenderViewHost* new_host); |
| 76 | 76 |
| 77 // Stop listening for user input. | 77 // Stop listening for user input. |
| 78 void Stop(); | 78 void Stop(); |
| 79 | 79 |
| 80 // Returns whether the InputTracker has been started for a RenderViewHost. | 80 // Returns whether the InputTracker has been started for a RenderViewHost. |
| 81 bool is_active() const { return is_active_; } | 81 bool IsActive() const; |
| 82 | 82 |
| 83 // Returns whether input tracking callbacks have been added to | 83 // Returns whether input tracking callbacks have been added to |
| 84 // RenderViewHost. | 84 // RenderViewHost. |
| 85 bool is_tracking() const { return is_tracking_; } | 85 bool is_tracking() const { return is_tracking_; } |
| 86 | 86 |
| 87 content::RenderViewHost* host() const { return host_; } |
| 88 |
| 87 // Set the timer object for testing purposes. | 89 // Set the timer object for testing purposes. |
| 88 void SetPauseTimerForTesting(scoped_ptr<base::Timer> timer); | 90 void SetPauseTimerForTesting(scoped_ptr<base::Timer> timer); |
| 89 | 91 |
| 90 private: | 92 private: |
| 91 // Starts the timer for adding callbacks to the RenderViewHost. | 93 // Starts the timer for adding callbacks to the RenderViewHost. |
| 92 void StartTimer(base::TimeDelta delay); | 94 void StartTimer(base::TimeDelta delay); |
| 93 | 95 |
| 94 // Adds/removes tracking callbacks to the RenderViewHost. | 96 // Adds/removes tracking callbacks to the RenderViewHost. |
| 95 void AddCallbacks(); | 97 void AddCallbacks(); |
| 96 void RemoveCallbacks(); | 98 void RemoveCallbacks(); |
| 97 | 99 |
| 98 SiteEngagementHelper* helper_; | 100 SiteEngagementHelper* helper_; |
| 99 scoped_ptr<base::Timer> pause_timer_; | 101 scoped_ptr<base::Timer> pause_timer_; |
| 100 content::RenderViewHost* host_; | 102 content::RenderViewHost* host_; |
| 101 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_; | 103 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_; |
| 102 content::RenderWidgetHost::MouseEventCallback mouse_event_callback_; | 104 content::RenderWidgetHost::MouseEventCallback mouse_event_callback_; |
| 103 bool is_active_; | |
| 104 bool is_tracking_; | 105 bool is_tracking_; |
| 105 }; | 106 }; |
| 106 | 107 |
| 107 explicit SiteEngagementHelper(content::WebContents* web_contents); | 108 explicit SiteEngagementHelper(content::WebContents* web_contents); |
| 108 friend class content::WebContentsUserData<SiteEngagementHelper>; | 109 friend class content::WebContentsUserData<SiteEngagementHelper>; |
| 109 friend class SiteEngagementServiceBrowserTest; | 110 friend class SiteEngagementServiceBrowserTest; |
| 110 | 111 |
| 111 // Ask the SiteEngagementService to record engagement via user input at the | 112 // Ask the SiteEngagementService to record engagement via user input at the |
| 112 // current contents location. | 113 // current contents location. |
| 113 void RecordUserInput(SiteEngagementMetrics::EngagementType type); | 114 void RecordUserInput(SiteEngagementMetrics::EngagementType type); |
| 114 | 115 |
| 115 InputTracker input_tracker_; | 116 InputTracker input_tracker_; |
| 116 bool record_engagement_; | 117 bool record_engagement_; |
| 117 | 118 |
| 118 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper); | 119 DISALLOW_COPY_AND_ASSIGN(SiteEngagementHelper); |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ | 122 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_HELPER_H_ |
| OLD | NEW |