1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_WEB_PACKAGE_WEB_BUNDLE_PARSER_H_
#define COMPONENTS_WEB_PACKAGE_WEB_BUNDLE_PARSER_H_
#include <memory>
#include <optional>
#include "base/containers/flat_set.h"
#include "base/containers/unique_ptr_adapters.h"
#include "components/web_package/mojom/web_bundle_parser.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "url/gurl.h"
namespace web_package {
// This class is responsible for assigning parsing requests to the particular
// parsers.
class WebBundleParser : public mojom::WebBundleParser {
public:
WebBundleParser(mojo::PendingRemote<mojom::BundleDataSource> data_source,
GURL base_url);
WebBundleParser(const WebBundleParser&) = delete;
WebBundleParser& operator=(const WebBundleParser&) = delete;
~WebBundleParser() override;
// This interface defines the parser of sections of the Web Bundle.
// Please implement it if you need to create a parse of anything in the
// Web Bundle.
class WebBundleSectionParser {
public:
// The closure should contain the callback provided by the caller with
// bound parameters that we should return to the caller.
using ParsingCompleteCallback = base::OnceCallback<void(base::OnceClosure)>;
virtual void StartParsing(ParsingCompleteCallback) = 0;
virtual ~WebBundleSectionParser() = default;
};
private:
class MetadataParser;
class ResponseParser;
// mojom::WebBundleParser implementation.
void ParseIntegrityBlock(ParseIntegrityBlockCallback callback) override;
void ParseMetadata(std::optional<uint64_t> offset,
ParseMetadataCallback callback) override;
void ParseResponse(uint64_t response_offset,
uint64_t response_length,
ParseResponseCallback callback) override;
void Close(CloseCallback parser_closed_callback) override;
void OnDataSourceClosed(CloseCallback parser_closed_callback);
void ActivateParser(std::unique_ptr<WebBundleSectionParser> parser);
void OnParsingComplete(WebBundleSectionParser* parser,
base::OnceClosure result_callback);
void OnDisconnect();
bool CheckIfClosed();
GURL base_url_;
base::flat_set<std::unique_ptr<WebBundleSectionParser>,
base::UniquePtrComparator>
active_parsers_;
mojo::Remote<mojom::BundleDataSource> data_source_;
bool is_closed_ = false;
};
} // namespace web_package
#endif // COMPONENTS_WEB_PACKAGE_WEB_BUNDLE_PARSER_H_
|