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

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

Issue 10060003: Support for different weight-functions for time-slicing. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased Created 8 years, 7 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
« no previous file with comments | « chrome/browser/ui/webui/ntp/suggestions_page_handler.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h"
11 #include "base/md5.h" 12 #include "base/md5.h"
12 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
13 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
14 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
15 #include "base/string16.h" 16 #include "base/string16.h"
16 #include "base/string_number_conversions.h" 17 #include "base/string_number_conversions.h"
17 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
18 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 #include "chrome/browser/history/page_usage_data.h" 21 #include "chrome/browser/history/page_usage_data.h"
21 #include "chrome/browser/history/top_sites.h" 22 #include "chrome/browser/history/top_sites.h"
22 #include "chrome/browser/history/visit_filter.h" 23 #include "chrome/browser/history/visit_filter.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
25 #include "chrome/browser/ui/webui/favicon_source.h" 26 #include "chrome/browser/ui/webui/favicon_source.h"
26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 27 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
27 #include "chrome/browser/ui/webui/ntp/ntp_stats.h" 28 #include "chrome/browser/ui/webui/ntp/ntp_stats.h"
28 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" 29 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
29 #include "chrome/common/chrome_notification_types.h" 30 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
31 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/navigation_controller.h" 34 #include "content/public/browser/navigation_controller.h"
33 #include "content/public/browser/navigation_entry.h" 35 #include "content/public/browser/navigation_entry.h"
34 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
35 #include "content/public/browser/user_metrics.h" 37 #include "content/public/browser/user_metrics.h"
36 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
37 #include "content/public/browser/web_ui.h" 39 #include "content/public/browser/web_ui.h"
38 #include "content/public/common/page_transition_types.h" 40 #include "content/public/common/page_transition_types.h"
39 #include "googleurl/src/gurl.h" 41 #include "googleurl/src/gurl.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 pages_value_.reset(); 132 pages_value_.reset();
131 } 133 }
132 } 134 }
133 135
134 void SuggestionsHandler::StartQueryForSuggestions() { 136 void SuggestionsHandler::StartQueryForSuggestions() {
135 HistoryService* history = 137 HistoryService* history =
136 Profile::FromWebUI(web_ui())->GetHistoryService(Profile::EXPLICIT_ACCESS); 138 Profile::FromWebUI(web_ui())->GetHistoryService(Profile::EXPLICIT_ACCESS);
137 // |history| may be null during unit tests. 139 // |history| may be null during unit tests.
138 if (history) { 140 if (history) {
139 history::VisitFilter time_filter; 141 history::VisitFilter time_filter;
140 base::TimeDelta half_an_hour = 142
Evan Stade 2012/05/03 00:06:57 remove \n
Rune Fevang 2012/05/03 20:50:59 Done.
141 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerHour / 2); 143 time_filter.SetFilterTime(base::Time::Now());
142 base::Time now = base::Time::Now(); 144
Evan Stade 2012/05/03 00:06:57 remove \n
Rune Fevang 2012/05/03 20:50:59 Done.
143 time_filter.SetTimeInRangeFilter(now - half_an_hour, now + half_an_hour); 145 time_filter.SetFilterWidth(GetFilterWidth());
144 history->QueryFilteredURLs(0, time_filter, &history_consumer_, 146 time_filter.set_sorting_order(GetSortingOrder());
147
148 history->QueryFilteredURLs(
149 0, time_filter, &history_consumer_,
145 base::Bind(&SuggestionsHandler::OnSuggestionsURLsAvailable, 150 base::Bind(&SuggestionsHandler::OnSuggestionsURLsAvailable,
146 base::Unretained(this))); 151 base::Unretained(this)));
147 } 152 }
148 } 153 }
149 154
150 void SuggestionsHandler::HandleBlacklistURL(const ListValue* args) { 155 void SuggestionsHandler::HandleBlacklistURL(const ListValue* args) {
151 std::string url = UTF16ToUTF8(ExtractStringValue(args)); 156 std::string url = UTF16ToUTF8(ExtractStringValue(args));
152 BlacklistURL(GURL(url)); 157 BlacklistURL(GURL(url));
153 } 158 }
154 159
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 225 }
221 226
222 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { 227 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) {
223 return base::MD5String(url); 228 return base::MD5String(url);
224 } 229 }
225 230
226 // static 231 // static
227 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) { 232 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) {
228 // TODO(georgey) add user preferences (such as own blacklist) as needed. 233 // TODO(georgey) add user preferences (such as own blacklist) as needed.
229 } 234 }
235
236 // static
237 base::TimeDelta SuggestionsHandler::GetFilterWidth() {
238 const CommandLine* cli = CommandLine::ForCurrentProcess();
239 const std::string filter_width_switch =
240 cli->GetSwitchValueASCII(switches::kSuggestionNtpFilterWidth);
241 unsigned int filter_width;
242 if (base::StringToUint(filter_width_switch, &filter_width)) {
Evan Stade 2012/05/03 00:06:57 no curlies
Rune Fevang 2012/05/03 20:50:59 Done.
243 return base::TimeDelta::FromMinutes(filter_width);
244 }
245 return base::TimeDelta::FromHours(1);
246 }
247
248 // static
249 history::VisitFilter::SortingOrder SuggestionsHandler::GetSortingOrder() {
250 const CommandLine* cli = CommandLine::ForCurrentProcess();
251 if (cli->HasSwitch(switches::kSuggestionNtpGaussianFilter))
252 return history::VisitFilter::ORDER_BY_TIME_GAUSSIAN;
253 if (cli->HasSwitch(switches::kSuggestionNtpLinearFilter))
254 return history::VisitFilter::ORDER_BY_TIME_LINEAR;
255 return history::VisitFilter::ORDER_BY_RECENCY;
256 }
257
Evan Stade 2012/05/03 00:06:57 remove \n
Rune Fevang 2012/05/03 20:50:59 Done.
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/suggestions_page_handler.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698