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

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

Issue 2570673004: Remove host restrictions from snippets (Closed)
Patch Set: rebase 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>
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded, 181 &SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded,
182 weak_ptr_factory_.GetWeakPtr(), category_state_pair.first)); 182 weak_ptr_factory_.GetWeakPtr(), category_state_pair.first));
183 } 183 }
184 } 184 }
185 185
186 SendAllContent(); 186 SendAllContent();
187 } 187 }
188 188
189 void SnippetsInternalsMessageHandler::HandleDownload( 189 void SnippetsInternalsMessageHandler::HandleDownload(
190 const base::ListValue* args) { 190 const base::ListValue* args) {
191 DCHECK_EQ(1u, args->GetSize()); 191 DCHECK_EQ(0u, args->GetSize());
192 192
193 SendString("hosts-status", std::string()); 193 SendString("remote-status", std::string());
194 194
195 if (!remote_suggestions_provider_) 195 if (!remote_suggestions_provider_)
196 return; 196 return;
197 197
198 std::string hosts_string; 198 remote_suggestions_provider_->FetchSnippetsForAllCategories();
199 if (!args->GetString(0, &hosts_string))
200 return;
201
202 std::vector<std::string> hosts_vector = base::SplitString(
203 hosts_string, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
204 std::set<std::string> hosts(hosts_vector.begin(), hosts_vector.end());
205
206 remote_suggestions_provider_->FetchSnippetsFromHosts(
207 hosts,
208 /*interactive_request=*/true);
209 } 199 }
210 200
211 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions( 201 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions(
212 const base::ListValue* args) { 202 const base::ListValue* args) {
213 DCHECK_EQ(1u, args->GetSize()); 203 DCHECK_EQ(1u, args->GetSize());
214 204
215 int category_id; 205 int category_id;
216 if (!args->GetInteger(0, &category_id)) 206 if (!args->GetInteger(0, &category_id))
217 return; 207 return;
218 208
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 category_entry->SetString("status", GetCategoryStatusName(status)); 387 category_entry->SetString("status", GetCategoryStatusName(status));
398 category_entry->Set("suggestions", std::move(suggestions_list)); 388 category_entry->Set("suggestions", std::move(suggestions_list));
399 category_entry->Set("dismissedSuggestions", std::move(dismissed_list)); 389 category_entry->Set("dismissedSuggestions", std::move(dismissed_list));
400 categories_list->Append(std::move(category_entry)); 390 categories_list->Append(std::move(category_entry));
401 } 391 }
402 392
403 if (remote_suggestions_provider_) { 393 if (remote_suggestions_provider_) {
404 const std::string& status = 394 const std::string& status =
405 remote_suggestions_provider_->snippets_fetcher()->last_status(); 395 remote_suggestions_provider_->snippets_fetcher()->last_status();
406 if (!status.empty()) 396 if (!status.empty())
407 SendString("hosts-status", "Finished: " + status); 397 SendString("remote-status", "Finished: " + status);
408 } 398 }
409 399
410 base::DictionaryValue result; 400 base::DictionaryValue result;
411 result.Set("list", std::move(categories_list)); 401 result.Set("list", std::move(categories_list));
412 web_ui()->CallJavascriptFunctionUnsafe( 402 web_ui()->CallJavascriptFunctionUnsafe(
413 "chrome.SnippetsInternals.receiveContentSuggestions", result); 403 "chrome.SnippetsInternals.receiveContentSuggestions", result);
414 } 404 }
415 405
416 void SnippetsInternalsMessageHandler::SendBoolean(const std::string& name, 406 void SnippetsInternalsMessageHandler::SendBoolean(const std::string& name,
417 bool value) { 407 bool value) {
(...skipping 11 matching lines...) Expand all
429 419
430 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( 420 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded(
431 Category category, 421 Category category,
432 std::vector<ContentSuggestion> dismissed_suggestions) { 422 std::vector<ContentSuggestion> dismissed_suggestions) {
433 if (dismissed_state_[category] == DismissedState::HIDDEN) 423 if (dismissed_state_[category] == DismissedState::HIDDEN)
434 return; 424 return;
435 dismissed_suggestions_[category] = std::move(dismissed_suggestions); 425 dismissed_suggestions_[category] = std::move(dismissed_suggestions);
436 dismissed_state_[category] = DismissedState::VISIBLE; 426 dismissed_state_[category] = DismissedState::VISIBLE;
437 SendContentSuggestions(); 427 SendContentSuggestions();
438 } 428 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/snippets_internals.js ('k') | components/ntp_snippets/remote/ntp_snippets_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698