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

Side by Side 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: After code review #2 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>
10 #include <vector> 9 #include <vector>
11 10
12 #include "base/bind.h" 11 #include "base/bind.h"
13 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 13 #include "base/command_line.h"
15 #include "base/feature_list.h" 14 #include "base/feature_list.h"
16 #include "base/i18n/time_formatting.h" 15 #include "base/i18n/time_formatting.h"
16 #include "base/json/json_writer.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
20 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "chrome/browser/android/chrome_feature_list.h" 22 #include "chrome/browser/android/chrome_feature_list.h"
23 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" 23 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "components/ntp_snippets/ntp_snippet.h" 25 #include "components/ntp_snippets/ntp_snippet.h"
26 #include "components/ntp_snippets/pref_names.h"
26 #include "components/ntp_snippets/switches.h" 27 #include "components/ntp_snippets/switches.h"
28 #include "components/prefs/pref_service.h"
27 #include "content/public/browser/web_ui.h" 29 #include "content/public/browser/web_ui.h"
28 30
29 namespace { 31 namespace {
30 32
31 std::unique_ptr<base::DictionaryValue> PrepareSnippet( 33 std::unique_ptr<base::DictionaryValue> PrepareSnippet(
32 const ntp_snippets::NTPSnippet& snippet, 34 const ntp_snippets::NTPSnippet& snippet,
33 int index, 35 int index,
34 bool discarded) { 36 bool discarded) {
35 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); 37 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
36 entry->SetString("title", snippet.title()); 38 entry->SetString("title", snippet.title());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 web_ui()->RegisterMessageCallback( 81 web_ui()->RegisterMessageCallback(
80 "loaded", 82 "loaded",
81 base::Bind(&SnippetsInternalsMessageHandler::HandleLoaded, 83 base::Bind(&SnippetsInternalsMessageHandler::HandleLoaded,
82 base::Unretained(this))); 84 base::Unretained(this)));
83 85
84 web_ui()->RegisterMessageCallback( 86 web_ui()->RegisterMessageCallback(
85 "clear", base::Bind(&SnippetsInternalsMessageHandler::HandleClear, 87 "clear", base::Bind(&SnippetsInternalsMessageHandler::HandleClear,
86 base::Unretained(this))); 88 base::Unretained(this)));
87 89
88 web_ui()->RegisterMessageCallback( 90 web_ui()->RegisterMessageCallback(
91 "dump", base::Bind(&SnippetsInternalsMessageHandler::HandleDump,
92 base::Unretained(this)));
93
94 web_ui()->RegisterMessageCallback(
89 "download", base::Bind(&SnippetsInternalsMessageHandler::HandleDownload, 95 "download", base::Bind(&SnippetsInternalsMessageHandler::HandleDownload,
90 base::Unretained(this))); 96 base::Unretained(this)));
91 97
92 web_ui()->RegisterMessageCallback( 98 web_ui()->RegisterMessageCallback(
93 "clearDiscarded", 99 "clearDiscarded",
94 base::Bind(&SnippetsInternalsMessageHandler::HandleClearDiscarded, 100 base::Bind(&SnippetsInternalsMessageHandler::HandleClearDiscarded,
95 base::Unretained(this))); 101 base::Unretained(this)));
96 } 102 }
97 103
98 void SnippetsInternalsMessageHandler::HandleLoaded( 104 void SnippetsInternalsMessageHandler::HandleLoaded(
99 const base::ListValue* args) { 105 const base::ListValue* args) {
100 DCHECK_EQ(0u, args->GetSize()); 106 DCHECK_EQ(0u, args->GetSize());
101 107
102 dom_loaded_ = true; 108 dom_loaded_ = true;
103 109
104 SendInitialData(); 110 SendInitialData();
105 } 111 }
106 112
107 void SnippetsInternalsMessageHandler::HandleClear(const base::ListValue* args) { 113 void SnippetsInternalsMessageHandler::HandleClear(const base::ListValue* args) {
108 DCHECK_EQ(0u, args->GetSize()); 114 DCHECK_EQ(0u, args->GetSize());
109 115
110 ntp_snippets_service_->ClearSnippets(); 116 ntp_snippets_service_->ClearSnippets();
111 } 117 }
112 118
119 void SnippetsInternalsMessageHandler::HandleDump(const base::ListValue* args) {
120 DCHECK_EQ(0u, args->GetSize());
121
122 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
123
124 std::string json;
125 base::JSONWriter::Write(
126 *pref_service->GetList(ntp_snippets::prefs::kSnippets), &json);
127
128 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveJson",
129 base::StringValue(json));
130 }
131
113 void SnippetsInternalsMessageHandler::HandleClearDiscarded( 132 void SnippetsInternalsMessageHandler::HandleClearDiscarded(
114 const base::ListValue* args) { 133 const base::ListValue* args) {
115 DCHECK_EQ(0u, args->GetSize()); 134 DCHECK_EQ(0u, args->GetSize());
116 135
117 ntp_snippets_service_->ClearDiscardedSnippets(); 136 ntp_snippets_service_->ClearDiscardedSnippets();
118 SendDiscardedSnippets(); 137 SendDiscardedSnippets();
119 } 138 }
120 139
121 void SnippetsInternalsMessageHandler::HandleDownload( 140 void SnippetsInternalsMessageHandler::HandleDownload(
122 const base::ListValue* args) { 141 const base::ListValue* args) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 218 }
200 219
201 void SnippetsInternalsMessageHandler::SendString(const std::string& name, 220 void SnippetsInternalsMessageHandler::SendString(const std::string& name,
202 const std::string& value) { 221 const std::string& value) {
203 base::StringValue string_name(name); 222 base::StringValue string_name(name);
204 base::StringValue string_value(value); 223 base::StringValue string_value(value);
205 224
206 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveProperty", 225 web_ui()->CallJavascriptFunction("chrome.SnippetsInternals.receiveProperty",
207 string_name, string_value); 226 string_name, string_value);
208 } 227 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/snippets_internals_message_handler.h ('k') | components/ntp_snippets/ntp_snippets_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698