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

Side by Side Diff: components/ntp_snippets/offline_pages/recent_tab_suggestions_provider.cc

Issue 2804633003: Add base::FeatureParam<> struct (Closed)
Patch Set: Remove windows-incompatible constexpr Created 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/ntp_snippets/offline_pages/recent_tab_suggestions_provider. h" 5 #include "components/ntp_snippets/offline_pages/recent_tab_suggestions_provider. h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 14 matching lines...) Expand all
25 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
26 26
27 using offline_pages::ClientId; 27 using offline_pages::ClientId;
28 using offline_pages::DownloadUIAdapter; 28 using offline_pages::DownloadUIAdapter;
29 using offline_pages::DownloadUIItem; 29 using offline_pages::DownloadUIItem;
30 30
31 namespace ntp_snippets { 31 namespace ntp_snippets {
32 32
33 namespace { 33 namespace {
34 34
35 const int kDefaultMaxSuggestionsCount = 5; 35 const base::FeatureParam<int> kMaxSuggestionsCountParam{
36 36 &kRecentOfflineTabSuggestionsFeature, "recent_tabs_max_count", 5};
37 const char* kMaxSuggestionsCountParamName = "recent_tabs_max_count";
38
39 int GetMaxSuggestionsCount() {
40 return variations::GetVariationParamByFeatureAsInt(
41 kRecentOfflineTabSuggestionsFeature, kMaxSuggestionsCountParamName,
42 kDefaultMaxSuggestionsCount);
43 }
44 37
45 struct OrderUIItemsByMostRecentlyCreatedFirst { 38 struct OrderUIItemsByMostRecentlyCreatedFirst {
46 bool operator()(const DownloadUIItem* left, 39 bool operator()(const DownloadUIItem* left,
47 const DownloadUIItem* right) const { 40 const DownloadUIItem* right) const {
48 return left->start_time > right->start_time; 41 return left->start_time > right->start_time;
49 } 42 }
50 }; 43 };
51 44
52 struct OrderUIItemsByUrlAndThenMostRecentlyCreatedFirst { 45 struct OrderUIItemsByUrlAndThenMostRecentlyCreatedFirst {
53 bool operator()(const DownloadUIItem* left, 46 bool operator()(const DownloadUIItem* left,
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 std::unique(ui_items.begin(), ui_items.end(), 265 std::unique(ui_items.begin(), ui_items.end(),
273 [](const DownloadUIItem* left, const DownloadUIItem* right) { 266 [](const DownloadUIItem* left, const DownloadUIItem* right) {
274 return left->url == right->url; 267 return left->url == right->url;
275 }); 268 });
276 ui_items.erase(new_end, ui_items.end()); 269 ui_items.erase(new_end, ui_items.end());
277 std::sort(ui_items.begin(), ui_items.end(), 270 std::sort(ui_items.begin(), ui_items.end(),
278 OrderUIItemsByMostRecentlyCreatedFirst()); 271 OrderUIItemsByMostRecentlyCreatedFirst());
279 std::vector<ContentSuggestion> suggestions; 272 std::vector<ContentSuggestion> suggestions;
280 for (const DownloadUIItem* ui_item : ui_items) { 273 for (const DownloadUIItem* ui_item : ui_items) {
281 suggestions.push_back(ConvertUIItem(*ui_item)); 274 suggestions.push_back(ConvertUIItem(*ui_item));
282 if (static_cast<int>(suggestions.size()) == GetMaxSuggestionsCount()) { 275 if (static_cast<int>(suggestions.size()) ==
276 kMaxSuggestionsCountParam.Get()) {
283 break; 277 break;
284 } 278 }
285 } 279 }
286 return suggestions; 280 return suggestions;
287 } 281 }
288 282
289 void RecentTabSuggestionsProvider::InvalidateSuggestion( 283 void RecentTabSuggestionsProvider::InvalidateSuggestion(
290 const std::string& ui_item_guid) { 284 const std::string& ui_item_guid) {
291 std::string offline_page_id = base::IntToString( 285 std::string offline_page_id = base::IntToString(
292 recent_tabs_ui_adapter_->GetOfflineIdByGuid(ui_item_guid)); 286 recent_tabs_ui_adapter_->GetOfflineIdByGuid(ui_item_guid));
(...skipping 15 matching lines...) Expand all
308 } 302 }
309 303
310 void RecentTabSuggestionsProvider::StoreDismissedIDsToPrefs( 304 void RecentTabSuggestionsProvider::StoreDismissedIDsToPrefs(
311 const std::set<std::string>& dismissed_ids) { 305 const std::set<std::string>& dismissed_ids) {
312 prefs::StoreDismissedIDsToPrefs(pref_service_, 306 prefs::StoreDismissedIDsToPrefs(pref_service_,
313 prefs::kDismissedRecentOfflineTabSuggestions, 307 prefs::kDismissedRecentOfflineTabSuggestions,
314 dismissed_ids); 308 dismissed_ids);
315 } 309 }
316 310
317 } // namespace ntp_snippets 311 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698