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

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: Removed static variable that required an exit-time destructor. 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
37 SuggestionsHandler::SuggestionsHandler() 42 SuggestionsHandler::SuggestionsHandler()
38 : got_first_suggestions_request_(false) { 43 : got_first_suggestions_request_(false),
44 suggestions_viewed_(false),
45 valid_user_action_(false) {
39 } 46 }
40 47
41 SuggestionsHandler::~SuggestionsHandler() { 48 SuggestionsHandler::~SuggestionsHandler() {
49 // TODO(macourteau): ensure that |suggestions_viewed_| gets set correctly,
50 // once the Suggestions pane gets be statically included into the NTP (e.g.,
51 // if the Suggestions pane is the one shown by default, the
52 // |suggestions_viewed_| flag might not get set).
53 if (!valid_user_action_ && suggestions_viewed_) {
54 const GURL ntp_url = GURL(chrome::kChromeUINewTabURL);
55 int action_id = 0; // "0" means "Other".
56 content::NavigationEntry* entry =
57 web_ui()->GetWebContents()->GetController().GetActiveEntry();
58 if (entry && (entry->GetURL() != ntp_url)) {
59 if (content::PageTransitionStripQualifier(entry->GetTransitionType()) ==
60 content::PAGE_TRANSITION_TYPED) {
61 action_id = 3; // "3" means "Navigation via omnibox".
62 }
63 }
64
65 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction", action_id, 4);
66 }
42 } 67 }
43 68
44 void SuggestionsHandler::RegisterMessages() { 69 void SuggestionsHandler::RegisterMessages() {
45 Profile* profile = Profile::FromWebUI(web_ui()); 70 Profile* profile = Profile::FromWebUI(web_ui());
46 // Set up our sources for thumbnail and favicon data. 71 // Set up our sources for thumbnail and favicon data.
47 profile->GetChromeURLDataManager()->AddDataSource( 72 profile->GetChromeURLDataManager()->AddDataSource(
48 new ThumbnailSource(profile)); 73 new ThumbnailSource(profile));
49 profile->GetChromeURLDataManager()->AddDataSource( 74 profile->GetChromeURLDataManager()->AddDataSource(
50 new FaviconSource(profile, FaviconSource::FAVICON)); 75 new FaviconSource(profile, FaviconSource::FAVICON));
51 76
(...skipping 22 matching lines...) Expand all
74 // Register ourselves for any suggestions item blacklisting. 99 // Register ourselves for any suggestions item blacklisting.
75 web_ui()->RegisterMessageCallback("blacklistURLFromSuggestions", 100 web_ui()->RegisterMessageCallback("blacklistURLFromSuggestions",
76 base::Bind(&SuggestionsHandler::HandleBlacklistURL, 101 base::Bind(&SuggestionsHandler::HandleBlacklistURL,
77 base::Unretained(this))); 102 base::Unretained(this)));
78 web_ui()->RegisterMessageCallback("removeURLsFromSuggestionsBlacklist", 103 web_ui()->RegisterMessageCallback("removeURLsFromSuggestionsBlacklist",
79 base::Bind(&SuggestionsHandler::HandleRemoveURLsFromBlacklist, 104 base::Bind(&SuggestionsHandler::HandleRemoveURLsFromBlacklist,
80 base::Unretained(this))); 105 base::Unretained(this)));
81 web_ui()->RegisterMessageCallback("clearSuggestionsURLsBlacklist", 106 web_ui()->RegisterMessageCallback("clearSuggestionsURLsBlacklist",
82 base::Bind(&SuggestionsHandler::HandleClearBlacklist, 107 base::Bind(&SuggestionsHandler::HandleClearBlacklist,
83 base::Unretained(this))); 108 base::Unretained(this)));
109 web_ui()->RegisterMessageCallback("suggestedSitesAction",
110 base::Bind(&SuggestionsHandler::HandleSuggestedSitesAction,
111 base::Unretained(this)));
112 web_ui()->RegisterMessageCallback("suggestedSitesSelected",
113 base::Bind(&SuggestionsHandler::HandleSuggestedSitesSelected,
114 base::Unretained(this)));
84 } 115 }
85 116
86 void SuggestionsHandler::HandleGetSuggestions(const ListValue* args) { 117 void SuggestionsHandler::HandleGetSuggestions(const ListValue* args) {
87 if (!got_first_suggestions_request_) { 118 if (!got_first_suggestions_request_) {
88 // If our initial data is already here, return it. 119 // If our initial data is already here, return it.
89 SendPagesValue(); 120 SendPagesValue();
90 got_first_suggestions_request_ = true; 121 got_first_suggestions_request_ = true;
91 } else { 122 } else {
92 StartQueryForSuggestions(); 123 StartQueryForSuggestions();
93 } 124 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 159
129 void SuggestionsHandler::HandleRemoveURLsFromBlacklist(const ListValue* args) { 160 void SuggestionsHandler::HandleRemoveURLsFromBlacklist(const ListValue* args) {
130 DCHECK_GT(args->GetSize(), 0U); 161 DCHECK_GT(args->GetSize(), 0U);
131 // TODO(georgey) remove URLs from blacklist. 162 // TODO(georgey) remove URLs from blacklist.
132 } 163 }
133 164
134 void SuggestionsHandler::HandleClearBlacklist(const ListValue* args) { 165 void SuggestionsHandler::HandleClearBlacklist(const ListValue* args) {
135 // TODO(georgey) clear blacklist. 166 // TODO(georgey) clear blacklist.
136 } 167 }
137 168
169 void SuggestionsHandler::HandleSuggestedSitesAction(
170 const base::ListValue* args) {
171 DCHECK(args);
172
173 double action_id;
174 if (!args->GetDouble(0, &action_id))
175 NOTREACHED();
176
177 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction",
178 static_cast<int>(action_id), 4);
179 suggestions_viewed_ = true;
180 valid_user_action_ = true;
181 }
182
183 void SuggestionsHandler::HandleSuggestedSitesSelected(
184 const base::ListValue* args) {
185 suggestions_viewed_ = true;
186 }
187
138 void SuggestionsHandler::SetPagesValueFromTopSites( 188 void SuggestionsHandler::SetPagesValueFromTopSites(
139 const history::MostVisitedURLList& data) { 189 const history::MostVisitedURLList& data) {
140 pages_value_.reset(new ListValue()); 190 pages_value_.reset(new ListValue());
141 for (size_t i = 0; i < data.size(); i++) { 191 for (size_t i = 0; i < data.size(); i++) {
142 const history::MostVisitedURL& suggested_url = data[i]; 192 const history::MostVisitedURL& suggested_url = data[i];
143 if (suggested_url.url.is_empty()) 193 if (suggested_url.url.is_empty())
144 continue; 194 continue;
145 195
146 DictionaryValue* page_value = new DictionaryValue(); 196 DictionaryValue* page_value = new DictionaryValue();
147 NewTabUI::SetURLTitleAndDirection(page_value, 197 NewTabUI::SetURLTitleAndDirection(page_value,
(...skipping 25 matching lines...) Expand all
173 } 223 }
174 224
175 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { 225 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) {
176 return base::MD5String(url); 226 return base::MD5String(url);
177 } 227 }
178 228
179 // static 229 // static
180 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) { 230 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) {
181 // TODO(georgey) add user preferences (such as own blacklist) as needed. 231 // TODO(georgey) add user preferences (such as own blacklist) as needed.
182 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698