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

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

Issue 2223073002: Add per-section clearing and dismissed suggestions to snippets-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix non-Debug builds 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::ClearCachedSuggestionsForDebugging() { 82 void ContentSuggestionsService::ClearAllCachedSuggestionsForDebugging() {
83 suggestions_by_category_.clear(); 83 suggestions_by_category_.clear();
84 id_category_map_.clear(); 84 id_category_map_.clear();
85 for (auto& category_provider_pair : providers_by_category_) { 85 for (const auto& category_provider_pair : providers_by_category_) {
86 category_provider_pair.second->ClearCachedSuggestionsForDebugging(); 86 category_provider_pair.second->ClearCachedSuggestionsForDebugging(
87 category_provider_pair.first);
87 } 88 }
88 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions()); 89 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions());
89 } 90 }
90 91
91 void ContentSuggestionsService::ClearDismissedSuggestionsForDebugging() { 92 void ContentSuggestionsService::ClearCachedSuggestionsForDebugging(
92 for (auto& category_provider_pair : providers_by_category_) { 93 Category category) {
93 category_provider_pair.second->ClearDismissedSuggestionsForDebugging(); 94 for (const ContentSuggestion& suggestion :
95 suggestions_by_category_[category]) {
96 id_category_map_.erase(suggestion.id());
94 } 97 }
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);
95 } 118 }
96 119
97 void ContentSuggestionsService::DismissSuggestion( 120 void ContentSuggestionsService::DismissSuggestion(
98 const std::string& suggestion_id) { 121 const std::string& suggestion_id) {
99 if (!id_category_map_.count(suggestion_id)) { 122 if (!id_category_map_.count(suggestion_id)) {
100 LOG(WARNING) << "Dismissed unknown suggestion " << suggestion_id; 123 LOG(WARNING) << "Dismissed unknown suggestion " << suggestion_id;
101 return; 124 return;
102 } 125 }
103 Category category = id_category_map_.at(suggestion_id); 126 Category category = id_category_map_.at(suggestion_id);
104 if (!providers_by_category_.count(category)) { 127 if (!providers_by_category_.count(category)) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return true; 239 return true;
217 } 240 }
218 241
219 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { 242 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) {
220 FOR_EACH_OBSERVER( 243 FOR_EACH_OBSERVER(
221 Observer, observers_, 244 Observer, observers_,
222 OnCategoryStatusChanged(category, GetCategoryStatus(category))); 245 OnCategoryStatusChanged(category, GetCategoryStatus(category)));
223 } 246 }
224 247
225 } // namespace ntp_snippets 248 } // 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