blob: a43fbf98f02518f449e0d061a7833ae2ed08c001 [file] [log] [blame]
// Copyright 2013 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.
#ifndef SERVICES_DATA_DECODER_PUBLIC_CPP_SAFE_JSON_PARSER_IMPL_H_
#define SERVICES_DATA_DECODER_PUBLIC_CPP_SAFE_JSON_PARSER_IMPL_H_
#include <memory>
#include <string>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/optional.h"
#include "base/threading/thread_checker.h"
#include "base/token.h"
#include "base/values.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/data_decoder/public/cpp/safe_json_parser.h"
#include "services/data_decoder/public/mojom/json_parser.mojom.h"
namespace service_manager {
class Connector;
}
namespace data_decoder {
class SafeJsonParserImpl : public SafeJsonParser {
public:
SafeJsonParserImpl(service_manager::Connector* connector,
const std::string& unsafe_json,
SuccessCallback success_callback,
ErrorCallback error_callback,
const base::Optional<base::Token>& batch_id);
private:
~SafeJsonParserImpl() override;
// SafeJsonParser implementation.
void Start() override;
void StartOnIOThread();
void OnConnectionError();
// mojom::SafeJsonParser::Parse callback.
void OnParseDone(base::Optional<base::Value> result,
const base::Optional<std::string>& error);
// Reports the result on the calling task runner via the |success_callback_|
// or the |error_callback_|.
void ReportResults(base::Optional<base::Value> parsed_json,
const std::string& error);
const std::string unsafe_json_;
SuccessCallback success_callback_;
ErrorCallback error_callback_;
mojo::Remote<mojom::JsonParser> json_parser_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(SafeJsonParserImpl);
};
} // namespace data_decoder
#endif // SERVICES_DATA_DECODER_PUBLIC_CPP_SAFE_JSON_PARSER_IMPL_H_