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

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: Rebased 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 #include "googleurl/src/gurl.h"
16
17 namespace {
18
19 // Helper class for logging data from the NTP. Attached to each InstantNTP
20 // instance.
21 class NTPLoggingUserData
22 : public content::WebContentsObserver,
23 public content::WebContentsUserData<NTPLoggingUserData> {
24 public:
25 virtual ~NTPLoggingUserData() {}
26
27 // Called each time the mouse hovers over an iframe or title.
28 void increment_number_of_mouseovers() {
29 number_of_mouseovers_++;
30 }
31
32 void set_instant_url(const GURL& url) {
33 instant_url_ = url;
34 }
35
36 // Logs total number of mouseovers per NTP session to UMA histogram. Called
37 // when an NTP tab is about to be deactivated (be it by switching tabs, losing
38 // focus or closing the tab/shutting down Chrome) or when the user navigates
39 // to a URL.
40 void EmitMouseoverCount() {
41 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers",
42 number_of_mouseovers_);
43 number_of_mouseovers_ = 0;
44 }
45
46 // content::WebContentsObserver override
47 virtual void NavigationEntryCommitted OVERRIDE(
beaudoin 2013/07/04 16:12:03 Nit: space between OVERRIDE and (
annark1 2013/07/04 19:25:09 Done.
48 const content::LoadCommittedDetails& load_details) {
49 if (!load_details.previous_url.is_valid())
50 return;
51
52 if (chrome::MatchesOriginAndPath(instant_url_, load_details.previous_url))
53 EmitMouseoverCount();
54 }
55
56 private:
57 explicit NTPLoggingUserData(content::WebContents* contents)
58 : content::WebContentsObserver(contents),
59 number_of_mouseovers_(0) {}
60 friend class content::WebContentsUserData<NTPLoggingUserData>;
61
62 int number_of_mouseovers_;
63 GURL instant_url_;
64
65 DISALLOW_COPY_AND_ASSIGN(NTPLoggingUserData);
66 };
67
68 } // namespace
69
70 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPLoggingUserData);
10 71
11 InstantNTP::InstantNTP(InstantPage::Delegate* delegate, 72 InstantNTP::InstantNTP(InstantPage::Delegate* delegate,
12 const std::string& instant_url, 73 const std::string& instant_url,
13 bool is_incognito) 74 bool is_incognito)
14 : InstantPage(delegate, instant_url, is_incognito), 75 : InstantPage(delegate, instant_url, is_incognito),
15 loader_(this) { 76 loader_(this) {
16 DCHECK(delegate); 77 DCHECK(delegate);
17 } 78 }
18 79
19 InstantNTP::~InstantNTP() { 80 InstantNTP::~InstantNTP() {
20 } 81 }
21 82
22 void InstantNTP::InitContents(Profile* profile, 83 void InstantNTP::InitContents(Profile* profile,
23 const content::WebContents* active_tab, 84 const content::WebContents* active_tab,
24 const base::Closure& on_stale_callback) { 85 const base::Closure& on_stale_callback) {
25 loader_.Init(GURL(instant_url()), profile, active_tab, on_stale_callback); 86 GURL instantNTP_url(instant_url());
87 loader_.Init(instantNTP_url, profile, active_tab, on_stale_callback);
26 SetContents(loader_.contents()); 88 SetContents(loader_.contents());
27 SearchTabHelper::FromWebContents(contents())->InitForPreloadedNTP(); 89 content::WebContents* content = contents();
90 SearchTabHelper::FromWebContents(content)->InitForPreloadedNTP();
91
92 NTPLoggingUserData::CreateForWebContents(content);
93 NTPLoggingUserData::FromWebContents(content)->set_instant_url(instantNTP_url);
94
28 loader_.Load(); 95 loader_.Load();
29 } 96 }
30 97
31 scoped_ptr<content::WebContents> InstantNTP::ReleaseContents() { 98 scoped_ptr<content::WebContents> InstantNTP::ReleaseContents() {
32 SetContents(NULL); 99 SetContents(NULL);
33 return loader_.ReleaseContents(); 100 return loader_.ReleaseContents();
34 } 101 }
35 102
36 void InstantNTP::RenderViewCreated(content::RenderViewHost* render_view_host) { 103 void InstantNTP::RenderViewCreated(content::RenderViewHost* render_view_host) {
37 delegate()->InstantPageRenderViewCreated(contents()); 104 delegate()->InstantPageRenderViewCreated(contents());
38 } 105 }
39 106
40 void InstantNTP::RenderViewGone(base::TerminationStatus /* status */) { 107 void InstantNTP::RenderViewGone(base::TerminationStatus /* status */) {
41 delegate()->InstantPageRenderViewGone(contents()); 108 delegate()->InstantPageRenderViewGone(contents());
42 } 109 }
43 110
111 // static
112 void InstantNTP::CountMouseover(content::WebContents* contents) {
113 if (NTPLoggingUserData* data = NTPLoggingUserData::FromWebContents(
114 contents)) {
115 data->increment_number_of_mouseovers();
116 }
beaudoin 2013/07/04 16:12:03 Nit: Would be slightly easier to read and shorter
annark1 2013/07/04 19:25:09 Done.
117 }
118
119 // static
120 void InstantNTP::EmitMouseoverCount(content::WebContents* contents) {
121 if (NTPLoggingUserData* data = NTPLoggingUserData::FromWebContents(
122 contents)) {
123 data->EmitMouseoverCount();
124 }
beaudoin 2013/07/04 16:12:03 Same here.
annark1 2013/07/04 19:25:09 Done.
125 }
126
44 void InstantNTP::OnSwappedContents() { 127 void InstantNTP::OnSwappedContents() {
45 SetContents(loader_.contents()); 128 SetContents(loader_.contents());
46 } 129 }
47 130
48 void InstantNTP::OnFocus() { 131 void InstantNTP::OnFocus() {
49 NOTREACHED(); 132 NOTREACHED();
50 } 133 }
51 134
52 void InstantNTP::OnMouseDown() { 135 void InstantNTP::OnMouseDown() {
53 NOTREACHED(); 136 NOTREACHED();
54 } 137 }
55 138
56 void InstantNTP::OnMouseUp() { 139 void InstantNTP::OnMouseUp() {
57 NOTREACHED(); 140 NOTREACHED();
58 } 141 }
59 142
60 content::WebContents* InstantNTP::OpenURLFromTab( 143 content::WebContents* InstantNTP::OpenURLFromTab(
61 content::WebContents* source, 144 content::WebContents* source,
62 const content::OpenURLParams& params) { 145 const content::OpenURLParams& params) {
63 return NULL; 146 return NULL;
64 } 147 }
65 148
66 void InstantNTP::LoadCompletedMainFrame() { 149 void InstantNTP::LoadCompletedMainFrame() {
67 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698