OLD | NEW |
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 200 } |
200 | 201 |
201 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions( | 202 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions( |
202 const base::ListValue* args) { | 203 const base::ListValue* args) { |
203 DCHECK_EQ(1u, args->GetSize()); | 204 DCHECK_EQ(1u, args->GetSize()); |
204 | 205 |
205 int category_id; | 206 int category_id; |
206 if (!args->GetInteger(0, &category_id)) | 207 if (!args->GetInteger(0, &category_id)) |
207 return; | 208 return; |
208 | 209 |
209 Category category = | 210 content_suggestions_service_->ClearCachedSuggestions( |
210 content_suggestions_service_->category_factory()->FromIDValue( | 211 Category::FromIDValue(category_id)); |
211 category_id); | |
212 content_suggestions_service_->ClearCachedSuggestions(category); | |
213 SendContentSuggestions(); | 212 SendContentSuggestions(); |
214 } | 213 } |
215 | 214 |
216 void SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions( | 215 void SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions( |
217 const base::ListValue* args) { | 216 const base::ListValue* args) { |
218 DCHECK_EQ(1u, args->GetSize()); | 217 DCHECK_EQ(1u, args->GetSize()); |
219 | 218 |
220 int category_id; | 219 int category_id; |
221 if (!args->GetInteger(0, &category_id)) | 220 if (!args->GetInteger(0, &category_id)) |
222 return; | 221 return; |
223 | 222 |
224 Category category = | 223 Category category = Category::FromIDValue(category_id); |
225 content_suggestions_service_->category_factory()->FromIDValue( | |
226 category_id); | |
227 content_suggestions_service_->ClearDismissedSuggestionsForDebugging(category); | 224 content_suggestions_service_->ClearDismissedSuggestionsForDebugging(category); |
228 SendContentSuggestions(); | 225 SendContentSuggestions(); |
229 dismissed_state_[category] = DismissedState::LOADING; | 226 dismissed_state_[category] = DismissedState::LOADING; |
230 content_suggestions_service_->GetDismissedSuggestionsForDebugging( | 227 content_suggestions_service_->GetDismissedSuggestionsForDebugging( |
231 category, | 228 category, |
232 base::Bind(&SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, | 229 base::Bind(&SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, |
233 weak_ptr_factory_.GetWeakPtr(), category)); | 230 weak_ptr_factory_.GetWeakPtr(), category)); |
234 } | 231 } |
235 | 232 |
236 void SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions( | 233 void SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions( |
237 const base::ListValue* args) { | 234 const base::ListValue* args) { |
238 DCHECK_EQ(2u, args->GetSize()); | 235 DCHECK_EQ(2u, args->GetSize()); |
239 | 236 |
240 int category_id; | 237 int category_id; |
241 if (!args->GetInteger(0, &category_id)) | 238 if (!args->GetInteger(0, &category_id)) |
242 return; | 239 return; |
243 bool dismissed_visible; | 240 bool dismissed_visible; |
244 if (!args->GetBoolean(1, &dismissed_visible)) | 241 if (!args->GetBoolean(1, &dismissed_visible)) |
245 return; | 242 return; |
246 | 243 |
247 Category category = | 244 Category category = Category::FromIDValue(category_id); |
248 content_suggestions_service_->category_factory()->FromIDValue( | |
249 category_id); | |
250 if (dismissed_visible) { | 245 if (dismissed_visible) { |
251 dismissed_state_[category] = DismissedState::LOADING; | 246 dismissed_state_[category] = DismissedState::LOADING; |
252 content_suggestions_service_->GetDismissedSuggestionsForDebugging( | 247 content_suggestions_service_->GetDismissedSuggestionsForDebugging( |
253 category, | 248 category, |
254 base::Bind( | 249 base::Bind( |
255 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, | 250 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, |
256 weak_ptr_factory_.GetWeakPtr(), category)); | 251 weak_ptr_factory_.GetWeakPtr(), category)); |
257 } else { | 252 } else { |
258 dismissed_state_[category] = DismissedState::HIDDEN; | 253 dismissed_state_[category] = DismissedState::HIDDEN; |
259 dismissed_suggestions_[category].clear(); | 254 dismissed_suggestions_[category].clear(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 414 |
420 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( | 415 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( |
421 Category category, | 416 Category category, |
422 std::vector<ContentSuggestion> dismissed_suggestions) { | 417 std::vector<ContentSuggestion> dismissed_suggestions) { |
423 if (dismissed_state_[category] == DismissedState::HIDDEN) | 418 if (dismissed_state_[category] == DismissedState::HIDDEN) |
424 return; | 419 return; |
425 dismissed_suggestions_[category] = std::move(dismissed_suggestions); | 420 dismissed_suggestions_[category] = std::move(dismissed_suggestions); |
426 dismissed_state_[category] = DismissedState::VISIBLE; | 421 dismissed_state_[category] = DismissedState::VISIBLE; |
427 SendContentSuggestions(); | 422 SendContentSuggestions(); |
428 } | 423 } |
OLD | NEW |