Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/reading_list/reading_list_suggestions_provider .h" | 5 #include "components/ntp_snippets/reading_list/reading_list_suggestions_provider .h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 IDS_NTP_READING_LIST_SUGGESTIONS_SECTION_HEADER), | 63 IDS_NTP_READING_LIST_SUGGESTIONS_SECTION_HEADER), |
| 64 ContentSuggestionsCardLayout::FULL_CARD, | 64 ContentSuggestionsCardLayout::FULL_CARD, |
| 65 ContentSuggestionsAdditionalAction::VIEW_ALL, | 65 ContentSuggestionsAdditionalAction::VIEW_ALL, |
| 66 /*show_if_empty=*/false, | 66 /*show_if_empty=*/false, |
| 67 l10n_util::GetStringUTF16( | 67 l10n_util::GetStringUTF16( |
| 68 IDS_NTP_READING_LIST_SUGGESTIONS_SECTION_EMPTY)); | 68 IDS_NTP_READING_LIST_SUGGESTIONS_SECTION_EMPTY)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void ReadingListSuggestionsProvider::DismissSuggestion( | 71 void ReadingListSuggestionsProvider::DismissSuggestion( |
| 72 const ContentSuggestion::ID& suggestion_id) { | 72 const ContentSuggestion::ID& suggestion_id) { |
| 73 // TODO(crbug.com/702241): Implement this method. | 73 DCHECK(reading_list_model_->loaded()); |
| 74 GURL url(suggestion_id.id_within_category()); | |
| 75 SetDismissedState(url, true); | |
| 74 } | 76 } |
| 75 | 77 |
| 76 void ReadingListSuggestionsProvider::FetchSuggestionImage( | 78 void ReadingListSuggestionsProvider::FetchSuggestionImage( |
| 77 const ContentSuggestion::ID& suggestion_id, | 79 const ContentSuggestion::ID& suggestion_id, |
| 78 const ImageFetchedCallback& callback) { | 80 const ImageFetchedCallback& callback) { |
| 79 base::ThreadTaskRunnerHandle::Get()->PostTask( | 81 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 80 FROM_HERE, base::Bind(callback, gfx::Image())); | 82 FROM_HERE, base::Bind(callback, gfx::Image())); |
| 81 } | 83 } |
| 82 | 84 |
| 83 void ReadingListSuggestionsProvider::Fetch( | 85 void ReadingListSuggestionsProvider::Fetch( |
| 84 const Category& category, | 86 const Category& category, |
| 85 const std::set<std::string>& known_suggestion_ids, | 87 const std::set<std::string>& known_suggestion_ids, |
| 86 const FetchDoneCallback& callback) { | 88 const FetchDoneCallback& callback) { |
| 87 LOG(DFATAL) << "ReadingListSuggestionsProvider has no |Fetch| functionality!"; | 89 LOG(DFATAL) << "ReadingListSuggestionsProvider has no |Fetch| functionality!"; |
| 88 base::ThreadTaskRunnerHandle::Get()->PostTask( | 90 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 89 FROM_HERE, | 91 FROM_HERE, |
| 90 base::Bind(callback, | 92 base::Bind(callback, |
| 91 Status(StatusCode::PERMANENT_ERROR, | 93 Status(StatusCode::PERMANENT_ERROR, |
| 92 "ReadingListSuggestionsProvider has no |Fetch| " | 94 "ReadingListSuggestionsProvider has no |Fetch| " |
| 93 "functionality!"), | 95 "functionality!"), |
| 94 base::Passed(std::vector<ContentSuggestion>()))); | 96 base::Passed(std::vector<ContentSuggestion>()))); |
| 95 } | 97 } |
| 96 | 98 |
| 97 void ReadingListSuggestionsProvider::ClearHistory( | 99 void ReadingListSuggestionsProvider::ClearHistory( |
| 98 base::Time begin, | 100 base::Time begin, |
| 99 base::Time end, | 101 base::Time end, |
| 100 const base::Callback<bool(const GURL& url)>& filter) { | 102 const base::Callback<bool(const GURL& url)>& filter) { |
| 101 // TODO(crbug.com/702241): Implement this method. | 103 // Ignored. |
|
Marc Treib
2017/04/11 12:35:15
nit: Mention why it's okay to ignore? (I'd assume
gambard
2017/04/11 13:29:53
Reading List has nothing to do with history :)
I h
| |
| 102 } | 104 } |
| 103 | 105 |
| 104 void ReadingListSuggestionsProvider::ClearCachedSuggestions(Category category) { | 106 void ReadingListSuggestionsProvider::ClearCachedSuggestions(Category category) { |
| 105 DCHECK_EQ(category, provided_category_); | 107 DCHECK_EQ(category, provided_category_); |
| 106 // Ignored. | 108 // Ignored. |
| 107 } | 109 } |
| 108 | 110 |
| 109 void ReadingListSuggestionsProvider::GetDismissedSuggestionsForDebugging( | 111 void ReadingListSuggestionsProvider::GetDismissedSuggestionsForDebugging( |
| 110 Category category, | 112 Category category, |
| 111 const DismissedSuggestionsCallback& callback) { | 113 const DismissedSuggestionsCallback& callback) { |
| 112 // TODO(crbug.com/702241): Implement this method. | 114 // The provider does not store the dismissed suggestions, returning an empty |
| 115 // vector. | |
|
Marc Treib
2017/04/11 12:35:15
So essentially "not implemented"... hm.
Couldn't y
gambard
2017/04/11 13:29:53
Ok, but I guess the comment in the content_suggest
Marc Treib
2017/04/11 13:41:08
You mean the "may return an empty vector" part? I
gambard
2017/04/11 15:01:18
Isn't it the page implemented in chrome/browser/ui
Marc Treib
2017/04/11 15:28:14
Currently it is, yes. See e.g. components/ntp_tile
gambard
2017/04/12 07:50:43
I have created crbug.com/710769
| |
| 116 callback.Run(std::vector<ContentSuggestion>()); | |
| 113 } | 117 } |
| 114 void ReadingListSuggestionsProvider::ClearDismissedSuggestionsForDebugging( | 118 void ReadingListSuggestionsProvider::ClearDismissedSuggestionsForDebugging( |
|
Marc Treib
2017/04/11 12:35:15
nit: empty line before
gambard
2017/04/11 13:29:53
Done.
| |
| 115 Category category) { | 119 Category category) { |
| 116 // TODO(crbug.com/702241): Implement this method. | 120 for (const auto& url : reading_list_model_->Keys()) { |
| 121 SetDismissedState(url, false); | |
| 122 } | |
| 117 } | 123 } |
| 118 | 124 |
| 119 void ReadingListSuggestionsProvider::ReadingListModelLoaded( | 125 void ReadingListSuggestionsProvider::ReadingListModelLoaded( |
| 120 const ReadingListModel* model) { | 126 const ReadingListModel* model) { |
| 121 DCHECK(model == reading_list_model_); | 127 DCHECK(model == reading_list_model_); |
| 122 FetchReadingListInternal(); | 128 FetchReadingListInternal(); |
| 123 } | 129 } |
| 124 | 130 |
| 125 void ReadingListSuggestionsProvider::ReadingListModelBeingDeleted( | 131 void ReadingListSuggestionsProvider::ReadingListModelBeingDeleted( |
| 126 const ReadingListModel* model) { | 132 const ReadingListModel* model) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 145 | 151 |
| 146 void ReadingListSuggestionsProvider::FetchReadingListInternal() { | 152 void ReadingListSuggestionsProvider::FetchReadingListInternal() { |
| 147 if (!reading_list_model_ || reading_list_model_->IsPerformingBatchUpdates()) { | 153 if (!reading_list_model_ || reading_list_model_->IsPerformingBatchUpdates()) { |
| 148 return; | 154 return; |
| 149 } | 155 } |
| 150 | 156 |
| 151 DCHECK(reading_list_model_->loaded()); | 157 DCHECK(reading_list_model_->loaded()); |
| 152 std::vector<const ReadingListEntry*> entries; | 158 std::vector<const ReadingListEntry*> entries; |
| 153 for (const GURL& url : reading_list_model_->Keys()) { | 159 for (const GURL& url : reading_list_model_->Keys()) { |
| 154 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); | 160 const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); |
| 155 if (!entry->IsRead()) { | 161 if (!entry->IsRead() && !entry->ContentSuggestionsExtra()->dismissed) { |
| 156 entries.emplace_back(entry); | 162 entries.emplace_back(entry); |
| 157 } | 163 } |
| 158 } | 164 } |
| 159 | 165 |
| 160 if (entries.size() > kMaxEntries) { | 166 if (entries.size() > kMaxEntries) { |
| 161 // Get the |kMaxEntries| most recent entries. | 167 // Get the |kMaxEntries| most recent entries. |
| 162 std::partial_sort(entries.begin(), entries.begin() + kMaxEntries, | 168 std::partial_sort(entries.begin(), entries.begin() + kMaxEntries, |
| 163 entries.end(), CompareEntries); | 169 entries.end(), CompareEntries); |
| 164 entries.resize(kMaxEntries); | 170 entries.resize(kMaxEntries); |
| 165 } else { | 171 } else { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 | 207 |
| 202 void ReadingListSuggestionsProvider::NotifyStatusChanged( | 208 void ReadingListSuggestionsProvider::NotifyStatusChanged( |
| 203 CategoryStatus new_status) { | 209 CategoryStatus new_status) { |
| 204 if (category_status_ == new_status) { | 210 if (category_status_ == new_status) { |
| 205 return; | 211 return; |
| 206 } | 212 } |
| 207 category_status_ = new_status; | 213 category_status_ = new_status; |
| 208 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); | 214 observer()->OnCategoryStatusChanged(this, provided_category_, new_status); |
| 209 } | 215 } |
| 210 | 216 |
| 217 void ReadingListSuggestionsProvider::SetDismissedState(const GURL& url, | |
| 218 bool dismissed) { | |
| 219 reading_list::ContentSuggestionsExtra extra; | |
| 220 extra.dismissed = dismissed; | |
| 221 reading_list_model_->SetContentSuggestionsExtra(url, extra); | |
|
Marc Treib
2017/04/11 12:35:15
Is the ContentSuggestionsExtra stuff actually impl
gambard
2017/04/11 13:29:53
It is the depend CL :)
Marc Treib
2017/04/11 13:41:08
Aah, missed that. Thanks!
| |
| 222 } | |
| 223 | |
| 211 } // namespace ntp_snippets | 224 } // namespace ntp_snippets |
| OLD | NEW |