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

Unified Diff: components/safe_json/safe_json_parser_mojo_impl.cc

Issue 1861573002: Convert the utility process JSON parser into a Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename build rule 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: components/safe_json/safe_json_parser_mojo_impl.cc
diff --git a/components/safe_json/safe_json_parser_mojo_impl.cc b/components/safe_json/safe_json_parser_mojo_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..931c5d07066f3a5e94965eb0d53ab6d200c843a7
--- /dev/null
+++ b/components/safe_json/safe_json_parser_mojo_impl.cc
@@ -0,0 +1,43 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/safe_json/safe_json_parser_mojo_impl.h"
Bernhard Bauer 2016/04/13 15:49:08 Technically, we should split this up into a browse
Anand Mistry (off Chromium) 2016/04/14 00:59:49 Well, the utility-side message filter was still in
Bernhard Bauer 2016/04/14 14:11:38 Sure, they get built as different targets, but the
Anand Mistry (off Chromium) 2016/04/18 05:06:45 I've made the change for this latest patchset. How
Bernhard Bauer 2016/04/20 16:43:15 OK, fair enough. It is a rather big change, and in
+
+#include <utility>
+
+#include "base/json/json_reader.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+
+namespace safe_json {
+
+// static
+void SafeJsonParserMojoImpl::Create(
+ mojo::InterfaceRequest<mojom::SafeJsonParser> request) {
+ new SafeJsonParserMojoImpl(std::move(request));
+}
+
+SafeJsonParserMojoImpl::SafeJsonParserMojoImpl(
+ mojo::InterfaceRequest<mojom::SafeJsonParser> request)
+ : binding_(this, std::move(request)) {}
+
+SafeJsonParserMojoImpl::~SafeJsonParserMojoImpl() {
+}
+
+void SafeJsonParserMojoImpl::Parse(const mojo::String& json,
+ const ParseCallback& callback) {
+ int error_code;
+ std::string error;
+ scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError(
+ json.get(), base::JSON_PARSE_RFC, &error_code, &error);
+ base::ListValue wrapper;
+ if (value) {
+ wrapper.Append(std::move(value));
+ callback.Run(wrapper, nullptr);
+ } else {
+ callback.Run(wrapper, error);
+ }
+}
+
+} // namespace safe_json

Powered by Google App Engine
This is Rietveld 408576698