Chromium Code Reviews| 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 (auto& snippet : ntp_snippets_service_->snippets()) |
|
Bernhard Bauer
2016/05/10 14:48:56
Make this const as well? Also, use the actual type
mastiz
2016/05/10 15:59:52
Done.
| |
| 181 snippets_list->Append(PrepareSnippet(snippet, index++, false)); | 181 snippets_list->Append(PrepareSnippet(*snippet, index++, false)); |
| 182 | 182 |
| 183 base::DictionaryValue result; | 183 base::DictionaryValue result; |
| 184 result.Set("list", std::move(snippets_list)); | 184 result.Set("list", std::move(snippets_list)); |
| 185 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveSnippets", | 185 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveSnippets", |
| 186 result); | 186 result); |
| 187 | 187 |
| 188 const std::string& status = ntp_snippets_service_->last_status(); | 188 const std::string& status = ntp_snippets_service_->last_status(); |
| 189 if (!status.empty()) | 189 if (!status.empty()) |
| 190 SendString("hosts-status", "Finished: " + status); | 190 SendString("hosts-status", "Finished: " + status); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void SnippetsInternalsMessageHandler::SendDiscardedSnippets() { | 193 void SnippetsInternalsMessageHandler::SendDiscardedSnippets() { |
| 194 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); | 194 std::unique_ptr<base::ListValue> snippets_list(new base::ListValue); |
| 195 | 195 |
| 196 int index = 0; | 196 int index = 0; |
| 197 for (auto& snippet : ntp_snippets_service_->discarded_snippets()) | 197 for (const auto& snippet : ntp_snippets_service_->discarded_snippets()) |
| 198 snippets_list->Append(PrepareSnippet(*snippet, index++, true)); | 198 snippets_list->Append(PrepareSnippet(*snippet, index++, true)); |
| 199 | 199 |
| 200 base::DictionaryValue result; | 200 base::DictionaryValue result; |
| 201 result.Set("list", std::move(snippets_list)); | 201 result.Set("list", std::move(snippets_list)); |
| 202 web_ui()->CallJavascriptFunction( | 202 web_ui()->CallJavascriptFunction( |
| 203 "chrome.SnippetsInternals.receiveDiscardedSnippets", result); | 203 "chrome.SnippetsInternals.receiveDiscardedSnippets", result); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void SnippetsInternalsMessageHandler::SendHosts() { | 206 void SnippetsInternalsMessageHandler::SendHosts() { |
| 207 std::unique_ptr<base::ListValue> hosts_list(new base::ListValue); | 207 std::unique_ptr<base::ListValue> hosts_list(new base::ListValue); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 233 } | 233 } |
| 234 | 234 |
| 235 void SnippetsInternalsMessageHandler::SendString(const std::string& name, | 235 void SnippetsInternalsMessageHandler::SendString(const std::string& name, |
| 236 const std::string& value) { | 236 const std::string& value) { |
| 237 base::StringValue string_name(name); | 237 base::StringValue string_name(name); |
| 238 base::StringValue string_value(value); | 238 base::StringValue string_value(value); |
| 239 | 239 |
| 240 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveProperty", | 240 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveProperty", |
| 241 string_name, string_value); | 241 string_name, string_value); |
| 242 } | 242 } |
| OLD | NEW |