| OLD | NEW |
| 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 Loading... |
| 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 (size_t i = 0; i < data->size(); i++) { |
| 90 const history::FilteredURL& suggested_url = data[i]; | 94 const history::FilteredURL& suggested_url = (*data)[i]; |
| 91 if (suggested_url.url.is_empty()) | 95 if (suggested_url.url.is_empty()) |
| 92 continue; | 96 continue; |
| 93 | 97 |
| 94 base::DictionaryValue* page_value = new base::DictionaryValue(); | 98 base::DictionaryValue* page_value = new base::DictionaryValue(); |
| 95 NewTabUI::SetUrlTitleAndDirection(page_value, | 99 NewTabUI::SetUrlTitleAndDirection(page_value, |
| 96 suggested_url.title, | 100 suggested_url.title, |
| 97 suggested_url.url); | 101 suggested_url.url); |
| 98 page_value->SetDouble("score", suggested_url.score); | 102 page_value->SetDouble("score", suggested_url.score); |
| 99 if (debug_) { | 103 if (debug_) { |
| 100 if (suggested_url.extended_info.total_visits) { | 104 if (suggested_url.extended_info.total_visits) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // static | 140 // static |
| 137 history::VisitFilter::SortingOrder | 141 history::VisitFilter::SortingOrder |
| 138 SuggestionsSourceTopSites::GetSortingOrder() { | 142 SuggestionsSourceTopSites::GetSortingOrder() { |
| 139 const CommandLine* cli = CommandLine::ForCurrentProcess(); | 143 const CommandLine* cli = CommandLine::ForCurrentProcess(); |
| 140 if (cli->HasSwitch(switches::kSuggestionNtpGaussianFilter)) | 144 if (cli->HasSwitch(switches::kSuggestionNtpGaussianFilter)) |
| 141 return history::VisitFilter::ORDER_BY_TIME_GAUSSIAN; | 145 return history::VisitFilter::ORDER_BY_TIME_GAUSSIAN; |
| 142 if (cli->HasSwitch(switches::kSuggestionNtpLinearFilter)) | 146 if (cli->HasSwitch(switches::kSuggestionNtpLinearFilter)) |
| 143 return history::VisitFilter::ORDER_BY_TIME_LINEAR; | 147 return history::VisitFilter::ORDER_BY_TIME_LINEAR; |
| 144 return history::VisitFilter::ORDER_BY_RECENCY; | 148 return history::VisitFilter::ORDER_BY_RECENCY; |
| 145 } | 149 } |
| OLD | NEW |