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

Side by Side Diff: components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc

Issue 2260783002: Make GetDismissedSuggestionsForDebugging asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // there. 135 // there.
136 base::ThreadTaskRunnerHandle::Get()->PostTask( 136 base::ThreadTaskRunnerHandle::Get()->PostTask(
137 FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image())); 137 FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image()));
138 } 138 }
139 139
140 void OfflinePageSuggestionsProvider::ClearCachedSuggestionsForDebugging( 140 void OfflinePageSuggestionsProvider::ClearCachedSuggestionsForDebugging(
141 Category category) { 141 Category category) {
142 // Ignored. 142 // Ignored.
143 } 143 }
144 144
145 std::vector<ContentSuggestion> 145 void OfflinePageSuggestionsProvider::GetDismissedSuggestionsForDebugging(
146 OfflinePageSuggestionsProvider::GetDismissedSuggestionsForDebugging( 146 Category category,
147 Category category) { 147 const DismissedSuggestionsCallback& callback) {
148 // TODO(pke): Make GetDismissedSuggestionsForDebugging asynchronous so this 148 offline_page_model_->GetAllPages(
149 // can return proper values. 149 base::Bind(&OfflinePageSuggestionsProvider::
150 std::set<std::string> dismissed_ids = ReadDismissedIDsFromPrefs(category); 150 OnOfflinePagesLoadedForDismissedDebugging,
151 std::vector<ContentSuggestion> suggestions; 151 base::Unretained(this), category, callback));
152 for (const std::string& dismissed_id : dismissed_ids) {
153 ContentSuggestion suggestion(
154 MakeUniqueID(category, dismissed_id),
155 GURL("http://dismissed-offline-page-" + dismissed_id));
156 suggestion.set_title(base::UTF8ToUTF16("Title not available"));
157 suggestions.push_back(std::move(suggestion));
158 }
159 return suggestions;
160 } 152 }
161 153
162 void OfflinePageSuggestionsProvider::ClearDismissedSuggestionsForDebugging( 154 void OfflinePageSuggestionsProvider::ClearDismissedSuggestionsForDebugging(
163 Category category) { 155 Category category) {
164 StoreDismissedIDsToPrefs(category, std::set<std::string>()); 156 StoreDismissedIDsToPrefs(category, std::set<std::string>());
165 FetchOfflinePages(); 157 FetchOfflinePages();
166 } 158 }
167 159
168 void OfflinePageSuggestionsProvider::OfflinePageModelLoaded( 160 void OfflinePageSuggestionsProvider::OfflinePageModelLoaded(
169 OfflinePageModel* model) { 161 OfflinePageModel* model) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (need_recent_tabs && 215 if (need_recent_tabs &&
224 item.client_id.name_space == offline_pages::kLastNNamespace) { 216 item.client_id.name_space == offline_pages::kLastNNamespace) {
225 if (dismissed_recent_tab_ids.count(offline_page_id)) 217 if (dismissed_recent_tab_ids.count(offline_page_id))
226 cleaned_recent_tab_ids.insert(offline_page_id); 218 cleaned_recent_tab_ids.insert(offline_page_id);
227 else 219 else
228 recent_tab_items.push_back(&item); 220 recent_tab_items.push_back(&item);
229 } 221 }
230 222
231 // TODO(pke): Use kDownloadNamespace once the OfflinePageModel uses that. 223 // TODO(pke): Use kDownloadNamespace once the OfflinePageModel uses that.
232 // The current logic is taken from DownloadUIAdapter::IsVisibleInUI. 224 // The current logic is taken from DownloadUIAdapter::IsVisibleInUI.
233 // Note: This is also copied in |OfflinePageDeleted| above. 225 // Note: This is also copied in |OfflinePageDeleted| above and in
226 // |OnOfflinePagesLoadedForDismissedDebugging| below.
Marc Treib 2016/08/19 10:07:51 Maybe time to extract it into a helper function?
Philipp Keck 2016/08/19 12:11:54 I thought about that, also in order to simplify th
234 if (need_downloads && 227 if (need_downloads &&
235 item.client_id.name_space == offline_pages::kAsyncNamespace && 228 item.client_id.name_space == offline_pages::kAsyncNamespace &&
236 base::IsValidGUID(item.client_id.id)) { 229 base::IsValidGUID(item.client_id.id)) {
237 if (dismissed_download_ids.count(offline_page_id)) 230 if (dismissed_download_ids.count(offline_page_id))
238 cleaned_download_ids.insert(offline_page_id); 231 cleaned_download_ids.insert(offline_page_id);
239 else 232 else
240 download_items.push_back(&item); 233 download_items.push_back(&item);
241 } 234 }
242 } 235 }
243 236
(...skipping 11 matching lines...) Expand all
255 } 248 }
256 if (need_downloads) { 249 if (need_downloads) {
257 observer()->OnNewSuggestions( 250 observer()->OnNewSuggestions(
258 this, downloads_category_, 251 this, downloads_category_,
259 GetMostRecentlyVisited(downloads_category_, std::move(download_items))); 252 GetMostRecentlyVisited(downloads_category_, std::move(download_items)));
260 if (cleaned_download_ids.size() != dismissed_download_ids.size()) 253 if (cleaned_download_ids.size() != dismissed_download_ids.size())
261 StoreDismissedIDsToPrefs(downloads_category_, cleaned_download_ids); 254 StoreDismissedIDsToPrefs(downloads_category_, cleaned_download_ids);
262 } 255 }
263 } 256 }
264 257
258 void OfflinePageSuggestionsProvider::OnOfflinePagesLoadedForDismissedDebugging(
259 Category category,
260 const DismissedSuggestionsCallback& callback,
261 const offline_pages::MultipleOfflinePageItemResult& result) {
262 std::set<std::string> dismissed_ids = ReadDismissedIDsFromPrefs(category);
263
264 std::vector<ContentSuggestion> suggestions;
265 for (const OfflinePageItem& item : result) {
266 if ((category == recent_tabs_category_ &&
267 item.client_id.name_space == offline_pages::kLastNNamespace) ||
268 (category == downloads_category_ &&
269 item.client_id.name_space == offline_pages::kAsyncNamespace &&
270 base::IsValidGUID(item.client_id.id))) {
271 if (dismissed_ids.count(base::IntToString(item.offline_id))) {
272 suggestions.push_back(ConvertOfflinePage(category, item));
273 }
274 }
275 }
276 return callback.Run(category, std::move(suggestions));
Marc Treib 2016/08/19 10:07:51 No "return"
Philipp Keck 2016/08/19 12:11:54 Done.
277 }
278
265 void OfflinePageSuggestionsProvider::NotifyStatusChanged( 279 void OfflinePageSuggestionsProvider::NotifyStatusChanged(
266 Category category, 280 Category category,
267 CategoryStatus new_status) { 281 CategoryStatus new_status) {
268 if (category == recent_tabs_category_) { 282 if (category == recent_tabs_category_) {
269 DCHECK_NE(CategoryStatus::NOT_PROVIDED, recent_tabs_status_); 283 DCHECK_NE(CategoryStatus::NOT_PROVIDED, recent_tabs_status_);
270 if (recent_tabs_status_ == new_status) 284 if (recent_tabs_status_ == new_status)
271 return; 285 return;
272 recent_tabs_status_ = new_status; 286 recent_tabs_status_ = new_status;
273 observer()->OnCategoryStatusChanged(this, category, new_status); 287 observer()->OnCategoryStatusChanged(this, category, new_status);
274 } else if (category == downloads_category_) { 288 } else if (category == downloads_category_) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( 375 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs(
362 Category category, 376 Category category,
363 const std::set<std::string>& dismissed_ids) { 377 const std::set<std::string>& dismissed_ids) {
364 base::ListValue list; 378 base::ListValue list;
365 for (const std::string& dismissed_id : dismissed_ids) 379 for (const std::string& dismissed_id : dismissed_ids)
366 list.AppendString(dismissed_id); 380 list.AppendString(dismissed_id);
367 pref_service_->Set(GetDismissedPref(category), list); 381 pref_service_->Set(GetDismissedPref(category), list);
368 } 382 }
369 383
370 } // namespace ntp_snippets 384 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698