| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 SendString("hosts-help", help); | 170 SendString("hosts-help", help); |
| 171 | 171 |
| 172 SendSnippets(); | 172 SendSnippets(); |
| 173 SendDiscardedSnippets(); | 173 SendDiscardedSnippets(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void SnippetsInternalsMessageHandler::SendSnippets() { | 176 void SnippetsInternalsMessageHandler::SendSnippets() { |
| 177 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); | 177 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); |
| 178 | 178 |
| 179 int index = 0; | 179 int index = 0; |
| 180 for (auto& snippet : *ntp_snippets_service_) | 180 for (const std::unique_ptr<ntp_snippets::NTPSnippet>& snippet : |
| 181 snippets_list->Append(PrepareSnippet(snippet, index++, false)); | 181 ntp_snippets_service_->snippets()) |
| 182 snippets_list->Append(PrepareSnippet(*snippet, index++, false)); |
| 182 | 183 |
| 183 base::DictionaryValue result; | 184 base::DictionaryValue result; |
| 184 result.Set("list", std::move(snippets_list)); | 185 result.Set("list", std::move(snippets_list)); |
| 185 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveSnippets", | 186 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveSnippets", |
| 186 result); | 187 result); |
| 187 | 188 |
| 188 const std::string& status = ntp_snippets_service_->last_status(); | 189 const std::string& status = ntp_snippets_service_->last_status(); |
| 189 if (!status.empty()) | 190 if (!status.empty()) |
| 190 SendString("hosts-status", "Finished: " + status); | 191 SendString("hosts-status", "Finished: " + status); |
| 191 } | 192 } |
| 192 | 193 |
| 193 void SnippetsInternalsMessageHandler::SendDiscardedSnippets() { | 194 void SnippetsInternalsMessageHandler::SendDiscardedSnippets() { |
| 194 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); | 195 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); |
| 195 | 196 |
| 196 int index = 0; | 197 int index = 0; |
| 197 for (auto& snippet : ntp_snippets_service_->discarded_snippets()) | 198 for (const auto& snippet : ntp_snippets_service_->discarded_snippets()) |
| 198 snippets_list->Append(PrepareSnippet(*snippet, index++, true)); | 199 snippets_list->Append(PrepareSnippet(*snippet, index++, true)); |
| 199 | 200 |
| 200 base::DictionaryValue result; | 201 base::DictionaryValue result; |
| 201 result.Set("list", std::move(snippets_list)); | 202 result.Set("list", std::move(snippets_list)); |
| 202 web_ui()->CallJavascriptFunction( | 203 web_ui()->CallJavascriptFunction( |
| 203 "chrome.SnippetsInternals.receiveDiscardedSnippets", result); | 204 "chrome.SnippetsInternals.receiveDiscardedSnippets", result); |
| 204 } | 205 } |
| 205 | 206 |
| 206 void SnippetsInternalsMessageHandler::SendHosts() { | 207 void SnippetsInternalsMessageHandler::SendHosts() { |
| 207 std::unique_ptr<base::ListValue> hosts_list(new base::ListValue); | 208 std::unique_ptr<base::ListValue> hosts_list(new base::ListValue); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 233 } | 234 } |
| 234 | 235 |
| 235 void SnippetsInternalsMessageHandler::SendString(const std::string& name, | 236 void SnippetsInternalsMessageHandler::SendString(const std::string& name, |
| 236 const std::string& value) { | 237 const std::string& value) { |
| 237 base::StringValue string_name(name); | 238 base::StringValue string_name(name); |
| 238 base::StringValue string_value(value); | 239 base::StringValue string_value(value); |
| 239 | 240 |
| 240 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveProperty", | 241 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveProperty", |
| 241 string_name, string_value); | 242 string_name, string_value); |
| 242 } | 243 } |
| OLD | NEW |