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 12 matching lines...) Expand all Loading... | |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 25 | 25 |
| 26 using bookmarks::BookmarkModel; | 26 using bookmarks::BookmarkModel; |
| 27 using bookmarks::BookmarkNode; | 27 using bookmarks::BookmarkNode; |
| 28 | 28 |
| 29 namespace ntp_snippets { | 29 namespace ntp_snippets { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 const int kMaxBookmarks = 10; | 33 constexpr base::FeatureParam<int> kMaxBookmarksParam{ |
| 34 const int kMaxBookmarkAgeInDays = 7; | 34 &kBookmarkSuggestionsFeature, "bookmarks_max_count", 10}; |
| 35 | 35 constexpr base::FeatureParam<int> kMaxBookmarkAgeInDaysParam{ |
| 36 const char* kMaxBookmarksParamName = "bookmarks_max_count"; | 36 &kBookmarkSuggestionsFeature, "bookmarks_max_age_in_days", 7}; |
| 37 const char* kMaxBookmarkAgeInDaysParamName = "bookmarks_max_age_in_days"; | 37 constexpr base::FeatureParam<bool> kConsiderDesktopVisitsParam{ |
| 38 const char* kConsiderDesktopVisitsParamName = | 38 &kBookmarkSuggestionsFeature, "bookmarks_consider_desktop_visits", false}; |
|
Alexei Svitkine (slow)
2017/08/24 18:13:05
Seems you're changing logic as the previous code h
sfiera
2017/08/25 11:56:16
Fixed.
| |
| 39 "bookmarks_consider_desktop_visits"; | |
| 40 | 39 |
| 41 // Any bookmark created or visited after this time will be considered recent. | 40 // Any bookmark created or visited after this time will be considered recent. |
| 42 // Note that bookmarks can be shown that do not meet this threshold. | 41 // Note that bookmarks can be shown that do not meet this threshold. |
| 43 base::Time GetThresholdTime() { | 42 base::Time GetThresholdTime() { |
| 44 return base::Time::Now() - | 43 return base::Time::Now() - |
| 45 base::TimeDelta::FromDays(variations::GetVariationParamByFeatureAsInt( | 44 base::TimeDelta::FromDays(kMaxBookmarkAgeInDaysParam.Get()); |
| 46 ntp_snippets::kBookmarkSuggestionsFeature, | |
| 47 kMaxBookmarkAgeInDaysParamName, kMaxBookmarkAgeInDays)); | |
| 48 } | |
| 49 | |
| 50 // The maximum number of suggestions ever provided. | |
| 51 int GetMaxCount() { | |
| 52 return variations::GetVariationParamByFeatureAsInt( | |
| 53 ntp_snippets::kBookmarkSuggestionsFeature, kMaxBookmarksParamName, | |
| 54 kMaxBookmarks); | |
| 55 } | |
| 56 | |
| 57 bool AreDesktopVisitsConsidered() { | |
| 58 return variations::GetVariationParamByFeatureAsBool( | |
| 59 ntp_snippets::kBookmarkSuggestionsFeature, | |
| 60 kConsiderDesktopVisitsParamName, true); | |
| 61 } | 45 } |
| 62 | 46 |
| 63 } // namespace | 47 } // namespace |
| 64 | 48 |
| 65 BookmarkSuggestionsProvider::BookmarkSuggestionsProvider( | 49 BookmarkSuggestionsProvider::BookmarkSuggestionsProvider( |
| 66 ContentSuggestionsProvider::Observer* observer, | 50 ContentSuggestionsProvider::Observer* observer, |
| 67 bookmarks::BookmarkModel* bookmark_model) | 51 bookmarks::BookmarkModel* bookmark_model) |
| 68 : ContentSuggestionsProvider(observer), | 52 : ContentSuggestionsProvider(observer), |
| 69 category_status_(CategoryStatus::AVAILABLE_LOADING), | 53 category_status_(CategoryStatus::AVAILABLE_LOADING), |
| 70 provided_category_( | 54 provided_category_( |
| 71 Category::FromKnownCategory(KnownCategories::BOOKMARKS)), | 55 Category::FromKnownCategory(KnownCategories::BOOKMARKS)), |
| 72 bookmark_model_(bookmark_model), | 56 bookmark_model_(bookmark_model), |
| 73 fetch_requested_(false), | 57 fetch_requested_(false), |
| 74 end_of_list_last_visit_date_(GetThresholdTime()), | 58 end_of_list_last_visit_date_(GetThresholdTime()), |
| 75 consider_bookmark_visits_from_desktop_(AreDesktopVisitsConsidered()) { | 59 consider_bookmark_visits_from_desktop_( |
| 60 kConsiderDesktopVisitsParam.Get()) { | |
| 76 observer->OnCategoryStatusChanged(this, provided_category_, category_status_); | 61 observer->OnCategoryStatusChanged(this, provided_category_, category_status_); |
| 77 bookmark_model_->AddObserver(this); | 62 bookmark_model_->AddObserver(this); |
| 78 FetchBookmarks(); | 63 FetchBookmarks(); |
| 79 } | 64 } |
| 80 | 65 |
| 81 BookmarkSuggestionsProvider::~BookmarkSuggestionsProvider() { | 66 BookmarkSuggestionsProvider::~BookmarkSuggestionsProvider() { |
| 82 bookmark_model_->RemoveObserver(this); | 67 bookmark_model_->RemoveObserver(this); |
| 83 } | 68 } |
| 84 | 69 |
| 85 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 suggestions->emplace_back(std::move(suggestion)); | 253 suggestions->emplace_back(std::move(suggestion)); |
| 269 } | 254 } |
| 270 | 255 |
| 271 void BookmarkSuggestionsProvider::FetchBookmarksInternal() { | 256 void BookmarkSuggestionsProvider::FetchBookmarksInternal() { |
| 272 DCHECK(bookmark_model_->loaded()); | 257 DCHECK(bookmark_model_->loaded()); |
| 273 | 258 |
| 274 NotifyStatusChanged(CategoryStatus::AVAILABLE); | 259 NotifyStatusChanged(CategoryStatus::AVAILABLE); |
| 275 | 260 |
| 276 base::Time threshold_time = GetThresholdTime(); | 261 base::Time threshold_time = GetThresholdTime(); |
| 277 std::vector<const BookmarkNode*> bookmarks = GetRecentlyVisitedBookmarks( | 262 std::vector<const BookmarkNode*> bookmarks = GetRecentlyVisitedBookmarks( |
| 278 bookmark_model_, GetMaxCount(), threshold_time, | 263 bookmark_model_, kMaxBookmarksParam.Get(), threshold_time, |
| 279 consider_bookmark_visits_from_desktop_); | 264 consider_bookmark_visits_from_desktop_); |
| 280 | 265 |
| 281 std::vector<ContentSuggestion> suggestions; | 266 std::vector<ContentSuggestion> suggestions; |
| 282 for (const BookmarkNode* bookmark : bookmarks) { | 267 for (const BookmarkNode* bookmark : bookmarks) { |
| 283 ConvertBookmark(*bookmark, &suggestions); | 268 ConvertBookmark(*bookmark, &suggestions); |
| 284 } | 269 } |
| 285 | 270 |
| 286 if (suggestions.empty()) { | 271 if (suggestions.empty()) { |
| 287 end_of_list_last_visit_date_ = threshold_time; | 272 end_of_list_last_visit_date_ = threshold_time; |
| 288 } else { | 273 } else { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 303 void BookmarkSuggestionsProvider::NotifyStatusChanged( | 288 void BookmarkSuggestionsProvider::NotifyStatusChanged( |
| 304 CategoryStatus new_status) { | 289 CategoryStatus new_status) { |
| 305 if (category_status_ == new_status) { | 290 if (category_status_ == new_status) { |
| 306 return; | 291 return; |
| 307 } | 292 } |
| 308 category_status_ = new_status; | 293 category_status_ = new_status; |
| 309 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); | 294 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); |
| 310 } | 295 } |
| 311 | 296 |
| 312 } // namespace ntp_snippets | 297 } // namespace ntp_snippets |
| OLD | NEW |