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

Side by Side Diff: chrome/browser/ui/search/instant_ntp.cc

Issue 17526008: Log NTP hovers in 1993 clients (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Edited histogram summary Created 7 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/search/instant_ntp.h" 5 #include "chrome/browser/ui/search/instant_ntp.h"
6 6
7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/search/search.h"
7 #include "chrome/browser/ui/search/search_tab_helper.h" 9 #include "chrome/browser/ui/search/search_tab_helper.h"
10 #include "content/public/browser/navigation_details.h"
8 #include "content/public/browser/navigation_entry.h" 11 #include "content/public/browser/navigation_entry.h"
9 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
15
16
17 namespace {
18 // Helper class for logging data from the NTP. Attached to each InstantNTP
19 // instance.
20 class NTPLoggingUserData
21 : public content::WebContentsObserver,
22 public content::WebContentsUserData<NTPLoggingUserData> {
23 public:
24 virtual ~NTPLoggingUserData() {}
25
26 // Called each time the mouse hovers over an iframe or title.
27 void increment_number_of_mouseovers() {
28 number_of_mouseovers_++;
29 }
30
31 // Logs total number of mouseovers per NTP session to UMA histogram. Called
32 // when an NTP tab is about to be deactivated (be it by switching tabs, losing
33 // focus or closing the tab/shutting down Chrome) or when the user navigates
34 // to a URL.
35 void log_number_of_mouseovers() {
36 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers",
37 number_of_mouseovers_);
38 number_of_mouseovers_ = 0;
39 }
40
41 void set_instant_url(const std::string& url) {
42 instant_url_ = url;
43 }
44
45 // content::WebContentsObserver override
46 virtual void NavigationEntryCommitted OVERRIDE(
Jered 2013/06/28 16:24:17 Remove extra space after "void".
annark1 2013/06/28 18:38:22 Done.
47 const content::LoadCommittedDetails& load_details) {
48 if (chrome::MatchesOriginAndPath(
49 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.
50 log_number_of_mouseovers();
51 }
52
53 private:
54 explicit NTPLoggingUserData(content::WebContents* contents)
55 : content::WebContentsObserver(contents),
56 number_of_mouseovers_(0),
57 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
58 friend class content::WebContentsUserData<NTPLoggingUserData>;
59
60 int number_of_mouseovers_;
61 std::string instant_url_;
62
63 DISALLOW_COPY_AND_ASSIGN(NTPLoggingUserData);
64 };
65
66 } // namespace
67
68 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPLoggingUserData);
10 69
11 InstantNTP::InstantNTP(InstantPage::Delegate* delegate, 70 InstantNTP::InstantNTP(InstantPage::Delegate* delegate,
12 const std::string& instant_url, 71 const std::string& instant_url,
13 bool is_incognito) 72 bool is_incognito)
14 : InstantPage(delegate, instant_url, is_incognito), 73 : InstantPage(delegate, instant_url, is_incognito),
15 loader_(this) { 74 loader_(this) {
16 } 75 }
17 76
18 InstantNTP::~InstantNTP() { 77 InstantNTP::~InstantNTP() {
19 } 78 }
20 79
21 void InstantNTP::InitContents(Profile* profile, 80 void InstantNTP::InitContents(Profile* profile,
22 const content::WebContents* active_tab, 81 const content::WebContents* active_tab,
23 const base::Closure& on_stale_callback) { 82 const base::Closure& on_stale_callback) {
24 loader_.Init(GURL(instant_url()), profile, active_tab, on_stale_callback); 83 loader_.Init(GURL(instant_url()), profile, active_tab, on_stale_callback);
25 SetContents(loader_.contents()); 84 SetContents(loader_.contents());
26 SearchTabHelper::FromWebContents(contents())->InitForPreloadedNTP(); 85 SearchTabHelper::FromWebContents(contents())->InitForPreloadedNTP();
86
87 NTPLoggingUserData::CreateForWebContents(contents());
88 NTPLoggingUserData::FromWebContents(
89 contents())->set_instant_url(instant_url());
90
27 loader_.Load(); 91 loader_.Load();
28 } 92 }
29 93
30 scoped_ptr<content::WebContents> InstantNTP::ReleaseContents() { 94 scoped_ptr<content::WebContents> InstantNTP::ReleaseContents() {
31 SetContents(NULL); 95 SetContents(NULL);
32 return loader_.ReleaseContents(); 96 return loader_.ReleaseContents();
33 } 97 }
34 98
99 void InstantNTP::LogIframeHover(content::WebContents* contents) {
100 if (NTPLoggingUserData::FromWebContents(contents)) {
101 NTPLoggingUserData::FromWebContents(contents)->
102 increment_number_of_mouseovers();
103 }
104 }
105
106 void InstantNTP::LogTotalMouseovers(content::WebContents* contents) {
107 if (NTPLoggingUserData::FromWebContents(contents)) {
108 NTPLoggingUserData::FromWebContents(contents)->log_number_of_mouseovers();
109 }
110 }
111
35 void InstantNTP::OnSwappedContents() { 112 void InstantNTP::OnSwappedContents() {
36 SetContents(loader_.contents()); 113 SetContents(loader_.contents());
37 } 114 }
38 115
39 void InstantNTP::OnFocus() { 116 void InstantNTP::OnFocus() {
40 NOTREACHED(); 117 NOTREACHED();
41 } 118 }
42 119
43 void InstantNTP::OnMouseDown() { 120 void InstantNTP::OnMouseDown() {
44 NOTREACHED(); 121 NOTREACHED();
(...skipping 12 matching lines...) Expand all
57 void InstantNTP::LoadCompletedMainFrame() { 134 void InstantNTP::LoadCompletedMainFrame() {
58 } 135 }
59 136
60 bool InstantNTP::ShouldProcessRenderViewCreated() { 137 bool InstantNTP::ShouldProcessRenderViewCreated() {
61 return true; 138 return true;
62 } 139 }
63 140
64 bool InstantNTP::ShouldProcessRenderViewGone() { 141 bool InstantNTP::ShouldProcessRenderViewGone() {
65 return true; 142 return true;
66 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698