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

Side by Side Diff: components/ntp_snippets/content_suggestions_service.cc

Issue 2292003002: Move OnURLsDeleted from NTPSnippetsService to ContentSuggestionsService (Closed)
Patch Set: Created 4 years, 3 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/content_suggestions_service.h" 5 #include "components/ntp_snippets/content_suggestions_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "ui/gfx/image/image.h" 14 #include "ui/gfx/image/image.h"
15 15
16 namespace ntp_snippets { 16 namespace ntp_snippets {
17 17
18 ContentSuggestionsService::ContentSuggestionsService(State state) 18 ContentSuggestionsService::ContentSuggestionsService(
19 : state_(state) {} 19 State state,
20 history::HistoryService* history_service)
21 : state_(state), history_service_observer_(this) {
22 // Can be null in tests.
23 if (history_service)
24 history_service_observer_.Add(history_service);
25 }
20 26
21 ContentSuggestionsService::~ContentSuggestionsService() {} 27 ContentSuggestionsService::~ContentSuggestionsService() {}
22 28
23 void ContentSuggestionsService::Shutdown() { 29 void ContentSuggestionsService::Shutdown() {
24 ntp_snippets_service_ = nullptr; 30 ntp_snippets_service_ = nullptr;
25 id_category_map_.clear(); 31 id_category_map_.clear();
26 suggestions_by_category_.clear(); 32 suggestions_by_category_.clear();
27 providers_by_category_.clear(); 33 providers_by_category_.clear();
28 categories_.clear(); 34 categories_.clear();
29 providers_.clear(); 35 providers_.clear();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 229
224 void ContentSuggestionsService::OnSuggestionInvalidated( 230 void ContentSuggestionsService::OnSuggestionInvalidated(
225 ContentSuggestionsProvider* provider, 231 ContentSuggestionsProvider* provider,
226 Category category, 232 Category category,
227 const std::string& suggestion_id) { 233 const std::string& suggestion_id) {
228 RemoveSuggestionByID(category, suggestion_id); 234 RemoveSuggestionByID(category, suggestion_id);
229 FOR_EACH_OBSERVER(Observer, observers_, 235 FOR_EACH_OBSERVER(Observer, observers_,
230 OnSuggestionInvalidated(category, suggestion_id)); 236 OnSuggestionInvalidated(category, suggestion_id));
231 } 237 }
232 238
239 // history::HistoryServiceObserver implementation.
240 void ContentSuggestionsService::OnURLsDeleted(
241 history::HistoryService* history_service,
242 bool all_history,
243 bool expired,
244 const history::URLRows& deleted_rows,
245 const std::set<GURL>& favicon_urls) {
246 if (expired)
Marc Treib 2016/09/02 12:57:10 Add a comment, like we had in NTPSnippetsService?
vitaliii 2016/09/02 14:13:17 Done.
247 return;
248
249 std::vector<GURL> deleted_urls;
250 for (const history::URLRow& row : deleted_rows) {
251 deleted_urls.emplace_back(row.url());
Marc Treib 2016/09/02 12:57:10 nit: push_back, since it has to make a copy anyway
vitaliii 2016/09/02 14:13:17 Acknowledged.
252 }
253 for (const auto& provider : providers_) {
254 provider->RemoveURLsFromHistory(all_history, deleted_urls);
255 }
256 }
257
258 void ContentSuggestionsService::HistoryServiceBeingDeleted(
259 history::HistoryService* history_service) {
260 history_service_observer_.RemoveAll();
261 }
262
233 bool ContentSuggestionsService::RegisterCategoryIfRequired( 263 bool ContentSuggestionsService::RegisterCategoryIfRequired(
234 ContentSuggestionsProvider* provider, 264 ContentSuggestionsProvider* provider,
235 Category category) { 265 Category category) {
236 auto it = providers_by_category_.find(category); 266 auto it = providers_by_category_.find(category);
237 if (it != providers_by_category_.end()) { 267 if (it != providers_by_category_.end()) {
238 DCHECK_EQ(it->second, provider); 268 DCHECK_EQ(it->second, provider);
239 return false; 269 return false;
240 } 270 }
241 271
242 providers_by_category_[category] = provider; 272 providers_by_category_[category] = provider;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (left.IsKnownCategory(KnownCategories::BOOKMARKS)) 322 if (left.IsKnownCategory(KnownCategories::BOOKMARKS))
293 return false; 323 return false;
294 if (right.IsKnownCategory(KnownCategories::BOOKMARKS)) 324 if (right.IsKnownCategory(KnownCategories::BOOKMARKS))
295 return true; 325 return true;
296 } 326 }
297 return category_factory_.CompareCategories(left, right); 327 return category_factory_.CompareCategories(left, right);
298 }); 328 });
299 } 329 }
300 330
301 } // namespace ntp_snippets 331 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698