| 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> |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, | 175 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, |
| 176 weak_ptr_factory_.GetWeakPtr(), category_state_pair.first)); | 176 weak_ptr_factory_.GetWeakPtr(), category_state_pair.first)); |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 SendAllContent(); | 180 SendAllContent(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void SnippetsInternalsMessageHandler::HandleDownload( | 183 void SnippetsInternalsMessageHandler::HandleDownload( |
| 184 const base::ListValue* args) { | 184 const base::ListValue* args) { |
| 185 DCHECK_EQ(1u, args->GetSize()); | 185 DCHECK_EQ(0u, args->GetSize()); |
| 186 | 186 |
| 187 SendString("hosts-status", std::string()); | 187 SendString("remote-status", std::string()); |
| 188 | 188 |
| 189 if (!ntp_snippets_service_) | 189 if (!ntp_snippets_service_) |
| 190 return; | 190 return; |
| 191 | 191 |
| 192 std::string hosts_string; | 192 ntp_snippets_service_->FetchSnippetsForAllCategories(); |
| 193 if (!args->GetString(0, &hosts_string)) | |
| 194 return; | |
| 195 | |
| 196 std::vector<std::string> hosts_vector = base::SplitString( | |
| 197 hosts_string, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
| 198 std::set<std::string> hosts(hosts_vector.begin(), hosts_vector.end()); | |
| 199 | |
| 200 ntp_snippets_service_->FetchSnippetsFromHosts(hosts, | |
| 201 /*interactive_request=*/true); | |
| 202 } | 193 } |
| 203 | 194 |
| 204 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions( | 195 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions( |
| 205 const base::ListValue* args) { | 196 const base::ListValue* args) { |
| 206 DCHECK_EQ(1u, args->GetSize()); | 197 DCHECK_EQ(1u, args->GetSize()); |
| 207 | 198 |
| 208 int category_id; | 199 int category_id; |
| 209 if (!args->GetInteger(0, &category_id)) | 200 if (!args->GetInteger(0, &category_id)) |
| 210 return; | 201 return; |
| 211 | 202 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 category_entry->SetString("status", GetCategoryStatusName(status)); | 362 category_entry->SetString("status", GetCategoryStatusName(status)); |
| 372 category_entry->Set("suggestions", std::move(suggestions_list)); | 363 category_entry->Set("suggestions", std::move(suggestions_list)); |
| 373 category_entry->Set("dismissedSuggestions", std::move(dismissed_list)); | 364 category_entry->Set("dismissedSuggestions", std::move(dismissed_list)); |
| 374 categories_list->Append(std::move(category_entry)); | 365 categories_list->Append(std::move(category_entry)); |
| 375 } | 366 } |
| 376 | 367 |
| 377 if (ntp_snippets_service_) { | 368 if (ntp_snippets_service_) { |
| 378 const std::string& status = | 369 const std::string& status = |
| 379 ntp_snippets_service_->snippets_fetcher()->last_status(); | 370 ntp_snippets_service_->snippets_fetcher()->last_status(); |
| 380 if (!status.empty()) | 371 if (!status.empty()) |
| 381 SendString("hosts-status", "Finished: " + status); | 372 SendString("remote-status", "Finished: " + status); |
| 382 } | 373 } |
| 383 | 374 |
| 384 base::DictionaryValue result; | 375 base::DictionaryValue result; |
| 385 result.Set("list", std::move(categories_list)); | 376 result.Set("list", std::move(categories_list)); |
| 386 web_ui()->CallJavascriptFunctionUnsafe( | 377 web_ui()->CallJavascriptFunctionUnsafe( |
| 387 "chrome.SnippetsInternals.receiveContentSuggestions", result); | 378 "chrome.SnippetsInternals.receiveContentSuggestions", result); |
| 388 } | 379 } |
| 389 | 380 |
| 390 void SnippetsInternalsMessageHandler::SendBoolean(const std::string& name, | 381 void SnippetsInternalsMessageHandler::SendBoolean(const std::string& name, |
| 391 bool value) { | 382 bool value) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 403 | 394 |
| 404 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( | 395 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( |
| 405 Category category, | 396 Category category, |
| 406 std::vector<ContentSuggestion> dismissed_suggestions) { | 397 std::vector<ContentSuggestion> dismissed_suggestions) { |
| 407 if (dismissed_state_[category] == DismissedState::HIDDEN) | 398 if (dismissed_state_[category] == DismissedState::HIDDEN) |
| 408 return; | 399 return; |
| 409 dismissed_suggestions_[category] = std::move(dismissed_suggestions); | 400 dismissed_suggestions_[category] = std::move(dismissed_suggestions); |
| 410 dismissed_state_[category] = DismissedState::VISIBLE; | 401 dismissed_state_[category] = DismissedState::VISIBLE; |
| 411 SendContentSuggestions(); | 402 SendContentSuggestions(); |
| 412 } | 403 } |
| OLD | NEW |