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..8519d90ee24e509776269b8eada05bc9ac3d0155 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,46 @@ 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 |
Jered
2013/06/26 16:37:57
instant_controller.cc feels like the wrong place f
annark1
2013/06/28 15:30:49
Done.
|
+// instance. |
+class NtpLoggingUserData |
Jered
2013/06/26 16:37:57
Ntp -> NTP.
annark1
2013/06/28 15:30:49
Done.
|
+ : 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 (be it by switching tabs, losing |
+ // focus or closing the tab/shutting down Chrome) or when the contents of the |
+ // current tab is replaced. Does not log 0 mouseover cases (for instance if a |
Jered
2013/06/26 16:37:57
Why not log the case with 0 hovers? This seems lik
annark1
2013/06/28 15:30:49
After offline discussions with Jered and Mark Pear
|
+ // user opens the NTP then immediately switches to another tab without |
+ // interacting with the NTP). |
+ void log_number_of_mouseovers() { |
+ if (number_of_mouseovers > 0) { |
+ UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", |
+ 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; |
Jered
2013/06/26 16:37:57
Member variables should end with _.
annark1
2013/06/28 15:30:49
Done.
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(NtpLoggingUserData); |
+}; |
+ |
} // namespace |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(NtpLoggingUserData); |
+ |
InstantController::InstantController(BrowserInstantController* browser, |
bool extended_enabled) |
: browser_(browser), |
@@ -1062,6 +1101,9 @@ void InstantController::TabDeactivated(content::WebContents* contents) { |
if (GetOverlayContents()) |
HideOverlay(); |
+ |
+ if (NtpLoggingUserData::FromWebContents(contents)) |
+ NtpLoggingUserData::FromWebContents(contents)->log_number_of_mouseovers(); |
} |
void InstantController::SetInstantEnabled(bool instant_enabled, |
@@ -1602,6 +1644,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())); |
} |
@@ -1675,6 +1721,11 @@ void InstantController::ResetInstantTab() { |
} else { |
instant_tab_.reset(); |
} |
+ |
+ if (NtpLoggingUserData::FromWebContents(browser_->GetActiveWebContents())) { |
Jered
2013/06/26 16:37:57
Why are you calling this here?
annark1
2013/06/28 15:30:49
I was calling this here to capture the cases when
|
+ NtpLoggingUserData::FromWebContents( |
+ browser_->GetActiveWebContents())->log_number_of_mouseovers(); |
+ } |
} |
void InstantController::UpdateInfoForInstantTab() { |
@@ -1900,6 +1951,16 @@ void InstantController::PopulateInstantAutocompleteResultFromMatch( |
<< result->transition << " " << result->autocomplete_match_index; |
} |
+void InstantController::LogIframeHover() { |
+ if (!browser_ || !browser_->GetActiveWebContents()) |
+ return; |
+ |
+ if(NtpLoggingUserData::FromWebContents(browser_->GetActiveWebContents())) { |
+ NtpLoggingUserData::FromWebContents( |
+ browser_->GetActiveWebContents())->increment_number_of_mouseovers(); |
+ } |
+} |
+ |
bool InstantController::IsJavascriptEnabled() const { |
GURL instant_url(GetInstantURL()); |
GURL origin(instant_url.GetOrigin()); |