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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/offline_pages/offline_page_suggestions_provide r.h" 5 #include "components/ntp_snippets/offline_pages/offline_page_suggestions_provide r.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 void OfflinePageSuggestionsProvider::OfflinePageModelChanged( 210 void OfflinePageSuggestionsProvider::OfflinePageModelChanged(
211 OfflinePageModel* model) { 211 OfflinePageModel* model) {
212 DCHECK_EQ(offline_page_model_, model); 212 DCHECK_EQ(offline_page_model_, model);
213 FetchOfflinePages(); 213 FetchOfflinePages();
214 } 214 }
215 215
216 void OfflinePageSuggestionsProvider::OfflinePageDeleted( 216 void OfflinePageSuggestionsProvider::OfflinePageDeleted(
217 int64_t offline_id, 217 int64_t offline_id,
218 const offline_pages::ClientId& client_id) { 218 const offline_pages::ClientId& client_id) {
219 // TODO(pke): Implement, suggestion has to be removed from UI immediately. 219 // Because we never switch to NOT_PROVIDED dynamically, there can be no open
220 // UI containing an invalidated suggestion unless the status is something
221 // other than NOT_PROVIDED, so only notify invalidation in that case.
222 std::string offline_page_id = base::IntToString(offline_id);
223 if (recent_tabs_status_ != CategoryStatus::NOT_PROVIDED &&
224 client_id.name_space == offline_pages::kLastNNamespace) {
225 auto it = std::find(dismissed_recent_tab_ids_.begin(),
226 dismissed_recent_tab_ids_.end(), offline_page_id);
227 if (it == dismissed_recent_tab_ids_.end()) {
228 observer()->OnSuggestionInvalidated(
229 this, recent_tabs_category_,
230 MakeUniqueID(recent_tabs_category_, offline_page_id));
231 } else {
232 dismissed_recent_tab_ids_.erase(it);
233 StoreDismissedIDsToPrefs(prefs::kDismissedRecentOfflineTabSuggestions,
234 dismissed_recent_tab_ids_);
235 }
236 } else if (downloads_status_ != CategoryStatus::NOT_PROVIDED &&
237 client_id.name_space == offline_pages::kAsyncNamespace &&
238 base::IsValidGUID(client_id.id)) {
239 auto it = std::find(dismissed_download_ids_.begin(),
240 dismissed_download_ids_.end(), offline_page_id);
241 if (it == dismissed_download_ids_.end()) {
242 observer()->OnSuggestionInvalidated(
243 this, downloads_category_,
244 MakeUniqueID(downloads_category_, offline_page_id));
245 } else {
246 dismissed_download_ids_.erase(it);
247 StoreDismissedIDsToPrefs(prefs::kDismissedDownloadSuggestions,
248 dismissed_download_ids_);
249 }
250 }
220 } 251 }
221 252
222 void OfflinePageSuggestionsProvider::FetchOfflinePages() { 253 void OfflinePageSuggestionsProvider::FetchOfflinePages() {
223 offline_page_model_->GetAllPages( 254 offline_page_model_->GetAllPages(
224 base::Bind(&OfflinePageSuggestionsProvider::OnOfflinePagesLoaded, 255 base::Bind(&OfflinePageSuggestionsProvider::OnOfflinePagesLoaded,
225 base::Unretained(this))); 256 base::Unretained(this)));
226 } 257 }
227 258
228 void OfflinePageSuggestionsProvider::OnOfflinePagesLoaded( 259 void OfflinePageSuggestionsProvider::OnOfflinePagesLoaded(
229 const MultipleOfflinePageItemResult& result) { 260 const MultipleOfflinePageItemResult& result) {
230 bool need_recent_tabs = recent_tabs_status_ != CategoryStatus::NOT_PROVIDED; 261 bool need_recent_tabs = recent_tabs_status_ != CategoryStatus::NOT_PROVIDED;
231 bool need_downloads = downloads_status_ != CategoryStatus::NOT_PROVIDED; 262 bool need_downloads = downloads_status_ != CategoryStatus::NOT_PROVIDED;
232 if (need_recent_tabs) 263 if (need_recent_tabs)
233 NotifyStatusChanged(recent_tabs_category_, CategoryStatus::AVAILABLE); 264 NotifyStatusChanged(recent_tabs_category_, CategoryStatus::AVAILABLE);
234 if (need_downloads) 265 if (need_downloads)
235 NotifyStatusChanged(downloads_category_, CategoryStatus::AVAILABLE); 266 NotifyStatusChanged(downloads_category_, CategoryStatus::AVAILABLE);
236 267
237 std::vector<const OfflinePageItem*> recent_tab_items; 268 std::vector<const OfflinePageItem*> recent_tab_items;
238 std::vector<const OfflinePageItem*> download_items; 269 std::vector<const OfflinePageItem*> download_items;
239 for (const OfflinePageItem& item : result) { 270 for (const OfflinePageItem& item : result) {
240 if (need_recent_tabs && 271 if (need_recent_tabs &&
241 item.client_id.name_space == offline_pages::kLastNNamespace && 272 item.client_id.name_space == offline_pages::kLastNNamespace &&
242 !dismissed_recent_tab_ids_.count(base::IntToString(item.offline_id))) { 273 !dismissed_recent_tab_ids_.count(base::IntToString(item.offline_id))) {
243 recent_tab_items.push_back(&item); 274 recent_tab_items.push_back(&item);
244 } 275 }
245 276
246 // TODO(pke): Use kDownloadNamespace once the OfflinePageModel uses that. 277 // TODO(pke): Use kDownloadNamespace once the OfflinePageModel uses that.
247 // The current logic is taken from DownloadUIAdapter::IsVisibleInUI. 278 // The current logic is taken from DownloadUIAdapter::IsVisibleInUI.
279 // Note: This is also copied in OfflinePageDeleted above.
248 if (need_downloads && 280 if (need_downloads &&
249 item.client_id.name_space == offline_pages::kAsyncNamespace && 281 item.client_id.name_space == offline_pages::kAsyncNamespace &&
250 base::IsValidGUID(item.client_id.id) && 282 base::IsValidGUID(item.client_id.id) &&
251 !dismissed_download_ids_.count(base::IntToString(item.offline_id))) { 283 !dismissed_download_ids_.count(base::IntToString(item.offline_id))) {
252 download_items.push_back(&item); 284 download_items.push_back(&item);
253 } 285 }
254 } 286 }
255 287
256 // TODO(pke): Once we have our OfflinePageModel getter and that doesn't do it 288 // TODO(pke): Once we have our OfflinePageModel getter and that doesn't do it
257 // already, filter out duplicate URLs for recent tabs here. Duplicates for 289 // already, filter out duplicate URLs for recent tabs here. Duplicates for
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( 375 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs(
344 const std::string& pref_name, 376 const std::string& pref_name,
345 const std::set<std::string>& dismissed_ids) { 377 const std::set<std::string>& dismissed_ids) {
346 base::ListValue list; 378 base::ListValue list;
347 for (const std::string& dismissed_id : dismissed_ids) 379 for (const std::string& dismissed_id : dismissed_ids)
348 list.AppendString(dismissed_id); 380 list.AppendString(dismissed_id);
349 pref_service_->Set(pref_name, list); 381 pref_service_->Set(pref_name, list);
350 } 382 }
351 383
352 } // namespace ntp_snippets 384 } // namespace ntp_snippets
OLDNEW
« 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