Chromium Code Reviews| Index: chrome/browser/ui/search/instant_controller.cc |
| diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc |
| index 18ca74516879b527a6e8efeb77542faecfa16796..003513eeb4ba1b859f33c8ec5639c0095de8b6c4 100644 |
| --- a/chrome/browser/ui/search/instant_controller.cc |
| +++ b/chrome/browser/ui/search/instant_controller.cc |
| @@ -43,6 +43,7 @@ |
| #include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/user_metrics.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_contents_user_data.h" |
| #include "content/public/browser/web_contents_view.h" |
| #include "net/base/escape.h" |
| #include "net/base/network_change_notifier.h" |
| @@ -250,8 +251,40 @@ void DeletePageSoon(scoped_ptr<T> page) { |
| base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); |
| } |
| +// Helper class for logging data from the NTP. Attached to each InstantNTP |
| +// instance. |
| +class NtpLoggingUserData |
| + : public content::WebContentsUserData<NtpLoggingUserData> { |
| + public: |
| + virtual ~NtpLoggingUserData() {} |
| + |
| + // Called each time the mouse hovers over an iframe or title. |
| + void increment_number_of_mouseovers() { |
| + number_of_mouseovers++; |
| + } |
| + |
| + // Logs total number of mouseovers per NTP session to UMA histogram. |
| + // Called when a tab is about to be deactivated. |
| + void log_number_of_mouseovers() { |
| + if (number_of_mouseovers > 0) { |
| + UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", |
|
Mark P
2013/06/25 19:04:32
Why do you only log if the number is greater than
annark1
2013/06/25 21:04:11
As per our offline discussion, I've addressed this
|
| + number_of_mouseovers); |
| + number_of_mouseovers = 0; |
| + } |
| + } |
| + |
| + private: |
| + explicit NtpLoggingUserData(content::WebContents* contents) |
| + : number_of_mouseovers(0) {} |
| + friend class content::WebContentsUserData<NtpLoggingUserData>; |
| + |
| + int number_of_mouseovers; |
| +}; |
|
Alexei Svitkine (slow)
2013/06/25 17:21:20
Should this have DISALLOW_COPY_AND_ASSIGN(NtpLoggi
annark1
2013/06/25 21:04:11
Done.
|
| + |
| } // namespace |
| +DEFINE_WEB_CONTENTS_USER_DATA_KEY(NtpLoggingUserData); |
| + |
| InstantController::InstantController(BrowserInstantController* browser, |
| bool extended_enabled) |
| : browser_(browser), |
| @@ -1062,6 +1095,11 @@ void InstantController::TabDeactivated(content::WebContents* contents) { |
| if (GetOverlayContents()) |
| HideOverlay(); |
| + |
| + NtpLoggingUserData* data = |
| + NtpLoggingUserData::FromWebContents(contents); |
| + if (data) |
| + data->log_number_of_mouseovers(); |
| } |
| void InstantController::SetInstantEnabled(bool instant_enabled, |
| @@ -1602,6 +1640,10 @@ void InstantController::ResetNTP(const std::string& instant_url) { |
| ntp_->InitContents(profile(), browser_->GetActiveWebContents(), |
| base::Bind(&InstantController::ReloadStaleNTP, |
| base::Unretained(this))); |
| + |
| + if (ntp_->contents()) |
| + NtpLoggingUserData::CreateForWebContents(ntp_->contents()); |
| + |
| LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| "ResetNTP: instant_url='%s'", instant_url.c_str())); |
| } |
| @@ -1900,6 +1942,16 @@ void InstantController::PopulateInstantAutocompleteResultFromMatch( |
| << result->transition << " " << result->autocomplete_match_index; |
| } |
| +void InstantController::LogIframeHover() { |
| + if (!browser_ || !browser_->GetActiveWebContents()) |
| + return; |
| + |
| + NtpLoggingUserData* data = |
| + NtpLoggingUserData::FromWebContents(browser_->GetActiveWebContents()); |
| + if (data) |
| + data->increment_number_of_mouseovers(); |
| +} |
| + |
| bool InstantController::IsJavascriptEnabled() const { |
| GURL instant_url(GetInstantURL()); |
| GURL origin(instant_url.GetOrigin()); |