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

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

Issue 2225753003: Revert of Add per-section clearing and dismissed suggestions to snippets-internals (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/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"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 LOG(WARNING) << "Requested image for suggestion " << suggestion_id 72 LOG(WARNING) << "Requested image for suggestion " << suggestion_id
73 << " for unavailable category " << category; 73 << " for unavailable category " << category;
74 base::ThreadTaskRunnerHandle::Get()->PostTask( 74 base::ThreadTaskRunnerHandle::Get()->PostTask(
75 FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image())); 75 FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image()));
76 return; 76 return;
77 } 77 }
78 providers_by_category_[category]->FetchSuggestionImage(suggestion_id, 78 providers_by_category_[category]->FetchSuggestionImage(suggestion_id,
79 callback); 79 callback);
80 } 80 }
81 81
82 void ContentSuggestionsService::ClearAllCachedSuggestionsForDebugging() { 82 void ContentSuggestionsService::ClearCachedSuggestionsForDebugging() {
83 suggestions_by_category_.clear(); 83 suggestions_by_category_.clear();
84 id_category_map_.clear(); 84 id_category_map_.clear();
85 for (const auto& category_provider_pair : providers_by_category_) { 85 for (auto& category_provider_pair : providers_by_category_) {
86 category_provider_pair.second->ClearCachedSuggestionsForDebugging( 86 category_provider_pair.second->ClearCachedSuggestionsForDebugging();
87 category_provider_pair.first);
88 } 87 }
89 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions()); 88 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions());
90 } 89 }
91 90
92 void ContentSuggestionsService::ClearCachedSuggestionsForDebugging( 91 void ContentSuggestionsService::ClearDismissedSuggestionsForDebugging() {
93 Category category) { 92 for (auto& category_provider_pair : providers_by_category_) {
94 for (const ContentSuggestion& suggestion : 93 category_provider_pair.second->ClearDismissedSuggestionsForDebugging();
95 suggestions_by_category_[category]) {
96 id_category_map_.erase(suggestion.id());
97 } 94 }
98 suggestions_by_category_[category].clear();
99 auto iterator = providers_by_category_.find(category);
100 if (iterator != providers_by_category_.end())
101 iterator->second->ClearCachedSuggestionsForDebugging(category);
102 }
103
104 std::vector<ContentSuggestion>
105 ContentSuggestionsService::GetDismissedSuggestionsForDebugging(
106 Category category) {
107 auto iterator = providers_by_category_.find(category);
108 if (iterator == providers_by_category_.end())
109 return std::vector<ContentSuggestion>();
110 return iterator->second->GetDismissedSuggestionsForDebugging(category);
111 }
112
113 void ContentSuggestionsService::ClearDismissedSuggestionsForDebugging(
114 Category category) {
115 auto iterator = providers_by_category_.find(category);
116 if (iterator != providers_by_category_.end())
117 iterator->second->ClearDismissedSuggestionsForDebugging(category);
118 } 95 }
119 96
120 void ContentSuggestionsService::DismissSuggestion( 97 void ContentSuggestionsService::DismissSuggestion(
121 const std::string& suggestion_id) { 98 const std::string& suggestion_id) {
122 if (!id_category_map_.count(suggestion_id)) { 99 if (!id_category_map_.count(suggestion_id)) {
123 LOG(WARNING) << "Dismissed unknown suggestion " << suggestion_id; 100 LOG(WARNING) << "Dismissed unknown suggestion " << suggestion_id;
124 return; 101 return;
125 } 102 }
126 Category category = id_category_map_.at(suggestion_id); 103 Category category = id_category_map_.at(suggestion_id);
127 if (!providers_by_category_.count(category)) { 104 if (!providers_by_category_.count(category)) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return true; 216 return true;
240 } 217 }
241 218
242 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { 219 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) {
243 FOR_EACH_OBSERVER( 220 FOR_EACH_OBSERVER(
244 Observer, observers_, 221 Observer, observers_,
245 OnCategoryStatusChanged(category, GetCategoryStatus(category))); 222 OnCategoryStatusChanged(category, GetCategoryStatus(category)));
246 } 223 }
247 224
248 } // namespace ntp_snippets 225 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/content_suggestions_service.h ('k') | components/ntp_snippets/content_suggestions_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698