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

Side by Side Diff: chrome/browser/ui/webui/snippets_internals_message_handler.cc

Issue 2568033005: [NTP::SectionOrder] Replace CategoryFactory with a category ranker. (Closed)
Patch Set: download provider tests. Created 4 years 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 "chrome/browser/ui/webui/snippets_internals_message_handler.h" 5 #include "chrome/browser/ui/webui/snippets_internals_message_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/feature_list.h" 15 #include "base/feature_list.h"
16 #include "base/i18n/time_formatting.h" 16 #include "base/i18n/time_formatting.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/optional.h" 19 #include "base/optional.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_split.h" 21 #include "base/strings/string_split.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" 24 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/common/chrome_features.h" 26 #include "chrome/common/chrome_features.h"
27 #include "components/ntp_snippets/category.h"
27 #include "components/ntp_snippets/category_info.h" 28 #include "components/ntp_snippets/category_info.h"
28 #include "components/ntp_snippets/features.h" 29 #include "components/ntp_snippets/features.h"
29 #include "components/ntp_snippets/pref_names.h" 30 #include "components/ntp_snippets/pref_names.h"
30 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" 31 #include "components/ntp_snippets/remote/remote_suggestions_provider.h"
31 #include "components/ntp_snippets/switches.h" 32 #include "components/ntp_snippets/switches.h"
32 #include "components/prefs/pref_service.h" 33 #include "components/prefs/pref_service.h"
33 #include "content/public/browser/web_ui.h" 34 #include "content/public/browser/web_ui.h"
34 35
35 using ntp_snippets::ContentSuggestion; 36 using ntp_snippets::ContentSuggestion;
36 using ntp_snippets::Category; 37 using ntp_snippets::Category;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 210 }
210 211
211 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions( 212 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions(
212 const base::ListValue* args) { 213 const base::ListValue* args) {
213 DCHECK_EQ(1u, args->GetSize()); 214 DCHECK_EQ(1u, args->GetSize());
214 215
215 int category_id; 216 int category_id;
216 if (!args->GetInteger(0, &category_id)) 217 if (!args->GetInteger(0, &category_id))
217 return; 218 return;
218 219
219 Category category = 220 content_suggestions_service_->ClearCachedSuggestions(
220 content_suggestions_service_->category_factory()->FromIDValue( 221 Category::FromIDValue(category_id));
221 category_id);
222 content_suggestions_service_->ClearCachedSuggestions(category);
223 SendContentSuggestions(); 222 SendContentSuggestions();
224 } 223 }
225 224
226 void SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions( 225 void SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions(
227 const base::ListValue* args) { 226 const base::ListValue* args) {
228 DCHECK_EQ(1u, args->GetSize()); 227 DCHECK_EQ(1u, args->GetSize());
229 228
230 int category_id; 229 int category_id;
231 if (!args->GetInteger(0, &category_id)) 230 if (!args->GetInteger(0, &category_id))
232 return; 231 return;
233 232
234 Category category = 233 Category category = Category::FromIDValue(category_id);
235 content_suggestions_service_->category_factory()->FromIDValue(
236 category_id);
237 content_suggestions_service_->ClearDismissedSuggestionsForDebugging(category); 234 content_suggestions_service_->ClearDismissedSuggestionsForDebugging(category);
238 SendContentSuggestions(); 235 SendContentSuggestions();
239 dismissed_state_[category] = DismissedState::LOADING; 236 dismissed_state_[category] = DismissedState::LOADING;
240 content_suggestions_service_->GetDismissedSuggestionsForDebugging( 237 content_suggestions_service_->GetDismissedSuggestionsForDebugging(
241 category, 238 category,
242 base::Bind(&SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, 239 base::Bind(&SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded,
243 weak_ptr_factory_.GetWeakPtr(), category)); 240 weak_ptr_factory_.GetWeakPtr(), category));
244 } 241 }
245 242
246 void SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions( 243 void SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions(
247 const base::ListValue* args) { 244 const base::ListValue* args) {
248 DCHECK_EQ(2u, args->GetSize()); 245 DCHECK_EQ(2u, args->GetSize());
249 246
250 int category_id; 247 int category_id;
251 if (!args->GetInteger(0, &category_id)) 248 if (!args->GetInteger(0, &category_id))
252 return; 249 return;
253 bool dismissed_visible; 250 bool dismissed_visible;
254 if (!args->GetBoolean(1, &dismissed_visible)) 251 if (!args->GetBoolean(1, &dismissed_visible))
255 return; 252 return;
256 253
257 Category category = 254 Category category = Category::FromIDValue(category_id);
258 content_suggestions_service_->category_factory()->FromIDValue(
259 category_id);
260 if (dismissed_visible) { 255 if (dismissed_visible) {
261 dismissed_state_[category] = DismissedState::LOADING; 256 dismissed_state_[category] = DismissedState::LOADING;
262 content_suggestions_service_->GetDismissedSuggestionsForDebugging( 257 content_suggestions_service_->GetDismissedSuggestionsForDebugging(
263 category, 258 category,
264 base::Bind( 259 base::Bind(
265 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, 260 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded,
266 weak_ptr_factory_.GetWeakPtr(), category)); 261 weak_ptr_factory_.GetWeakPtr(), category));
267 } else { 262 } else {
268 dismissed_state_[category] = DismissedState::HIDDEN; 263 dismissed_state_[category] = DismissedState::HIDDEN;
269 dismissed_suggestions_[category].clear(); 264 dismissed_suggestions_[category].clear();
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 424
430 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( 425 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded(
431 Category category, 426 Category category,
432 std::vector<ContentSuggestion> dismissed_suggestions) { 427 std::vector<ContentSuggestion> dismissed_suggestions) {
433 if (dismissed_state_[category] == DismissedState::HIDDEN) 428 if (dismissed_state_[category] == DismissedState::HIDDEN)
434 return; 429 return;
435 dismissed_suggestions_[category] = std::move(dismissed_suggestions); 430 dismissed_suggestions_[category] = std::move(dismissed_suggestions);
436 dismissed_state_[category] = DismissedState::VISIBLE; 431 dismissed_state_[category] = DismissedState::VISIBLE;
437 SendContentSuggestions(); 432 SendContentSuggestions();
438 } 433 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698