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

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

Issue 1368533004: Add UMA metrics to the site engagement service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@time-on-site
Patch Set: Refactor tests 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 #include "chrome/browser/engagement/site_engagement_helper.h" 5 #include "chrome/browser/engagement/site_engagement_helper.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "chrome/browser/engagement/site_engagement_service.h" 9 #include "chrome/browser/engagement/site_engagement_service.h"
10 #include "chrome/browser/engagement/site_engagement_service_factory.h" 10 #include "chrome/browser/engagement/site_engagement_service_factory.h"
(...skipping 28 matching lines...) Expand all
39 // web_contents() will return nullptr if the observed contents have been 39 // web_contents() will return nullptr if the observed contents have been
40 // deleted; if the contents exist, record engagement for the site. Once the 40 // deleted; if the contents exist, record engagement for the site. Once the
41 // timer finishes running, the callbacks detecting user input will be registered 41 // timer finishes running, the callbacks detecting user input will be registered
42 // again. 42 // again.
43 bool SiteEngagementHelper::InputTracker::HandleKeyPressEvent( 43 bool SiteEngagementHelper::InputTracker::HandleKeyPressEvent(
44 const content::NativeWebKeyboardEvent& event) { 44 const content::NativeWebKeyboardEvent& event) {
45 // Only respond to raw key down to avoid multiple triggering on a single input 45 // Only respond to raw key down to avoid multiple triggering on a single input
46 // (e.g. keypress is a key down then key up). 46 // (e.g. keypress is a key down then key up).
47 if (event.type == blink::WebInputEvent::RawKeyDown) { 47 if (event.type == blink::WebInputEvent::RawKeyDown) {
48 PauseTracking(helper_->web_contents()->GetRenderViewHost()); 48 PauseTracking(helper_->web_contents()->GetRenderViewHost());
49 helper_->RecordUserInput(); 49 helper_->RecordUserInput(SiteEngagementMetrics::ENGAGEMENT_KEYPRESS);
50 } 50 }
51 return false; 51 return false;
52 } 52 }
53 53
54 bool SiteEngagementHelper::InputTracker::HandleMouseEvent( 54 bool SiteEngagementHelper::InputTracker::HandleMouseEvent(
55 const blink::WebMouseEvent& event) { 55 const blink::WebMouseEvent& event) {
56 // Only respond to mouse down with a button or mouse move events (e.g. a click 56 // Only respond to mouse down with a button or mouse move events (e.g. a click
57 // is a mouse down and mouse up) to avoid cases where multiple events come in 57 // is a mouse down and mouse up) to avoid cases where multiple events come in
58 // before we can pause tracking. 58 // before we can pause tracking.
59 if ((event.button != blink::WebMouseEvent::ButtonNone && 59 if ((event.button != blink::WebMouseEvent::ButtonNone &&
60 event.type == blink::WebInputEvent::MouseDown) || 60 event.type == blink::WebInputEvent::MouseDown) ||
61 event.type == blink::WebInputEvent::MouseWheel) { 61 event.type == blink::WebInputEvent::MouseWheel) {
62 PauseTracking(helper_->web_contents()->GetRenderViewHost()); 62 PauseTracking(helper_->web_contents()->GetRenderViewHost());
63 helper_->RecordUserInput(); 63 helper_->RecordUserInput(SiteEngagementMetrics::ENGAGEMENT_MOUSE);
64 } 64 }
65 return false; 65 return false;
66 } 66 }
67 67
68 void SiteEngagementHelper::InputTracker::StartTracking( 68 void SiteEngagementHelper::InputTracker::StartTracking(
69 content::RenderViewHost* host) { 69 content::RenderViewHost* host) {
70 if (!callbacks_added_) { 70 if (!callbacks_added_) {
71 host->AddKeyPressEventCallback(key_press_event_callback_); 71 host->AddKeyPressEventCallback(key_press_event_callback_);
72 host->AddMouseEventCallback(mouse_event_callback_); 72 host->AddMouseEventCallback(mouse_event_callback_);
73 callbacks_added_ = true; 73 callbacks_added_ = true;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 content::WebContents* contents = web_contents(); 109 content::WebContents* contents = web_contents();
110 if (contents) 110 if (contents)
111 input_tracker_.StopTracking(contents->GetRenderViewHost()); 111 input_tracker_.StopTracking(contents->GetRenderViewHost());
112 } 112 }
113 113
114 SiteEngagementHelper::SiteEngagementHelper(content::WebContents* contents) 114 SiteEngagementHelper::SiteEngagementHelper(content::WebContents* contents)
115 : content::WebContentsObserver(contents), 115 : content::WebContentsObserver(contents),
116 input_tracker_(this), 116 input_tracker_(this),
117 record_engagement_(false) { } 117 record_engagement_(false) { }
118 118
119 void SiteEngagementHelper::RecordUserInput() { 119 void SiteEngagementHelper::RecordUserInput(
120 SiteEngagementMetrics::EngagementType type) {
120 TRACE_EVENT0("SiteEngagement", "RecordUserInput"); 121 TRACE_EVENT0("SiteEngagement", "RecordUserInput");
121 content::WebContents* contents = web_contents(); 122 content::WebContents* contents = web_contents();
122 if (contents) { 123 if (contents) {
123 Profile* profile = 124 Profile* profile =
124 Profile::FromBrowserContext(contents->GetBrowserContext()); 125 Profile::FromBrowserContext(contents->GetBrowserContext());
125 SiteEngagementService* service = 126 SiteEngagementService* service =
126 SiteEngagementServiceFactory::GetForProfile(profile); 127 SiteEngagementServiceFactory::GetForProfile(profile);
127 128
128 // Service is null in incognito. 129 // Service is null in incognito.
129 if (service) 130 if (service)
130 service->HandleUserInput(contents->GetVisibleURL()); 131 service->HandleUserInput(contents->GetVisibleURL(), type);
131 } 132 }
132 } 133 }
133 134
134 bool SiteEngagementHelper::ShouldRecordEngagement() { 135 bool SiteEngagementHelper::ShouldRecordEngagement() {
135 return record_engagement_; 136 return record_engagement_;
136 } 137 }
137 138
138 void SiteEngagementHelper::DidNavigateMainFrame( 139 void SiteEngagementHelper::DidNavigateMainFrame(
139 const content::LoadCommittedDetails& details, 140 const content::LoadCommittedDetails& details,
140 const content::FrameNavigateParams& params) { 141 const content::FrameNavigateParams& params) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 content::WebContents* contents = web_contents(); 183 content::WebContents* contents = web_contents();
183 if (contents) 184 if (contents)
184 input_tracker_.StopTracking(contents->GetRenderViewHost()); 185 input_tracker_.StopTracking(contents->GetRenderViewHost());
185 } 186 }
186 } 187 }
187 188
188 // static 189 // static
189 void SiteEngagementHelper::SetSecondsBetweenUserInputCheck(double seconds) { 190 void SiteEngagementHelper::SetSecondsBetweenUserInputCheck(double seconds) {
190 g_seconds_between_user_input_check = seconds; 191 g_seconds_between_user_input_check = seconds;
191 } 192 }
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_helper.h ('k') | chrome/browser/engagement/site_engagement_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698