Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Unified Diff: components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc

Issue 2244793002: Remove deleted offline page suggestions from opened NTPs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust MockContentSuggestionsProvider Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ntp_snippets/mock_content_suggestions_provider_observer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc
diff --git a/components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc b/components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc
index 0c153735bee2a199a1d5cf08bd9c0b2de1880202..32d003a4ab466ebf7bd8a95ec402f95aa2601c1e 100644
--- a/components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc
+++ b/components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc
@@ -216,7 +216,38 @@ void OfflinePageSuggestionsProvider::OfflinePageModelChanged(
void OfflinePageSuggestionsProvider::OfflinePageDeleted(
int64_t offline_id,
const offline_pages::ClientId& client_id) {
- // TODO(pke): Implement, suggestion has to be removed from UI immediately.
+ // Because we never switch to NOT_PROVIDED dynamically, there can be no open
+ // UI containing an invalidated suggestion unless the status is something
+ // other than NOT_PROVIDED, so only notify invalidation in that case.
+ std::string offline_page_id = base::IntToString(offline_id);
+ if (recent_tabs_status_ != CategoryStatus::NOT_PROVIDED &&
+ client_id.name_space == offline_pages::kLastNNamespace) {
+ auto it = std::find(dismissed_recent_tab_ids_.begin(),
+ dismissed_recent_tab_ids_.end(), offline_page_id);
+ if (it == dismissed_recent_tab_ids_.end()) {
+ observer()->OnSuggestionInvalidated(
+ this, recent_tabs_category_,
+ MakeUniqueID(recent_tabs_category_, offline_page_id));
+ } else {
+ dismissed_recent_tab_ids_.erase(it);
+ StoreDismissedIDsToPrefs(prefs::kDismissedRecentOfflineTabSuggestions,
+ dismissed_recent_tab_ids_);
+ }
+ } else if (downloads_status_ != CategoryStatus::NOT_PROVIDED &&
+ client_id.name_space == offline_pages::kAsyncNamespace &&
+ base::IsValidGUID(client_id.id)) {
+ auto it = std::find(dismissed_download_ids_.begin(),
+ dismissed_download_ids_.end(), offline_page_id);
+ if (it == dismissed_download_ids_.end()) {
+ observer()->OnSuggestionInvalidated(
+ this, downloads_category_,
+ MakeUniqueID(downloads_category_, offline_page_id));
+ } else {
+ dismissed_download_ids_.erase(it);
+ StoreDismissedIDsToPrefs(prefs::kDismissedDownloadSuggestions,
+ dismissed_download_ids_);
+ }
+ }
}
void OfflinePageSuggestionsProvider::FetchOfflinePages() {
@@ -245,6 +276,7 @@ void OfflinePageSuggestionsProvider::OnOfflinePagesLoaded(
// TODO(pke): Use kDownloadNamespace once the OfflinePageModel uses that.
// The current logic is taken from DownloadUIAdapter::IsVisibleInUI.
+ // Note: This is also copied in OfflinePageDeleted above.
if (need_downloads &&
item.client_id.name_space == offline_pages::kAsyncNamespace &&
base::IsValidGUID(item.client_id.id) &&
« no previous file with comments | « components/ntp_snippets/mock_content_suggestions_provider_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698