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 |