Chromium Code Reviews| Index: chrome/browser/ui/search/instant_ntp.cc |
| diff --git a/chrome/browser/ui/search/instant_ntp.cc b/chrome/browser/ui/search/instant_ntp.cc |
| index 8b5daec8bec626217914d25000e2709bb8320723..4be3fe9c80ba8bf0ac473ea013901fe3e5e5b3d9 100644 |
| --- a/chrome/browser/ui/search/instant_ntp.cc |
| +++ b/chrome/browser/ui/search/instant_ntp.cc |
| @@ -4,9 +4,68 @@ |
| #include "chrome/browser/ui/search/instant_ntp.h" |
| +#include "base/metrics/histogram.h" |
| +#include "chrome/browser/search/search.h" |
| #include "chrome/browser/ui/search/search_tab_helper.h" |
| +#include "content/public/browser/navigation_details.h" |
| #include "content/public/browser/navigation_entry.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| +#include "content/public/browser/web_contents_user_data.h" |
| + |
| + |
| +namespace { |
| +// Helper class for logging data from the NTP. Attached to each InstantNTP |
| +// instance. |
| +class NTPLoggingUserData |
| + : public content::WebContentsObserver, |
| + 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 an NTP tab is about to be deactivated (be it by switching tabs, losing |
| + // focus or closing the tab/shutting down Chrome) or when the user navigates |
| + // to a URL. |
| + void log_number_of_mouseovers() { |
| + UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", |
| + number_of_mouseovers_); |
| + number_of_mouseovers_ = 0; |
| + } |
| + |
| + void set_instant_url(const std::string& url) { |
| + instant_url_ = url; |
| + } |
| + |
| + // content::WebContentsObserver override |
| + virtual void NavigationEntryCommitted OVERRIDE( |
|
Jered
2013/06/28 16:24:17
Remove extra space after "void".
annark1
2013/06/28 18:38:22
Done.
|
| + const content::LoadCommittedDetails& load_details) { |
| + if (chrome::MatchesOriginAndPath( |
| + GURL(instant_url_), load_details.previous_url)) |
|
Jered
2013/06/28 16:24:17
Indent 4 more spaces.
annark1
2013/06/28 18:38:22
Done.
|
| + log_number_of_mouseovers(); |
| + } |
| + |
| + private: |
| + explicit NTPLoggingUserData(content::WebContents* contents) |
| + : content::WebContentsObserver(contents), |
| + number_of_mouseovers_(0), |
| + instant_url_("Needs To Be Set") {} |
|
Jered
2013/06/28 16:24:17
Omit this default value.
annark1
2013/06/28 18:38:22
The reason this is here is because on start up the
Jered
2013/06/28 18:43:09
How about not emitting the count when previous_url
|
| + friend class content::WebContentsUserData<NTPLoggingUserData>; |
| + |
| + int number_of_mouseovers_; |
| + std::string instant_url_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NTPLoggingUserData); |
| +}; |
| + |
| +} // namespace |
| + |
| +DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPLoggingUserData); |
| InstantNTP::InstantNTP(InstantPage::Delegate* delegate, |
| const std::string& instant_url, |
| @@ -24,6 +83,11 @@ void InstantNTP::InitContents(Profile* profile, |
| loader_.Init(GURL(instant_url()), profile, active_tab, on_stale_callback); |
| SetContents(loader_.contents()); |
| SearchTabHelper::FromWebContents(contents())->InitForPreloadedNTP(); |
| + |
| + NTPLoggingUserData::CreateForWebContents(contents()); |
| + NTPLoggingUserData::FromWebContents( |
| + contents())->set_instant_url(instant_url()); |
| + |
| loader_.Load(); |
| } |
| @@ -32,6 +96,19 @@ scoped_ptr<content::WebContents> InstantNTP::ReleaseContents() { |
| return loader_.ReleaseContents(); |
| } |
| +void InstantNTP::LogIframeHover(content::WebContents* contents) { |
| + if (NTPLoggingUserData::FromWebContents(contents)) { |
| + NTPLoggingUserData::FromWebContents(contents)-> |
| + increment_number_of_mouseovers(); |
| + } |
| +} |
| + |
| +void InstantNTP::LogTotalMouseovers(content::WebContents* contents) { |
| + if (NTPLoggingUserData::FromWebContents(contents)) { |
| + NTPLoggingUserData::FromWebContents(contents)->log_number_of_mouseovers(); |
| + } |
| +} |
| + |
| void InstantNTP::OnSwappedContents() { |
| SetContents(loader_.contents()); |
| } |