Skip to content

Commit

Permalink
Move WebBundleURLLoaderFactory and others into components/web_package/
Browse files Browse the repository at this point in the history
This is a preparation for https://crrev.com/c/3788952, which will use WebBundleURLLoaderFactory from a renderer.

This CL is a purely refactoring. No behavior change.

Bug: 1302217
Change-Id: If420ef3423c7e2fa1aa0578920b7f648a1ea0b68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3810977
Commit-Queue: Hayato Ito <hayato@chromium.org>
Reviewed-by: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: Kunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1032458}
  • Loading branch information
hayatoito authored and Chromium LUCI CQ committed Aug 8, 2022
1 parent e18402d commit 8c04250
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 181 deletions.
10 changes: 10 additions & 0 deletions components/web_package/BUILD.gn
Expand Up @@ -20,10 +20,15 @@ static_library("web_package") {
"signed_web_bundles/signed_web_bundle_utils.h",
"web_bundle_builder.cc",
"web_bundle_builder.h",
"web_bundle_chunked_buffer.cc",
"web_bundle_chunked_buffer.h",
"web_bundle_memory_quota_consumer.h",
"web_bundle_parser.cc",
"web_bundle_parser.h",
"web_bundle_parser_factory.cc",
"web_bundle_parser_factory.h",
"web_bundle_url_loader_factory.cc",
"web_bundle_url_loader_factory.h",
"web_bundle_utils.cc",
"web_bundle_utils.h",
]
Expand All @@ -34,6 +39,7 @@ static_library("web_package") {
"//components/cbor",
"//mojo/public/cpp/bindings",
"//net",
"//services/network/public/cpp",
"//services/network/public/mojom",
]

Expand All @@ -47,15 +53,19 @@ source_set("unit_tests") {
"signed_web_bundles/signed_web_bundle_id_unittest.cc",
"signed_web_bundles/signed_web_bundle_utils_unittest.cc",
"web_bundle_builder_unittest.cc",
"web_bundle_chunked_buffer_unittest.cc",
"web_bundle_parser_factory_unittest.cc",
"web_bundle_parser_unittest.cc",
"web_bundle_url_loader_factory_unittest.cc",
"web_bundle_utils_unittest.cc",
]
deps = [
":web_package",
"//base/test:test_support",
"//components/cbor",
"//components/web_package/test_support",
"//net/traffic_annotation:test_support",
"//services/network:test_support",
"//testing/gtest",
]
}
Expand Down
4 changes: 3 additions & 1 deletion components/web_package/DEPS
Expand Up @@ -3,7 +3,9 @@ include_rules = [
"+components/cbor",
"+mojo/public/cpp",
"+net",
"+services/network/public/mojom"
"+services/network/public/cpp",
"+services/network/public/mojom",
"+services/network/test",
]

specific_include_rules = {
Expand Down
Expand Up @@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/network/web_bundle/web_bundle_chunked_buffer.h"
#include "components/web_package/web_bundle_chunked_buffer.h"

#include <algorithm>

#include "base/check.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/checked_math.h"

namespace network {
namespace web_package {

namespace {

Expand Down Expand Up @@ -205,4 +205,4 @@ uint64_t WebBundleChunkedBuffer::ReadData(uint64_t offset,
return written;
}

} // namespace network
} // namespace web_package
Expand Up @@ -2,23 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_NETWORK_WEB_BUNDLE_WEB_BUNDLE_CHUNKED_BUFFER_H_
#define SERVICES_NETWORK_WEB_BUNDLE_WEB_BUNDLE_CHUNKED_BUFFER_H_
#ifndef COMPONENTS_WEB_PACKAGE_WEB_BUNDLE_CHUNKED_BUFFER_H_
#define COMPONENTS_WEB_PACKAGE_WEB_BUNDLE_CHUNKED_BUFFER_H_

#include <vector>

#include "base/component_export.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_refptr.h"
#include "mojo/public/cpp/system/data_pipe_producer.h"

namespace network {
namespace web_package {

// WebBundleChunkedBuffer keeps the appended bytes as a RefCountedBytes, so we
// don't need to copy the bytes while creating a DataSource to read the data
// using a DataPipeProducer.
class COMPONENT_EXPORT(NETWORK_SERVICE) WebBundleChunkedBuffer {
class WebBundleChunkedBuffer {
public:
WebBundleChunkedBuffer();
~WebBundleChunkedBuffer();
Expand Down Expand Up @@ -56,7 +55,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) WebBundleChunkedBuffer {
FRIEND_TEST_ALL_PREFIXES(WebBundleChunkedBufferTest, PartialBuffer);
FRIEND_TEST_ALL_PREFIXES(WebBundleChunkedBufferTest, FindChunk);

class COMPONENT_EXPORT(NETWORK_SERVICE) Chunk {
class Chunk {
public:
Chunk(uint64_t start_pos, scoped_refptr<const base::RefCountedBytes> bytes);
~Chunk();
Expand Down Expand Up @@ -98,6 +97,6 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) WebBundleChunkedBuffer {
ChunkVector chunks_;
};

} // namespace network
} // namespace web_package

#endif // SERVICES_NETWORK_WEB_BUNDLE_WEB_BUNDLE_CHUNKED_BUFFER_H_
#endif // COMPONENTS_WEB_PACKAGE_WEB_BUNDLE_CHUNKED_BUFFER_H_
Expand Up @@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/network/web_bundle/web_bundle_chunked_buffer.h"
#include "components/web_package/web_bundle_chunked_buffer.h"

#include "base/check.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace network {
namespace web_package {
namespace {
constexpr unsigned char kNumeric10Chars[] = "0123456789";
constexpr unsigned char kSmallAlphabet10Chars[] = "abcdefghij";
Expand Down Expand Up @@ -295,4 +295,4 @@ TEST_F(WebBundleChunkedBufferTest, DataSource) {
}
}

} // namespace network
} // namespace web_package
Expand Up @@ -2,21 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_NETWORK_WEB_BUNDLE_WEB_BUNDLE_MEMORY_QUOTA_CONSUMER_H_
#define SERVICES_NETWORK_WEB_BUNDLE_WEB_BUNDLE_MEMORY_QUOTA_CONSUMER_H_
#ifndef COMPONENTS_WEB_PACKAGE_WEB_BUNDLE_MEMORY_QUOTA_CONSUMER_H_
#define COMPONENTS_WEB_PACKAGE_WEB_BUNDLE_MEMORY_QUOTA_CONSUMER_H_

#include "base/component_export.h"

namespace network {
namespace web_package {

// This class is used to check the memory quota while loading subresource
// Web Bundles. The allocated quota is released in the destructor.
class COMPONENT_EXPORT(NETWORK_SERVICE) WebBundleMemoryQuotaConsumer {
class WebBundleMemoryQuotaConsumer {
public:
virtual ~WebBundleMemoryQuotaConsumer() = default;
virtual bool AllocateMemory(uint64_t num_bytes) = 0;
};

} // namespace network
} // namespace web_package

#endif // SERVICES_NETWORK_WEB_BUNDLE_WEB_BUNDLE_MEMORY_QUOTA_CONSUMER_H_
#endif // COMPONENTS_WEB_PACKAGE_WEB_BUNDLE_MEMORY_QUOTA_CONSUMER_H_

0 comments on commit 8c04250

Please sign in to comment.