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

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

Issue 351053003: Port HistoryService::QueryFilteredURLs to CancelableRequestTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
« no previous file with comments | « chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h ('k') | no next file » | 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_source_top_sites.h" 5 #include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 base::DictionaryValue* item = items_.front(); 55 base::DictionaryValue* item = items_.front();
56 items_.pop_front(); 56 items_.pop_front();
57 return item; 57 return item;
58 } 58 }
59 59
60 void SuggestionsSourceTopSites::FetchItems(Profile* profile) { 60 void SuggestionsSourceTopSites::FetchItems(Profile* profile) {
61 DCHECK(combiner_); 61 DCHECK(combiner_);
62 STLDeleteElements(&items_); 62 STLDeleteElements(&items_);
63 63
64 history_consumer_.CancelAllRequests(); 64 history_tracker_.TryCancelAll();
65 HistoryService* history = HistoryServiceFactory::GetForProfile( 65 HistoryService* history = HistoryServiceFactory::GetForProfile(
66 profile, Profile::EXPLICIT_ACCESS); 66 profile, Profile::EXPLICIT_ACCESS);
67 // |history| may be null during unit tests. 67 // |history| may be null during unit tests.
68 if (history) { 68 if (history) {
69 history::VisitFilter time_filter; 69 history::VisitFilter time_filter;
70 time_filter.SetFilterTime(base::Time::Now()); 70 time_filter.SetFilterTime(base::Time::Now());
71 time_filter.SetFilterWidth(GetFilterWidth()); 71 time_filter.SetFilterWidth(GetFilterWidth());
72 time_filter.set_sorting_order(GetSortingOrder()); 72 time_filter.set_sorting_order(GetSortingOrder());
73 73
74 history->QueryFilteredURLs(0, time_filter, debug_, &history_consumer_, 74 history->QueryFilteredURLs(
75 0,
76 time_filter,
77 debug_,
75 base::Bind(&SuggestionsSourceTopSites::OnSuggestionsUrlsAvailable, 78 base::Bind(&SuggestionsSourceTopSites::OnSuggestionsUrlsAvailable,
76 base::Unretained(this))); 79 base::Unretained(this)),
80 &history_tracker_);
77 } 81 }
78 } 82 }
79 83
80 void SuggestionsSourceTopSites::SetCombiner(SuggestionsCombiner* combiner) { 84 void SuggestionsSourceTopSites::SetCombiner(SuggestionsCombiner* combiner) {
81 DCHECK(!combiner_); 85 DCHECK(!combiner_);
82 combiner_ = combiner; 86 combiner_ = combiner;
83 } 87 }
84 88
85 void SuggestionsSourceTopSites::OnSuggestionsUrlsAvailable( 89 void SuggestionsSourceTopSites::OnSuggestionsUrlsAvailable(
86 CancelableRequestProvider::Handle handle, 90 const history::FilteredURLList* data) {
87 const history::FilteredURLList& data) { 91 DCHECK(data);
88 DCHECK(combiner_); 92 DCHECK(combiner_);
89 for (size_t i = 0; i < data.size(); i++) { 93 for (history::FilteredURLList::const_iterator iter = data->begin();
90 const history::FilteredURL& suggested_url = data[i]; 94 iter != data->end();
95 ++iter) {
96 const history::FilteredURL& suggested_url = *iter;
Dan Beam 2014/06/26 03:47:33 nit: revert this hunk, data[i] -> (*data)[i]
sdefresne 2014/06/28 07:59:47 Done.
91 if (suggested_url.url.is_empty()) 97 if (suggested_url.url.is_empty())
92 continue; 98 continue;
93 99
94 base::DictionaryValue* page_value = new base::DictionaryValue(); 100 base::DictionaryValue* page_value = new base::DictionaryValue();
95 NewTabUI::SetUrlTitleAndDirection(page_value, 101 NewTabUI::SetUrlTitleAndDirection(page_value,
96 suggested_url.title, 102 suggested_url.title,
97 suggested_url.url); 103 suggested_url.url);
98 page_value->SetDouble("score", suggested_url.score); 104 page_value->SetDouble("score", suggested_url.score);
99 if (debug_) { 105 if (debug_) {
100 if (suggested_url.extended_info.total_visits) { 106 if (suggested_url.extended_info.total_visits) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // static 142 // static
137 history::VisitFilter::SortingOrder 143 history::VisitFilter::SortingOrder
138 SuggestionsSourceTopSites::GetSortingOrder() { 144 SuggestionsSourceTopSites::GetSortingOrder() {
139 const CommandLine* cli = CommandLine::ForCurrentProcess(); 145 const CommandLine* cli = CommandLine::ForCurrentProcess();
140 if (cli->HasSwitch(switches::kSuggestionNtpGaussianFilter)) 146 if (cli->HasSwitch(switches::kSuggestionNtpGaussianFilter))
141 return history::VisitFilter::ORDER_BY_TIME_GAUSSIAN; 147 return history::VisitFilter::ORDER_BY_TIME_GAUSSIAN;
142 if (cli->HasSwitch(switches::kSuggestionNtpLinearFilter)) 148 if (cli->HasSwitch(switches::kSuggestionNtpLinearFilter))
143 return history::VisitFilter::ORDER_BY_TIME_LINEAR; 149 return history::VisitFilter::ORDER_BY_TIME_LINEAR;
144 return history::VisitFilter::ORDER_BY_RECENCY; 150 return history::VisitFilter::ORDER_BY_RECENCY;
145 } 151 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698