| 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 <sstream> | 9 #include <sstream> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 DCHECK_EQ(0u, args->GetSize()); | 115 DCHECK_EQ(0u, args->GetSize()); |
| 116 | 116 |
| 117 ntp_snippets_service_->ClearDiscardedSnippets(); | 117 ntp_snippets_service_->ClearDiscardedSnippets(); |
| 118 SendDiscardedSnippets(); | 118 SendDiscardedSnippets(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void SnippetsInternalsMessageHandler::HandleDownload( | 121 void SnippetsInternalsMessageHandler::HandleDownload( |
| 122 const base::ListValue* args) { | 122 const base::ListValue* args) { |
| 123 DCHECK_EQ(1u, args->GetSize()); | 123 DCHECK_EQ(1u, args->GetSize()); |
| 124 | 124 |
| 125 SendString("hosts-status", std::string()); |
| 126 |
| 125 std::string hosts_string; | 127 std::string hosts_string; |
| 126 args->GetString(0, &hosts_string); | 128 args->GetString(0, &hosts_string); |
| 127 | 129 |
| 128 std::vector<std::string> hosts_vector = base::SplitString( | 130 std::vector<std::string> hosts_vector = base::SplitString( |
| 129 hosts_string, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 131 hosts_string, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 130 std::set<std::string> hosts(hosts_vector.begin(), hosts_vector.end()); | 132 std::set<std::string> hosts(hosts_vector.begin(), hosts_vector.end()); |
| 131 | 133 |
| 132 ntp_snippets_service_->FetchSnippetsFromHosts(hosts); | 134 ntp_snippets_service_->FetchSnippetsFromHosts(hosts); |
| 133 } | 135 } |
| 134 | 136 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 153 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); | 155 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); |
| 154 | 156 |
| 155 int index = 0; | 157 int index = 0; |
| 156 for (auto& snippet : *ntp_snippets_service_) | 158 for (auto& snippet : *ntp_snippets_service_) |
| 157 snippets_list->Append(PrepareSnippet(snippet, index++, false)); | 159 snippets_list->Append(PrepareSnippet(snippet, index++, false)); |
| 158 | 160 |
| 159 base::DictionaryValue result; | 161 base::DictionaryValue result; |
| 160 result.Set("list", std::move(snippets_list)); | 162 result.Set("list", std::move(snippets_list)); |
| 161 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveSnippets", | 163 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveSnippets", |
| 162 result); | 164 result); |
| 165 |
| 166 const std::string& status = ntp_snippets_service_->last_status(); |
| 167 if (!status.empty()) |
| 168 SendString("hosts-status", "Finished: " + status); |
| 163 } | 169 } |
| 164 | 170 |
| 165 void SnippetsInternalsMessageHandler::SendDiscardedSnippets() { | 171 void SnippetsInternalsMessageHandler::SendDiscardedSnippets() { |
| 166 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); | 172 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); |
| 167 | 173 |
| 168 int index = 0; | 174 int index = 0; |
| 169 for (auto& snippet : ntp_snippets_service_->discarded_snippets()) | 175 for (auto& snippet : ntp_snippets_service_->discarded_snippets()) |
| 170 snippets_list->Append(PrepareSnippet(*snippet, index++, true)); | 176 snippets_list->Append(PrepareSnippet(*snippet, index++, true)); |
| 171 | 177 |
| 172 base::DictionaryValue result; | 178 base::DictionaryValue result; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 199 } | 205 } |
| 200 | 206 |
| 201 void SnippetsInternalsMessageHandler::SendString(const std::string& name, | 207 void SnippetsInternalsMessageHandler::SendString(const std::string& name, |
| 202 const std::string& value) { | 208 const std::string& value) { |
| 203 base::StringValue string_name(name); | 209 base::StringValue string_name(name); |
| 204 base::StringValue string_value(value); | 210 base::StringValue string_value(value); |
| 205 | 211 |
| 206 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveProperty", | 212 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveProperty", |
| 207 string_name, string_value); | 213 string_name, string_value); |
| 208 } | 214 } |
| OLD | NEW |