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

Side by Side Diff: chrome/browser/ui/webui/ntp/suggestions_page_handler.cc

Issue 9958116: Adds the NewTabPage.SuggestedSitesAction stat. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/webui/ntp/suggestions_page_handler.h" 5 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/md5.h" 11 #include "base/md5.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/metrics/histogram.h"
14 #include "base/string16.h" 15 #include "base/string16.h"
15 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
16 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
17 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 19 #include "base/values.h"
19 #include "chrome/browser/history/page_usage_data.h" 20 #include "chrome/browser/history/page_usage_data.h"
20 #include "chrome/browser/history/top_sites.h" 21 #include "chrome/browser/history/top_sites.h"
21 #include "chrome/browser/history/visit_filter.h" 22 #include "chrome/browser/history/visit_filter.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
24 #include "chrome/browser/ui/webui/favicon_source.h" 25 #include "chrome/browser/ui/webui/favicon_source.h"
25 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
26 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" 27 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
27 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
29 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/navigation_controller.h"
32 #include "content/public/browser/navigation_entry.h"
30 #include "content/public/browser/notification_source.h" 33 #include "content/public/browser/notification_source.h"
31 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
35 #include "content/public/browser/web_contents.h"
32 #include "content/public/browser/web_ui.h" 36 #include "content/public/browser/web_ui.h"
37 #include "content/public/common/page_transition_types.h"
33 #include "googleurl/src/gurl.h" 38 #include "googleurl/src/gurl.h"
34 39
35 using content::UserMetricsAction; 40 using content::UserMetricsAction;
36 41
42 namespace {
43
44 // Those values are defined in histograms.xml. These represent the action that
45 // the user has taken to leave the Suggested pane, given that they have viewed
46 // that pane on the NTP.
47 enum SuggestedSitesActions {
48 // Values 0 to 10 are the core values from PageTransition (see
49 // page_transition_types.h).
50
51 // The user has clicked on a Suggested tile.
52 SUGGESTED_SITES_ACTION_CLICKED_SUGGESTED_TILE = 11,
53 // The user has moved to another pane within the NTP.
54 SUGGESTED_SITES_ACTION_CLICKED_OTHER_NTP_PANE,
55 // Any action other than what is listed here (e.g. closing the tab, etc.).
56 SUGGESTED_SITES_ACTION_OTHER
57 };
58
59 } // namespace
60
37 SuggestionsHandler::SuggestionsHandler() 61 SuggestionsHandler::SuggestionsHandler()
38 : got_first_suggestions_request_(false) { 62 : got_first_suggestions_request_(false),
63 suggestions_viewed_(false),
64 valid_user_action_(false) {
39 } 65 }
40 66
41 SuggestionsHandler::~SuggestionsHandler() { 67 SuggestionsHandler::~SuggestionsHandler() {
68 // TODO(macourteau): ensure that |suggestions_viewed_| gets set correctly,
69 // once the Suggestions pane gets statically included into the NTP (e.g.,
70 // if the Suggestions pane is the one shown by default, the
71 // |suggestions_viewed_| flag might not get set).
72 if (!valid_user_action_ && suggestions_viewed_) {
73 const GURL ntp_url = GURL(chrome::kChromeUINewTabURL);
74 int action_id = SUGGESTED_SITES_ACTION_OTHER;
75 content::NavigationEntry* entry =
76 web_ui()->GetWebContents()->GetController().GetActiveEntry();
77 if (entry && (entry->GetURL() != ntp_url)) {
78 action_id =
79 content::PageTransitionStripQualifier(entry->GetTransitionType());
Evan Stade 2012/04/12 03:30:53 2 more spaces indent
macourteau 2012/04/12 13:59:43 Done.
80 }
81
82 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction", action_id, 4);
Evan Stade 2012/04/12 03:30:53 4?
macourteau 2012/04/12 13:59:43 Done.
83 }
42 } 84 }
43 85
44 void SuggestionsHandler::RegisterMessages() { 86 void SuggestionsHandler::RegisterMessages() {
45 Profile* profile = Profile::FromWebUI(web_ui()); 87 Profile* profile = Profile::FromWebUI(web_ui());
46 // Set up our sources for thumbnail and favicon data. 88 // Set up our sources for thumbnail and favicon data.
47 profile->GetChromeURLDataManager()->AddDataSource( 89 profile->GetChromeURLDataManager()->AddDataSource(
48 new ThumbnailSource(profile)); 90 new ThumbnailSource(profile));
49 profile->GetChromeURLDataManager()->AddDataSource( 91 profile->GetChromeURLDataManager()->AddDataSource(
50 new FaviconSource(profile, FaviconSource::FAVICON)); 92 new FaviconSource(profile, FaviconSource::FAVICON));
51 93
(...skipping 22 matching lines...) Expand all
74 // Register ourselves for any suggestions item blacklisting. 116 // Register ourselves for any suggestions item blacklisting.
75 web_ui()->RegisterMessageCallback("blacklistURLFromSuggestions", 117 web_ui()->RegisterMessageCallback("blacklistURLFromSuggestions",
76 base::Bind(&SuggestionsHandler::HandleBlacklistURL, 118 base::Bind(&SuggestionsHandler::HandleBlacklistURL,
77 base::Unretained(this))); 119 base::Unretained(this)));
78 web_ui()->RegisterMessageCallback("removeURLsFromSuggestionsBlacklist", 120 web_ui()->RegisterMessageCallback("removeURLsFromSuggestionsBlacklist",
79 base::Bind(&SuggestionsHandler::HandleRemoveURLsFromBlacklist, 121 base::Bind(&SuggestionsHandler::HandleRemoveURLsFromBlacklist,
80 base::Unretained(this))); 122 base::Unretained(this)));
81 web_ui()->RegisterMessageCallback("clearSuggestionsURLsBlacklist", 123 web_ui()->RegisterMessageCallback("clearSuggestionsURLsBlacklist",
82 base::Bind(&SuggestionsHandler::HandleClearBlacklist, 124 base::Bind(&SuggestionsHandler::HandleClearBlacklist,
83 base::Unretained(this))); 125 base::Unretained(this)));
126 web_ui()->RegisterMessageCallback("suggestedSitesAction",
127 base::Bind(&SuggestionsHandler::HandleSuggestedSitesAction,
128 base::Unretained(this)));
129 web_ui()->RegisterMessageCallback("suggestedSitesSelected",
130 base::Bind(&SuggestionsHandler::HandleSuggestedSitesSelected,
131 base::Unretained(this)));
84 } 132 }
85 133
86 void SuggestionsHandler::HandleGetSuggestions(const ListValue* args) { 134 void SuggestionsHandler::HandleGetSuggestions(const ListValue* args) {
87 if (!got_first_suggestions_request_) { 135 if (!got_first_suggestions_request_) {
88 // If our initial data is already here, return it. 136 // If our initial data is already here, return it.
89 SendPagesValue(); 137 SendPagesValue();
90 got_first_suggestions_request_ = true; 138 got_first_suggestions_request_ = true;
91 } else { 139 } else {
92 StartQueryForSuggestions(); 140 StartQueryForSuggestions();
93 } 141 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 176
129 void SuggestionsHandler::HandleRemoveURLsFromBlacklist(const ListValue* args) { 177 void SuggestionsHandler::HandleRemoveURLsFromBlacklist(const ListValue* args) {
130 DCHECK_GT(args->GetSize(), 0U); 178 DCHECK_GT(args->GetSize(), 0U);
131 // TODO(georgey) remove URLs from blacklist. 179 // TODO(georgey) remove URLs from blacklist.
132 } 180 }
133 181
134 void SuggestionsHandler::HandleClearBlacklist(const ListValue* args) { 182 void SuggestionsHandler::HandleClearBlacklist(const ListValue* args) {
135 // TODO(georgey) clear blacklist. 183 // TODO(georgey) clear blacklist.
136 } 184 }
137 185
186 void SuggestionsHandler::HandleSuggestedSitesAction(
187 const base::ListValue* args) {
188 DCHECK(args);
189
190 double action_id;
191 if (!args->GetDouble(0, &action_id))
192 NOTREACHED();
193
194 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction",
195 static_cast<int>(action_id), 4);
Evan Stade 2012/04/12 03:30:53 4?
macourteau 2012/04/12 13:59:43 Done.
196 suggestions_viewed_ = true;
197 valid_user_action_ = true;
198 }
199
200 void SuggestionsHandler::HandleSuggestedSitesSelected(
201 const base::ListValue* args) {
202 suggestions_viewed_ = true;
203 }
204
138 void SuggestionsHandler::SetPagesValueFromTopSites( 205 void SuggestionsHandler::SetPagesValueFromTopSites(
139 const history::MostVisitedURLList& data) { 206 const history::MostVisitedURLList& data) {
140 pages_value_.reset(new ListValue()); 207 pages_value_.reset(new ListValue());
141 for (size_t i = 0; i < data.size(); i++) { 208 for (size_t i = 0; i < data.size(); i++) {
142 const history::MostVisitedURL& suggested_url = data[i]; 209 const history::MostVisitedURL& suggested_url = data[i];
143 if (suggested_url.url.is_empty()) 210 if (suggested_url.url.is_empty())
144 continue; 211 continue;
145 212
146 DictionaryValue* page_value = new DictionaryValue(); 213 DictionaryValue* page_value = new DictionaryValue();
147 NewTabUI::SetURLTitleAndDirection(page_value, 214 NewTabUI::SetURLTitleAndDirection(page_value,
(...skipping 25 matching lines...) Expand all
173 } 240 }
174 241
175 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { 242 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) {
176 return base::MD5String(url); 243 return base::MD5String(url);
177 } 244 }
178 245
179 // static 246 // static
180 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) { 247 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) {
181 // TODO(georgey) add user preferences (such as own blacklist) as needed. 248 // TODO(georgey) add user preferences (such as own blacklist) as needed.
182 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698