OLD | NEW |
---|---|
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 | |
Alexei Svitkine (slow)
2013/06/28 18:50:29
Nit: Remove extra blank line here.
annark1
2013/06/28 19:37:44
Done.
| |
16 | |
17 namespace { | |
Alexei Svitkine (slow)
2013/06/28 18:50:29
Nit: Add blank line after this.
annark1
2013/06/28 19:37:44
Done.
| |
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 emit_mouseover_count() { | |
Alexei Svitkine (slow)
2013/06/28 18:50:29
This method isn't trivial so should use CamelCase
annark1
2013/06/28 19:37:44
Done.
| |
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( | |
47 const content::LoadCommittedDetails& load_details) { | |
48 if (chrome::MatchesOriginAndPath( | |
49 GURL(instant_url_), load_details.previous_url)) | |
50 emit_mouseover_count(); | |
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") {} | |
58 friend class content::WebContentsUserData<NTPLoggingUserData>; | |
59 | |
60 int number_of_mouseovers_; | |
61 std::string instant_url_; | |
Alexei Svitkine (slow)
2013/06/28 18:50:29
Why not make this a GURL()? Also, remove the dummy
annark1
2013/06/28 19:37:44
Done.
| |
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 |
Jered
2013/06/28 18:43:09
Put
// static
on the line above class static funct
annark1
2013/06/28 19:37:44
Done.
| |
99 void InstantNTP::CountMouseover(content::WebContents* contents) { | |
100 if (NTPLoggingUserData::FromWebContents(contents)) { | |
Alexei Svitkine (slow)
2013/06/28 18:50:29
Suggestion, instead you can do this to avoid query
annark1
2013/06/28 19:37:44
Done.
| |
101 NTPLoggingUserData::FromWebContents(contents)-> | |
102 increment_number_of_mouseovers(); | |
103 } | |
104 } | |
105 | |
106 void InstantNTP::EmitMouseoverCount(content::WebContents* contents) { | |
107 if (NTPLoggingUserData::FromWebContents(contents)) { | |
108 NTPLoggingUserData::FromWebContents(contents)->emit_mouseover_count(); | |
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 Loading... | |
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 } |
OLD | NEW |