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

Unified Diff: chrome/browser/ui/webui/snippets_internals_message_handler.cc

Issue 1907233002: Allows to dump current snippets to a json in the Downloads folder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor cleanup 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/snippets_internals_message_handler.cc
diff --git a/chrome/browser/ui/webui/snippets_internals_message_handler.cc b/chrome/browser/ui/webui/snippets_internals_message_handler.cc
index 363919fbec35873db79e2b69c843a73f07445273..823324bfb1e33ea82ec646836952e79ded8a72c1 100644
--- a/chrome/browser/ui/webui/snippets_internals_message_handler.cc
+++ b/chrome/browser/ui/webui/snippets_internals_message_handler.cc
@@ -6,7 +6,6 @@
#include <memory>
#include <set>
-#include <sstream>
#include <vector>
#include "base/bind.h"
@@ -14,6 +13,7 @@
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/i18n/time_formatting.h"
+#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
@@ -86,6 +86,10 @@ void SnippetsInternalsMessageHandler::RegisterMessages() {
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
+ "dump", base::Bind(&SnippetsInternalsMessageHandler::HandleDump,
+ base::Unretained(this)));
+
+ web_ui()->RegisterMessageCallback(
"download", base::Bind(&SnippetsInternalsMessageHandler::HandleDownload,
base::Unretained(this)));
@@ -110,6 +114,20 @@ void SnippetsInternalsMessageHandler::HandleClear(const base::ListValue* args) {
ntp_snippets_service_->ClearSnippets();
}
+void SnippetsInternalsMessageHandler::HandleDump(const base::ListValue* args) {
+ DCHECK_EQ(0u, args->GetSize());
+
+ std::string json;
+ base::JSONWriter::Write(
+ *ntp_snippets_service_->SnippetsToListValue(
Bernhard Bauer 2016/04/25 10:32:22 Really, you could just get the value direct from p
jkrcal 2016/04/25 12:04:15 Done.
+ ntp_snippets_service_->snippets()),
+ &json);
+
+ base::StringValue json_value(json);
Bernhard Bauer 2016/04/25 10:32:22 You could inline this.
jkrcal 2016/04/25 12:04:15 Done.
+ web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveJson",
+ json_value);
+}
+
void SnippetsInternalsMessageHandler::HandleClearDiscarded(
const base::ListValue* args) {
DCHECK_EQ(0u, args->GetSize());

Powered by Google App Engine
This is Rietveld 408576698