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

Unified Diff: components/safe_json/utility/safe_json_parser_mojo_impl.cc

Issue 1948303002: Re-land: Convert the utility process JSON parser into a Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « components/safe_json/utility/safe_json_parser_mojo_impl.h ('k') | components/typemaps.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_json/utility/safe_json_parser_mojo_impl.cc
diff --git a/components/safe_json/utility/safe_json_parser_mojo_impl.cc b/components/safe_json/utility/safe_json_parser_mojo_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..45820757ce858de460bc9a2083d1209de63c65be
--- /dev/null
+++ b/components/safe_json/utility/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/utility/safe_json_parser_mojo_impl.h"
+
+#include <memory>
+#include <utility>
+
+#include "base/json/json_reader.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;
+ std::unique_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
« no previous file with comments | « components/safe_json/utility/safe_json_parser_mojo_impl.h ('k') | components/typemaps.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698