Commit 92489594 authored by treib's avatar treib Committed by Commit bot

[NTP Snippets] Don't show the bookmark section if there are no bookmarks at all

Also introduce a variation parameter to enable the "show if empty" behavior - it's off by default.

Followup to https://codereview.chromium.org/2277743002

BUG=640568

Review-Url: https://codereview.chromium.org/2277523003
Cr-Commit-Position: refs/heads/master@{#414399}
parent 22feb81b
......@@ -192,8 +192,8 @@ public class SnippetsBridge implements SuggestionsSource {
@CalledByNative
private static SuggestionsCategoryInfo createSuggestionsCategoryInfo(
String title, int cardLayout, boolean hasMoreButton, boolean hideIfEmpty) {
return new SuggestionsCategoryInfo(title, cardLayout, hasMoreButton, hideIfEmpty);
String title, int cardLayout, boolean hasMoreButton, boolean showIfEmpty) {
return new SuggestionsCategoryInfo(title, cardLayout, hasMoreButton, showIfEmpty);
}
@CalledByNative
......
......@@ -41,6 +41,7 @@ const char* kMinBookmarksParamName = "bookmarks_min_count";
const char* kMaxBookmarkAgeInDaysParamName = "bookmarks_max_age_in_days";
const char* kUseCreationDateFallbackForDaysParamName =
"bookmarks_creation_date_fallback_days";
const char* kShowIfEmptyParamName = "bookmarks_show_if_empty";
base::Time GetThresholdTime() {
std::string age_in_days_string = variations::GetVariationParamValueByFeature(
......@@ -74,7 +75,7 @@ int GetMaxCount() {
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;
LOG(WARNING) << "Failed to parse max bookmarks count " << max_count_string;
return kMaxBookmarks;
}
......@@ -86,11 +87,23 @@ int GetMinCount() {
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;
LOG(WARNING) << "Failed to parse min bookmarks count " << min_count_string;
return kMinBookmarks;
}
bool ShouldShowIfEmpty() {
std::string show_if_empty = variations::GetVariationParamValueByFeature(
ntp_snippets::kBookmarkSuggestionsFeature, kShowIfEmptyParamName);
if (show_if_empty.empty() || show_if_empty == "false")
return false;
if (show_if_empty == "true")
return true;
LOG(WARNING) << "Failed to parse show if empty " << show_if_empty;
return false;
}
} // namespace
namespace ntp_snippets {
......@@ -151,7 +164,8 @@ CategoryInfo BookmarkSuggestionsProvider::GetCategoryInfo(Category category) {
l10n_util::GetStringUTF16(IDS_NTP_BOOKMARK_SUGGESTIONS_SECTION_HEADER),
ContentSuggestionsCardLayout::MINIMAL_CARD,
/* has_more_button */ true,
/* show_if_empty */ true);
/* show_if_empty */ ShouldShowIfEmpty() &&
bookmark_model_->HasBookmarks());
// TODO(treib): Setting show_if_empty to true is a temporary hack, see
// crbug.com/640568.
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment