json_parser_impl.cc 899 B

12345678910111213141516171819202122232425262728293031
  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
  3. // found in the LICENSE file.
  4. #include "services/data_decoder/json_parser_impl.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "base/json/json_reader.h"
  8. #include "base/values.h"
  9. namespace data_decoder {
  10. JsonParserImpl::JsonParserImpl() = default;
  11. JsonParserImpl::~JsonParserImpl() = default;
  12. void JsonParserImpl::Parse(const std::string& json,
  13. uint32_t options,
  14. ParseCallback callback) {
  15. auto ret = base::JSONReader::ReadAndReturnValueWithError(json, options);
  16. if (ret.has_value()) {
  17. std::move(callback).Run(std::move(*ret), absl::nullopt);
  18. } else {
  19. std::move(callback).Run(
  20. absl::nullopt, absl::make_optional(std::move(ret.error().message)));
  21. }
  22. }
  23. } // namespace data_decoder