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

Unified Diff: components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc

Issue 2279123002: [Sync] Initial implementation of foreign sessions suggestions provider. (Closed)
Patch Set: Adding sessions deps to BUILD.gn 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc
diff --git a/components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc b/components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc
index 7e43abd335f02d5e5bbf5d688fa5b23443eb671c..935829359234c0de2adef720c106016b5375ed3a 100644
--- a/components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc
+++ b/components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc
@@ -29,6 +29,8 @@
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
+namespace ntp_snippets {
+
namespace {
const int kMaxBookmarks = 10;
@@ -43,53 +45,35 @@ const char* kUseCreationDateFallbackForDaysParamName =
"bookmarks_creation_date_fallback_days";
const char* kShowIfEmptyParamName = "bookmarks_show_if_empty";
+// Any bookmark created or visited after this time will be considered recent.
+// Note that bookmarks can be shown that do not meet this threshold.
base::Time GetThresholdTime() {
- std::string age_in_days_string = variations::GetVariationParamValueByFeature(
- ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarkAgeInDaysParamName);
- int age_in_days = 0;
- if (!base::StringToInt(age_in_days_string, &age_in_days)) {
- if (!age_in_days_string.empty())
- LOG(WARNING) << "Failed to parse bookmark age " << age_in_days_string;
- age_in_days = kMaxBookmarkAgeInDays;
- }
- return base::Time::Now() - base::TimeDelta::FromDays(age_in_days);
+ return base::Time::Now() -
+ base::TimeDelta::FromDays(GetParamAsInt(
+ ntp_snippets::kBookmarkSuggestionsFeature,
+ kMaxBookmarkAgeInDaysParamName, kMaxBookmarkAgeInDays));
}
+// Should the creation timestamp of a bookmark be used as a fallback if no last
+// visited timestamp is present.
Marc Treib 2016/09/16 12:26:48 nit: This sounds like it would return a bool.
skym 2016/09/16 18:18:47 This value is confusing. Updated.
int UseCreationDateFallbackForDays() {
- std::string days_string = variations::GetVariationParamValueByFeature(
- ntp_snippets::kBookmarkSuggestionsFeature,
- kUseCreationDateFallbackForDaysParamName);
- int days = 0;
- if (!base::StringToInt(days_string, &days)) {
- if (!days_string.empty())
- LOG(WARNING) << "Failed to parse bookmark fallback days " << days_string;
- days = kUseCreationDateFallbackForDays;
- }
- return days;
+ return GetParamAsInt(ntp_snippets::kBookmarkSuggestionsFeature,
+ kUseCreationDateFallbackForDaysParamName,
+ kUseCreationDateFallbackForDays);
}
+// The maximum number of suggestions ever provided.
int GetMaxCount() {
- std::string max_count_string = variations::GetVariationParamValueByFeature(
- ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarksParamName);
- int max_count = 0;
- if (base::StringToInt(max_count_string, &max_count))
- return max_count;
- if (!max_count_string.empty())
- LOG(WARNING) << "Failed to parse max bookmarks count " << max_count_string;
-
- return kMaxBookmarks;
+ return GetParamAsInt(ntp_snippets::kBookmarkSuggestionsFeature,
+ kMaxBookmarksParamName, kMaxBookmarks);
}
+// The minimum number of suggestions ever provided. If there are not enough
+// recent bookmarks to meet this minimum, then bookmarks more stale than the
+// threshold are used.
Marc Treib 2016/09/16 12:26:48 I don't think this quite matches the behavior (whi
skym 2016/09/16 18:18:47 Okay, I've updated this, let me know if you thinks
int GetMinCount() {
- std::string min_count_string = variations::GetVariationParamValueByFeature(
- ntp_snippets::kBookmarkSuggestionsFeature, kMinBookmarksParamName);
- int min_count = 0;
- if (base::StringToInt(min_count_string, &min_count))
- return min_count;
- if (!min_count_string.empty())
- LOG(WARNING) << "Failed to parse min bookmarks count " << min_count_string;
-
- return kMinBookmarks;
+ return GetParamAsInt(ntp_snippets::kBookmarkSuggestionsFeature,
+ kMinBookmarksParamName, kMinBookmarks);
}
bool ShouldShowIfEmpty() {
@@ -106,8 +90,6 @@ bool ShouldShowIfEmpty() {
} // namespace
-namespace ntp_snippets {
-
BookmarkSuggestionsProvider::BookmarkSuggestionsProvider(
ContentSuggestionsProvider::Observer* observer,
CategoryFactory* category_factory,

Powered by Google App Engine
This is Rietveld 408576698