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 10 matching lines...) Expand all Loading... | |
21 #include "grit/components_strings.h" | 21 #include "grit/components_strings.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
24 | 24 |
25 using bookmarks::BookmarkModel; | 25 using bookmarks::BookmarkModel; |
26 using bookmarks::BookmarkNode; | 26 using bookmarks::BookmarkNode; |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 const int kMaxBookmarks = 10; | 30 const int kMaxBookmarks = 10; |
31 const int kMinBookmarks = 3; | |
31 const int kMaxBookmarkAgeInDays = 42; | 32 const int kMaxBookmarkAgeInDays = 42; |
32 | 33 |
33 const char* kMaxBookmarksParamName = "max_count"; | 34 const char* kMaxBookmarksParamName = "max_count"; |
35 const char* kMinBookmarksParamName = "min_count"; | |
34 const char* kMaxBookmarkAgeInDaysParamName = "max_age_in_days"; | 36 const char* kMaxBookmarkAgeInDaysParamName = "max_age_in_days"; |
Marc Treib
2016/08/18 09:31:44
Unrelated to this CL, but: AFAIK these param names
Philipp Keck
2016/08/19 11:20:54
Done.
| |
35 | 37 |
36 base::Time GetThresholdTime() { | 38 base::Time GetThresholdTime() { |
37 std::string age_in_days_string = variations::GetVariationParamValueByFeature( | 39 std::string age_in_days_string = variations::GetVariationParamValueByFeature( |
38 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarkAgeInDaysParamName); | 40 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarkAgeInDaysParamName); |
39 int age_in_days = 0; | 41 int age_in_days = 0; |
40 if (!base::StringToInt(age_in_days_string, &age_in_days)) | 42 if (!base::StringToInt(age_in_days_string, &age_in_days)) |
41 age_in_days = kMaxBookmarkAgeInDays; | 43 age_in_days = kMaxBookmarkAgeInDays; |
42 | 44 |
43 return base::Time::Now() - base::TimeDelta::FromDays(age_in_days); | 45 return base::Time::Now() - base::TimeDelta::FromDays(age_in_days); |
44 } | 46 } |
45 | 47 |
46 int GetMaxCount() { | 48 int GetMaxCount() { |
47 std::string max_count_string = variations::GetVariationParamValueByFeature( | 49 std::string max_count_string = variations::GetVariationParamValueByFeature( |
48 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarksParamName); | 50 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarksParamName); |
49 int max_count = 0; | 51 int max_count = 0; |
50 if (base::StringToInt(max_count_string, &max_count)) | 52 if (base::StringToInt(max_count_string, &max_count)) |
51 return max_count; | 53 return max_count; |
52 | 54 |
53 return kMaxBookmarks; | 55 return kMaxBookmarks; |
54 } | 56 } |
55 | 57 |
58 int GetMinCount() { | |
59 std::string min_count_string = variations::GetVariationParamValueByFeature( | |
60 ntp_snippets::kBookmarkSuggestionsFeature, kMinBookmarksParamName); | |
61 int min_count = 0; | |
62 if (base::StringToInt(min_count_string, &min_count)) | |
Marc Treib
2016/08/18 09:31:44
nit: If the string is non-empty but fails to parse
Philipp Keck
2016/08/19 11:20:54
Done.
| |
63 return min_count; | |
64 | |
65 return kMinBookmarks; | |
66 } | |
67 | |
56 } // namespace | 68 } // namespace |
57 | 69 |
58 namespace ntp_snippets { | 70 namespace ntp_snippets { |
59 | 71 |
60 BookmarkSuggestionsProvider::BookmarkSuggestionsProvider( | 72 BookmarkSuggestionsProvider::BookmarkSuggestionsProvider( |
61 ContentSuggestionsProvider::Observer* observer, | 73 ContentSuggestionsProvider::Observer* observer, |
62 CategoryFactory* category_factory, | 74 CategoryFactory* category_factory, |
63 bookmarks::BookmarkModel* bookmark_model) | 75 bookmarks::BookmarkModel* bookmark_model) |
64 : ContentSuggestionsProvider(observer, category_factory), | 76 : ContentSuggestionsProvider(observer, category_factory), |
65 category_status_(CategoryStatus::AVAILABLE_LOADING), | 77 category_status_(CategoryStatus::AVAILABLE_LOADING), |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 return suggestion; | 206 return suggestion; |
195 } | 207 } |
196 | 208 |
197 void BookmarkSuggestionsProvider::FetchBookmarksInternal() { | 209 void BookmarkSuggestionsProvider::FetchBookmarksInternal() { |
198 DCHECK(bookmark_model_->loaded()); | 210 DCHECK(bookmark_model_->loaded()); |
199 | 211 |
200 NotifyStatusChanged(CategoryStatus::AVAILABLE); | 212 NotifyStatusChanged(CategoryStatus::AVAILABLE); |
201 | 213 |
202 base::Time threshold_time = GetThresholdTime(); | 214 base::Time threshold_time = GetThresholdTime(); |
203 std::vector<const BookmarkNode*> bookmarks = GetRecentlyVisitedBookmarks( | 215 std::vector<const BookmarkNode*> bookmarks = GetRecentlyVisitedBookmarks( |
204 bookmark_model_, GetMaxCount(), threshold_time); | 216 bookmark_model_, GetMinCount(), GetMaxCount(), |
217 threshold_time); | |
205 | 218 |
206 std::vector<ContentSuggestion> suggestions; | 219 std::vector<ContentSuggestion> suggestions; |
207 for (const BookmarkNode* bookmark : bookmarks) | 220 for (const BookmarkNode* bookmark : bookmarks) |
208 suggestions.emplace_back(ConvertBookmark(bookmark)); | 221 suggestions.emplace_back(ConvertBookmark(bookmark)); |
209 | 222 |
210 if (suggestions.empty()) | 223 if (suggestions.empty()) |
211 end_of_list_last_visit_date_ = threshold_time; | 224 end_of_list_last_visit_date_ = threshold_time; |
212 else | 225 else |
213 end_of_list_last_visit_date_ = suggestions.back().publish_date(); | 226 end_of_list_last_visit_date_ = suggestions.back().publish_date(); |
214 | 227 |
(...skipping 10 matching lines...) Expand all Loading... | |
225 | 238 |
226 void BookmarkSuggestionsProvider::NotifyStatusChanged( | 239 void BookmarkSuggestionsProvider::NotifyStatusChanged( |
227 CategoryStatus new_status) { | 240 CategoryStatus new_status) { |
228 if (category_status_ == new_status) | 241 if (category_status_ == new_status) |
229 return; | 242 return; |
230 category_status_ = new_status; | 243 category_status_ = new_status; |
231 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); | 244 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); |
232 } | 245 } |
233 | 246 |
234 } // namespace ntp_snippets | 247 } // namespace ntp_snippets |
OLD | NEW |