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

Side by Side Diff: components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc

Issue 2275613002: Bookmark Suggestions: Make 'creation date fallback' time configurable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_proguard
Patch Set: Created 4 years, 3 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 | « no previous file | 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 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/bookmarks/bookmark_suggestions_provider.h" 5 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 21 matching lines...) Expand all
32 namespace { 32 namespace {
33 33
34 const int kMaxBookmarks = 10; 34 const int kMaxBookmarks = 10;
35 const int kMinBookmarks = 3; 35 const int kMinBookmarks = 3;
36 const int kMaxBookmarkAgeInDays = 42; 36 const int kMaxBookmarkAgeInDays = 42;
37 const int kUseCreationDateFallbackForDays = 42; 37 const int kUseCreationDateFallbackForDays = 42;
38 38
39 const char* kMaxBookmarksParamName = "bookmarks_max_count"; 39 const char* kMaxBookmarksParamName = "bookmarks_max_count";
40 const char* kMinBookmarksParamName = "bookmarks_min_count"; 40 const char* kMinBookmarksParamName = "bookmarks_min_count";
41 const char* kMaxBookmarkAgeInDaysParamName = "bookmarks_max_age_in_days"; 41 const char* kMaxBookmarkAgeInDaysParamName = "bookmarks_max_age_in_days";
42 const char* kUseCreationDateFallbackForDaysParamName =
43 "bookmarks_creation_date_fallback_days";
42 44
43 base::Time GetThresholdTime() { 45 base::Time GetThresholdTime() {
44 std::string age_in_days_string = variations::GetVariationParamValueByFeature( 46 std::string age_in_days_string = variations::GetVariationParamValueByFeature(
45 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarkAgeInDaysParamName); 47 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarkAgeInDaysParamName);
46 int age_in_days = 0; 48 int age_in_days = 0;
47 if (!base::StringToInt(age_in_days_string, &age_in_days)) { 49 if (!base::StringToInt(age_in_days_string, &age_in_days)) {
48 if (!age_in_days_string.empty()) 50 if (!age_in_days_string.empty())
49 LOG(WARNING) << "Failed to parse bookmark age " << age_in_days_string; 51 LOG(WARNING) << "Failed to parse bookmark age " << age_in_days_string;
50 age_in_days = kMaxBookmarkAgeInDays; 52 age_in_days = kMaxBookmarkAgeInDays;
51 } 53 }
52 return base::Time::Now() - base::TimeDelta::FromDays(age_in_days); 54 return base::Time::Now() - base::TimeDelta::FromDays(age_in_days);
53 } 55 }
54 56
57 int UseCreationDateFallbackForDays() {
58 std::string days_string = variations::GetVariationParamValueByFeature(
59 ntp_snippets::kBookmarkSuggestionsFeature,
60 kUseCreationDateFallbackForDaysParamName);
61 int days = 0;
62 if (!base::StringToInt(days_string, &days)) {
63 if (!days_string.empty())
64 LOG(WARNING) << "Failed to parse bookmark fallback days " << days_string;
65 days = kUseCreationDateFallbackForDays;
66 }
67 return days;
68 }
69
55 int GetMaxCount() { 70 int GetMaxCount() {
56 std::string max_count_string = variations::GetVariationParamValueByFeature( 71 std::string max_count_string = variations::GetVariationParamValueByFeature(
57 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarksParamName); 72 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarksParamName);
58 int max_count = 0; 73 int max_count = 0;
59 if (base::StringToInt(max_count_string, &max_count)) 74 if (base::StringToInt(max_count_string, &max_count))
60 return max_count; 75 return max_count;
61 if (!max_count_string.empty()) 76 if (!max_count_string.empty())
62 LOG(WARNING) << "Failed to parse max bookmarks count" << max_count_string; 77 LOG(WARNING) << "Failed to parse max bookmarks count" << max_count_string;
63 78
64 return kMaxBookmarks; 79 return kMaxBookmarks;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (pref_service->HasPrefPath(prefs::kBookmarksFirstM54Start)) { 113 if (pref_service->HasPrefPath(prefs::kBookmarksFirstM54Start)) {
99 first_m54_start = base::Time::FromInternalValue( 114 first_m54_start = base::Time::FromInternalValue(
100 pref_service->GetInt64(prefs::kBookmarksFirstM54Start)); 115 pref_service->GetInt64(prefs::kBookmarksFirstM54Start));
101 } else { 116 } else {
102 first_m54_start = now; 117 first_m54_start = now;
103 pref_service->SetInt64(prefs::kBookmarksFirstM54Start, 118 pref_service->SetInt64(prefs::kBookmarksFirstM54Start,
104 first_m54_start.ToInternalValue()); 119 first_m54_start.ToInternalValue());
105 } 120 }
106 base::TimeDelta time_since_first_m54_start = now - first_m54_start; 121 base::TimeDelta time_since_first_m54_start = now - first_m54_start;
107 creation_date_fallback_ = 122 creation_date_fallback_ =
108 time_since_first_m54_start.InDays() < kUseCreationDateFallbackForDays; 123 time_since_first_m54_start.InDays() < UseCreationDateFallbackForDays();
sfiera 2016/08/23 15:31:14 Seems like setting "0" (or negative) would have th
Marc Treib 2016/08/23 15:35:19 That's exactly the behavior you'd expect, no? Use
sfiera 2016/08/23 15:42:04 I might expect that "0" would mean "use the compil
Marc Treib 2016/08/23 16:09:38 I'd expect a comment if it meant that! Anyway, com
109 bookmark_model_->AddObserver(this); 124 bookmark_model_->AddObserver(this);
110 FetchBookmarks(); 125 FetchBookmarks();
111 } 126 }
112 127
113 BookmarkSuggestionsProvider::~BookmarkSuggestionsProvider() { 128 BookmarkSuggestionsProvider::~BookmarkSuggestionsProvider() {
114 bookmark_model_->RemoveObserver(this); 129 bookmark_model_->RemoveObserver(this);
115 } 130 }
116 131
117 // static 132 // static
118 void BookmarkSuggestionsProvider::RegisterProfilePrefs( 133 void BookmarkSuggestionsProvider::RegisterProfilePrefs(
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 286
272 void BookmarkSuggestionsProvider::NotifyStatusChanged( 287 void BookmarkSuggestionsProvider::NotifyStatusChanged(
273 CategoryStatus new_status) { 288 CategoryStatus new_status) {
274 if (category_status_ == new_status) 289 if (category_status_ == new_status)
275 return; 290 return;
276 category_status_ = new_status; 291 category_status_ = new_status;
277 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); 292 observer()->OnCategoryStatusChanged(this, provided_category_, new_status);
278 } 293 }
279 294
280 } // namespace ntp_snippets 295 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698