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

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

Issue 1910633005: Display status message for "Add snippets" on chrome://snippets-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: The final version ;) Created 4 years, 8 months 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 <sstream> 9 #include <sstream>
10 #include <vector> 10 #include <vector>
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/snippets_internals.html ('k') | components/ntp_snippets/ntp_snippets_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698