Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 23 matching lines...) Expand all Loading... | |
| 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 = | 42 const char* kUseCreationDateFallbackForDaysParamName = |
| 43 "bookmarks_creation_date_fallback_days"; | 43 "bookmarks_creation_date_fallback_days"; |
| 44 const char* kShowIfEmptyParamName = "bookmarks_show_if_empty"; | |
| 44 | 45 |
| 45 base::Time GetThresholdTime() { | 46 base::Time GetThresholdTime() { |
| 46 std::string age_in_days_string = variations::GetVariationParamValueByFeature( | 47 std::string age_in_days_string = variations::GetVariationParamValueByFeature( |
| 47 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarkAgeInDaysParamName); | 48 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarkAgeInDaysParamName); |
| 48 int age_in_days = 0; | 49 int age_in_days = 0; |
| 49 if (!base::StringToInt(age_in_days_string, &age_in_days)) { | 50 if (!base::StringToInt(age_in_days_string, &age_in_days)) { |
| 50 if (!age_in_days_string.empty()) | 51 if (!age_in_days_string.empty()) |
| 51 LOG(WARNING) << "Failed to parse bookmark age " << age_in_days_string; | 52 LOG(WARNING) << "Failed to parse bookmark age " << age_in_days_string; |
| 52 age_in_days = kMaxBookmarkAgeInDays; | 53 age_in_days = kMaxBookmarkAgeInDays; |
| 53 } | 54 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 67 return days; | 68 return days; |
| 68 } | 69 } |
| 69 | 70 |
| 70 int GetMaxCount() { | 71 int GetMaxCount() { |
| 71 std::string max_count_string = variations::GetVariationParamValueByFeature( | 72 std::string max_count_string = variations::GetVariationParamValueByFeature( |
| 72 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarksParamName); | 73 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarksParamName); |
| 73 int max_count = 0; | 74 int max_count = 0; |
| 74 if (base::StringToInt(max_count_string, &max_count)) | 75 if (base::StringToInt(max_count_string, &max_count)) |
| 75 return max_count; | 76 return max_count; |
| 76 if (!max_count_string.empty()) | 77 if (!max_count_string.empty()) |
| 77 LOG(WARNING) << "Failed to parse max bookmarks count" << max_count_string; | 78 LOG(WARNING) << "Failed to parse max bookmarks count " << max_count_string; |
| 78 | 79 |
| 79 return kMaxBookmarks; | 80 return kMaxBookmarks; |
| 80 } | 81 } |
| 81 | 82 |
| 82 int GetMinCount() { | 83 int GetMinCount() { |
| 83 std::string min_count_string = variations::GetVariationParamValueByFeature( | 84 std::string min_count_string = variations::GetVariationParamValueByFeature( |
| 84 ntp_snippets::kBookmarkSuggestionsFeature, kMinBookmarksParamName); | 85 ntp_snippets::kBookmarkSuggestionsFeature, kMinBookmarksParamName); |
| 85 int min_count = 0; | 86 int min_count = 0; |
| 86 if (base::StringToInt(min_count_string, &min_count)) | 87 if (base::StringToInt(min_count_string, &min_count)) |
| 87 return min_count; | 88 return min_count; |
| 88 if (!min_count_string.empty()) | 89 if (!min_count_string.empty()) |
| 89 LOG(WARNING) << "Failed to parse min bookmarks count" << min_count_string; | 90 LOG(WARNING) << "Failed to parse min bookmarks count " << min_count_string; |
| 90 | 91 |
| 91 return kMinBookmarks; | 92 return kMinBookmarks; |
| 92 } | 93 } |
| 93 | 94 |
| 95 bool ShowIfEmpty() { | |
|
Bernhard Bauer
2016/08/25 10:07:20
Nit: Maybe "ShouldShowIfEmpty()" to make it clear
Marc Treib
2016/08/25 10:15:09
Done.
| |
| 96 std::string show_if_empty = variations::GetVariationParamValueByFeature( | |
| 97 ntp_snippets::kBookmarkSuggestionsFeature, kShowIfEmptyParamName); | |
| 98 if (show_if_empty.empty() || show_if_empty == "0") | |
|
Bernhard Bauer
2016/08/25 10:07:20
If the variation parameters are strings, why not j
Marc Treib
2016/08/25 10:15:09
No reason :) Done.
| |
| 99 return false; | |
| 100 if (show_if_empty == "1") | |
| 101 return true; | |
| 102 | |
| 103 LOG(WARNING) << "Failed to parse show if empty " << show_if_empty; | |
| 104 return false; | |
| 105 } | |
| 106 | |
| 94 } // namespace | 107 } // namespace |
| 95 | 108 |
| 96 namespace ntp_snippets { | 109 namespace ntp_snippets { |
| 97 | 110 |
| 98 BookmarkSuggestionsProvider::BookmarkSuggestionsProvider( | 111 BookmarkSuggestionsProvider::BookmarkSuggestionsProvider( |
| 99 ContentSuggestionsProvider::Observer* observer, | 112 ContentSuggestionsProvider::Observer* observer, |
| 100 CategoryFactory* category_factory, | 113 CategoryFactory* category_factory, |
| 101 bookmarks::BookmarkModel* bookmark_model, | 114 bookmarks::BookmarkModel* bookmark_model, |
| 102 PrefService* pref_service) | 115 PrefService* pref_service) |
| 103 : ContentSuggestionsProvider(observer, category_factory), | 116 : ContentSuggestionsProvider(observer, category_factory), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 Category category) { | 157 Category category) { |
| 145 DCHECK_EQ(category, provided_category_); | 158 DCHECK_EQ(category, provided_category_); |
| 146 return category_status_; | 159 return category_status_; |
| 147 } | 160 } |
| 148 | 161 |
| 149 CategoryInfo BookmarkSuggestionsProvider::GetCategoryInfo(Category category) { | 162 CategoryInfo BookmarkSuggestionsProvider::GetCategoryInfo(Category category) { |
| 150 return CategoryInfo( | 163 return CategoryInfo( |
| 151 l10n_util::GetStringUTF16(IDS_NTP_BOOKMARK_SUGGESTIONS_SECTION_HEADER), | 164 l10n_util::GetStringUTF16(IDS_NTP_BOOKMARK_SUGGESTIONS_SECTION_HEADER), |
| 152 ContentSuggestionsCardLayout::MINIMAL_CARD, | 165 ContentSuggestionsCardLayout::MINIMAL_CARD, |
| 153 /* has_more_button */ true, | 166 /* has_more_button */ true, |
| 154 /* show_if_empty */ true); | 167 /* show_if_empty */ ShowIfEmpty() && bookmark_model_->HasBookmarks()); |
| 155 // TODO(treib): Setting show_if_empty to true is a temporary hack, see | 168 // TODO(treib): Setting show_if_empty to true is a temporary hack, see |
| 156 // crbug.com/640568. | 169 // crbug.com/640568. |
| 157 } | 170 } |
| 158 | 171 |
| 159 void BookmarkSuggestionsProvider::DismissSuggestion( | 172 void BookmarkSuggestionsProvider::DismissSuggestion( |
| 160 const std::string& suggestion_id) { | 173 const std::string& suggestion_id) { |
| 161 DCHECK(bookmark_model_->loaded()); | 174 DCHECK(bookmark_model_->loaded()); |
| 162 GURL url(GetWithinCategoryIDFromUniqueID(suggestion_id)); | 175 GURL url(GetWithinCategoryIDFromUniqueID(suggestion_id)); |
| 163 MarkBookmarksDismissed(bookmark_model_, url); | 176 MarkBookmarksDismissed(bookmark_model_, url); |
| 164 } | 177 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 | 302 |
| 290 void BookmarkSuggestionsProvider::NotifyStatusChanged( | 303 void BookmarkSuggestionsProvider::NotifyStatusChanged( |
| 291 CategoryStatus new_status) { | 304 CategoryStatus new_status) { |
| 292 if (category_status_ == new_status) | 305 if (category_status_ == new_status) |
| 293 return; | 306 return; |
| 294 category_status_ = new_status; | 307 category_status_ = new_status; |
| 295 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); | 308 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); |
| 296 } | 309 } |
| 297 | 310 |
| 298 } // namespace ntp_snippets | 311 } // namespace ntp_snippets |
| OLD | NEW |