Commit 6d003e82 authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

Move source stream <-> data pipe adapters to network service

This code is currently in content/browser/loader but is useful to other
features.

Bug: 1012869
Change-Id: Ie129d975d0d381f2ec8e98670efc8ed52c39d40a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1848055Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: enne <enne@chromium.org>
Auto-Submit: enne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704734}
parent a30a8f8a
...@@ -1085,8 +1085,6 @@ jumbo_source_set("browser") { ...@@ -1085,8 +1085,6 @@ jumbo_source_set("browser") {
"loader/cached_navigation_url_loader.h", "loader/cached_navigation_url_loader.h",
"loader/cross_origin_read_blocking_checker.cc", "loader/cross_origin_read_blocking_checker.cc",
"loader/cross_origin_read_blocking_checker.h", "loader/cross_origin_read_blocking_checker.h",
"loader/data_pipe_to_source_stream.cc",
"loader/data_pipe_to_source_stream.h",
"loader/download_utils_impl.cc", "loader/download_utils_impl.cc",
"loader/download_utils_impl.h", "loader/download_utils_impl.h",
"loader/file_url_loader_factory.cc", "loader/file_url_loader_factory.cc",
...@@ -1109,8 +1107,6 @@ jumbo_source_set("browser") { ...@@ -1109,8 +1107,6 @@ jumbo_source_set("browser") {
"loader/shared_cors_origin_access_list_impl.h", "loader/shared_cors_origin_access_list_impl.h",
"loader/single_request_url_loader_factory.cc", "loader/single_request_url_loader_factory.cc",
"loader/single_request_url_loader_factory.h", "loader/single_request_url_loader_factory.h",
"loader/source_stream_to_data_pipe.cc",
"loader/source_stream_to_data_pipe.h",
"loader/webrtc_connections_observer.cc", "loader/webrtc_connections_observer.cc",
"loader/webrtc_connections_observer.h", "loader/webrtc_connections_observer.h",
"locks/lock_manager.cc", "locks/lock_manager.cc",
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "content/browser/loader/data_pipe_to_source_stream.h"
#include "content/browser/loader/source_stream_to_data_pipe.h"
#include "content/browser/web_package/signed_exchange_cert_fetcher_factory.h" #include "content/browser/web_package/signed_exchange_cert_fetcher_factory.h"
#include "content/browser/web_package/signed_exchange_devtools_proxy.h" #include "content/browser/web_package/signed_exchange_devtools_proxy.h"
#include "content/browser/web_package/signed_exchange_handler.h" #include "content/browser/web_package/signed_exchange_handler.h"
...@@ -28,8 +26,10 @@ ...@@ -28,8 +26,10 @@
#include "net/http/http_util.h" #include "net/http/http_util.h"
#include "net/url_request/redirect_util.h" #include "net/url_request/redirect_util.h"
#include "services/network/public/cpp/constants.h" #include "services/network/public/cpp/constants.h"
#include "services/network/public/cpp/data_pipe_to_source_stream.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/source_stream_to_data_pipe.h"
#include "services/network/public/cpp/url_loader_completion_status.h" #include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h" #include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "third_party/blink/public/common/loader/url_loader_throttle.h" #include "third_party/blink/public/common/loader/url_loader_throttle.h"
...@@ -154,7 +154,8 @@ void SignedExchangeLoader::OnStartLoadingResponseBody( ...@@ -154,7 +154,8 @@ void SignedExchangeLoader::OnStartLoadingResponseBody(
if (g_signed_exchange_factory_for_testing_) { if (g_signed_exchange_factory_for_testing_) {
signed_exchange_handler_ = g_signed_exchange_factory_for_testing_->Create( signed_exchange_handler_ = g_signed_exchange_factory_for_testing_->Create(
outer_request_.url, outer_request_.url,
std::make_unique<DataPipeToSourceStream>(std::move(response_body)), std::make_unique<network::DataPipeToSourceStream>(
std::move(response_body)),
base::BindOnce(&SignedExchangeLoader::OnHTTPExchangeFound, base::BindOnce(&SignedExchangeLoader::OnHTTPExchangeFound,
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
std::move(cert_fetcher_factory)); std::move(cert_fetcher_factory));
...@@ -164,7 +165,8 @@ void SignedExchangeLoader::OnStartLoadingResponseBody( ...@@ -164,7 +165,8 @@ void SignedExchangeLoader::OnStartLoadingResponseBody(
signed_exchange_handler_ = std::make_unique<SignedExchangeHandler>( signed_exchange_handler_ = std::make_unique<SignedExchangeHandler>(
IsOriginSecure(outer_request_.url), IsOriginSecure(outer_request_.url),
HasNoSniffHeader(outer_response_head_), content_type_, HasNoSniffHeader(outer_response_head_), content_type_,
std::make_unique<DataPipeToSourceStream>(std::move(response_body)), std::make_unique<network::DataPipeToSourceStream>(
std::move(response_body)),
base::BindOnce(&SignedExchangeLoader::OnHTTPExchangeFound, base::BindOnce(&SignedExchangeLoader::OnHTTPExchangeFound,
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
std::move(cert_fetcher_factory), outer_request_.load_flags, std::move(cert_fetcher_factory), outer_request_.load_flags,
...@@ -299,7 +301,7 @@ void SignedExchangeLoader::OnHTTPExchangeFound( ...@@ -299,7 +301,7 @@ void SignedExchangeLoader::OnHTTPExchangeFound(
return; return;
} }
pending_body_consumer_ = std::move(consumer_handle); pending_body_consumer_ = std::move(consumer_handle);
body_data_pipe_adapter_ = std::make_unique<SourceStreamToDataPipe>( body_data_pipe_adapter_ = std::make_unique<network::SourceStreamToDataPipe>(
std::move(payload_stream), std::move(producer_handle)); std::move(payload_stream), std::move(producer_handle));
StartReadingBody(); StartReadingBody();
......
...@@ -34,6 +34,7 @@ class SourceStream; ...@@ -34,6 +34,7 @@ class SourceStream;
namespace network { namespace network {
class SharedURLLoaderFactory; class SharedURLLoaderFactory;
class SourceStreamToDataPipe;
} // namespace network } // namespace network
namespace content { namespace content {
...@@ -44,7 +45,6 @@ class SignedExchangeHandlerFactory; ...@@ -44,7 +45,6 @@ class SignedExchangeHandlerFactory;
class SignedExchangePrefetchMetricRecorder; class SignedExchangePrefetchMetricRecorder;
class SignedExchangeReporter; class SignedExchangeReporter;
class SignedExchangeValidityPinger; class SignedExchangeValidityPinger;
class SourceStreamToDataPipe;
// SignedExchangeLoader handles an origin-signed HTTP exchange response. It is // SignedExchangeLoader handles an origin-signed HTTP exchange response. It is
// created when a SignedExchangeRequestHandler recieves an origin-signed HTTP // created when a SignedExchangeRequestHandler recieves an origin-signed HTTP
...@@ -161,7 +161,7 @@ class CONTENT_EXPORT SignedExchangeLoader final ...@@ -161,7 +161,7 @@ class CONTENT_EXPORT SignedExchangeLoader final
network::mojom::URLLoaderClientRequest pending_client_request_; network::mojom::URLLoaderClientRequest pending_client_request_;
std::unique_ptr<SignedExchangeHandler> signed_exchange_handler_; std::unique_ptr<SignedExchangeHandler> signed_exchange_handler_;
std::unique_ptr<SourceStreamToDataPipe> body_data_pipe_adapter_; std::unique_ptr<network::SourceStreamToDataPipe> body_data_pipe_adapter_;
// Kept around until ProceedWithResponse is called. // Kept around until ProceedWithResponse is called.
mojo::ScopedDataPipeConsumerHandle pending_body_consumer_; mojo::ScopedDataPipeConsumerHandle pending_body_consumer_;
......
...@@ -1674,11 +1674,9 @@ test("content_unittests") { ...@@ -1674,11 +1674,9 @@ test("content_unittests") {
"../browser/indexed_db/scopes/leveldb_scopes_test_utils.h", "../browser/indexed_db/scopes/leveldb_scopes_test_utils.h",
"../browser/indexed_db/scopes/leveldb_scopes_unittest.cc", "../browser/indexed_db/scopes/leveldb_scopes_unittest.cc",
"../browser/indexed_db/scopes/scopes_lock_manager_unittest.cc", "../browser/indexed_db/scopes/scopes_lock_manager_unittest.cc",
"../browser/loader/data_pipe_to_source_stream_unittest.cc",
"../browser/loader/merkle_integrity_source_stream_unittest.cc", "../browser/loader/merkle_integrity_source_stream_unittest.cc",
"../browser/loader/navigation_url_loader_impl_unittest.cc", "../browser/loader/navigation_url_loader_impl_unittest.cc",
"../browser/loader/navigation_url_loader_unittest.cc", "../browser/loader/navigation_url_loader_unittest.cc",
"../browser/loader/source_stream_to_data_pipe_unittest.cc",
"../browser/manifest/manifest_icon_downloader_unittest.cc", "../browser/manifest/manifest_icon_downloader_unittest.cc",
"../browser/media/audible_metrics_unittest.cc", "../browser/media/audible_metrics_unittest.cc",
"../browser/media/audio_input_stream_broker_unittest.cc", "../browser/media/audio_input_stream_broker_unittest.cc",
......
...@@ -31,6 +31,8 @@ jumbo_component("cpp") { ...@@ -31,6 +31,8 @@ jumbo_component("cpp") {
"cors/preflight_result.h", "cors/preflight_result.h",
"cross_thread_shared_url_loader_factory_info.cc", "cross_thread_shared_url_loader_factory_info.cc",
"cross_thread_shared_url_loader_factory_info.h", "cross_thread_shared_url_loader_factory_info.h",
"data_pipe_to_source_stream.cc",
"data_pipe_to_source_stream.h",
"features.cc", "features.cc",
"features.h", "features.h",
"header_util.cc", "header_util.cc",
...@@ -60,6 +62,8 @@ jumbo_component("cpp") { ...@@ -60,6 +62,8 @@ jumbo_component("cpp") {
"simple_url_loader.cc", "simple_url_loader.cc",
"simple_url_loader.h", "simple_url_loader.h",
"simple_url_loader_stream_consumer.h", "simple_url_loader_stream_consumer.h",
"source_stream_to_data_pipe.cc",
"source_stream_to_data_pipe.h",
"weak_wrapper_shared_url_loader_factory.cc", "weak_wrapper_shared_url_loader_factory.cc",
"weak_wrapper_shared_url_loader_factory.h", "weak_wrapper_shared_url_loader_factory.h",
"wrapper_shared_url_loader_factory.cc", "wrapper_shared_url_loader_factory.cc",
...@@ -198,6 +202,7 @@ source_set("tests") { ...@@ -198,6 +202,7 @@ source_set("tests") {
"cors/preflight_cache_unittest.cc", "cors/preflight_cache_unittest.cc",
"cors/preflight_result_unittest.cc", "cors/preflight_result_unittest.cc",
"cross_thread_shared_url_loader_factory_info_unittest.cc", "cross_thread_shared_url_loader_factory_info_unittest.cc",
"data_pipe_to_source_stream_unittest.cc",
"default_credentials_mojom_traits_unittest.cc", "default_credentials_mojom_traits_unittest.cc",
"digitally_signed_mojom_traits_unittest.cc", "digitally_signed_mojom_traits_unittest.cc",
"header_util_unittest.cc", "header_util_unittest.cc",
...@@ -212,6 +217,7 @@ source_set("tests") { ...@@ -212,6 +217,7 @@ source_set("tests") {
"network_quality_tracker_unittest.cc", "network_quality_tracker_unittest.cc",
"proxy_config_mojom_traits_unittest.cc", "proxy_config_mojom_traits_unittest.cc",
"simple_url_loader_unittest.cc", "simple_url_loader_unittest.cc",
"source_stream_to_data_pipe_unittest.cc",
"url_request_mojom_traits_unittest.cc", "url_request_mojom_traits_unittest.cc",
] ]
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/loader/data_pipe_to_source_stream.h" #include "services/network/public/cpp/data_pipe_to_source_stream.h"
#include <utility> #include <utility>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
namespace content { namespace network {
DataPipeToSourceStream::DataPipeToSourceStream( DataPipeToSourceStream::DataPipeToSourceStream(
mojo::ScopedDataPipeConsumerHandle body) mojo::ScopedDataPipeConsumerHandle body)
...@@ -103,4 +103,4 @@ void DataPipeToSourceStream::FinishReading() { ...@@ -103,4 +103,4 @@ void DataPipeToSourceStream::FinishReading() {
body_.reset(); body_.reset();
} }
} // namespace content } // namespace network
...@@ -2,18 +2,19 @@ ...@@ -2,18 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_LOADER_DATA_PIPE_TO_SOURCE_STREAM_H_ #ifndef SERVICES_NETWORK_PUBLIC_CPP_DATA_PIPE_TO_SOURCE_STREAM_H_
#define CONTENT_BROWSER_LOADER_DATA_PIPE_TO_SOURCE_STREAM_H_ #define SERVICES_NETWORK_PUBLIC_CPP_DATA_PIPE_TO_SOURCE_STREAM_H_
#include "content/common/content_export.h" #include "base/component_export.h"
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/public/cpp/system/simple_watcher.h" #include "mojo/public/cpp/system/simple_watcher.h"
#include "net/base/completion_once_callback.h" #include "net/base/completion_once_callback.h"
#include "net/filter/source_stream.h" #include "net/filter/source_stream.h"
namespace content { namespace network {
class CONTENT_EXPORT DataPipeToSourceStream final : public net::SourceStream { class COMPONENT_EXPORT(NETWORK_CPP) DataPipeToSourceStream final
: public net::SourceStream {
public: public:
explicit DataPipeToSourceStream(mojo::ScopedDataPipeConsumerHandle body); explicit DataPipeToSourceStream(mojo::ScopedDataPipeConsumerHandle body);
~DataPipeToSourceStream() override; ~DataPipeToSourceStream() override;
...@@ -39,6 +40,6 @@ class CONTENT_EXPORT DataPipeToSourceStream final : public net::SourceStream { ...@@ -39,6 +40,6 @@ class CONTENT_EXPORT DataPipeToSourceStream final : public net::SourceStream {
DISALLOW_COPY_AND_ASSIGN(DataPipeToSourceStream); DISALLOW_COPY_AND_ASSIGN(DataPipeToSourceStream);
}; };
} // namespace content } // namespace network
#endif // CONTENT_BROWSER_LOADER_DATA_PIPE_TO_SOURCE_STREAM_H_ #endif // SERVICES_NETWORK_PUBLIC_CPP_DATA_PIPE_TO_SOURCE_STREAM_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/loader/data_pipe_to_source_stream.h" #include "services/network/public/cpp/data_pipe_to_source_stream.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "net/base/test_completion_callback.h" #include "net/base/test_completion_callback.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace content { namespace network {
namespace { namespace {
...@@ -172,4 +172,4 @@ TEST_P(DataPipeToSourceStreamTest, DestructorClosesConsumerEnd) { ...@@ -172,4 +172,4 @@ TEST_P(DataPipeToSourceStreamTest, DestructorClosesConsumerEnd) {
EXPECT_EQ(result, MOJO_RESULT_FAILED_PRECONDITION); EXPECT_EQ(result, MOJO_RESULT_FAILED_PRECONDITION);
} }
} // namespace content } // namespace network
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/loader/source_stream_to_data_pipe.h" #include "services/network/public/cpp/source_stream_to_data_pipe.h"
#include "base/bind.h" #include "base/bind.h"
#include "net/filter/source_stream.h" #include "net/filter/source_stream.h"
namespace content { namespace network {
SourceStreamToDataPipe::SourceStreamToDataPipe( SourceStreamToDataPipe::SourceStreamToDataPipe(
std::unique_ptr<net::SourceStream> source, std::unique_ptr<net::SourceStream> source,
...@@ -99,4 +99,4 @@ void SourceStreamToDataPipe::OnComplete(int result) { ...@@ -99,4 +99,4 @@ void SourceStreamToDataPipe::OnComplete(int result) {
std::move(completion_callback_).Run(result); std::move(completion_callback_).Run(result);
} }
} // namespace content } // namespace network
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_LOADER_SOURCE_STREAM_TO_DATA_PIPE_H_ #ifndef SERVICES_NETWORK_PUBLIC_CPP_SOURCE_STREAM_TO_DATA_PIPE_H_
#define CONTENT_BROWSER_LOADER_SOURCE_STREAM_TO_DATA_PIPE_H_ #define SERVICES_NETWORK_PUBLIC_CPP_SOURCE_STREAM_TO_DATA_PIPE_H_
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/component_export.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/public/cpp/system/simple_watcher.h" #include "mojo/public/cpp/system/simple_watcher.h"
#include "services/network/public/cpp/net_adapters.h" #include "services/network/public/cpp/net_adapters.h"
...@@ -16,11 +16,11 @@ namespace net { ...@@ -16,11 +16,11 @@ namespace net {
class SourceStream; class SourceStream;
} }
namespace content { namespace network {
// A convenient adapter class to read out data from net::SourceStream // A convenient adapter class to read out data from net::SourceStream
// and write them into a data pipe. // and write them into a data pipe.
class CONTENT_EXPORT SourceStreamToDataPipe { class COMPONENT_EXPORT(NETWORK_CPP) SourceStreamToDataPipe {
public: public:
// Reads out the data from |source| and write into |dest|. // Reads out the data from |source| and write into |dest|.
SourceStreamToDataPipe(std::unique_ptr<net::SourceStream> source, SourceStreamToDataPipe(std::unique_ptr<net::SourceStream> source,
...@@ -50,6 +50,6 @@ class CONTENT_EXPORT SourceStreamToDataPipe { ...@@ -50,6 +50,6 @@ class CONTENT_EXPORT SourceStreamToDataPipe {
base::WeakPtrFactory<SourceStreamToDataPipe> weak_factory_{this}; base::WeakPtrFactory<SourceStreamToDataPipe> weak_factory_{this};
}; };
} // namespace content } // namespace network
#endif // CONTENT_BROWSER_LOADER_SOURCE_STREAM_TO_DATA_PIPE_H_ #endif // SERVICES_NETWORK_PUBLIC_CPP_SOURCE_STREAM_TO_DATA_PIPE_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/loader/source_stream_to_data_pipe.h" #include "services/network/public/cpp/source_stream_to_data_pipe.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/optional.h" #include "base/optional.h"
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "net/filter/mock_source_stream.h" #include "net/filter/mock_source_stream.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace content { namespace network {
namespace { namespace {
...@@ -196,4 +196,4 @@ TEST_P(SourceStreamToDataPipeTest, ConsumerClosed) { ...@@ -196,4 +196,4 @@ TEST_P(SourceStreamToDataPipeTest, ConsumerClosed) {
EXPECT_EQ(*CallbackResult(), net::ERR_ABORTED); EXPECT_EQ(*CallbackResult(), net::ERR_ABORTED);
} }
} // namespace content } // namespace network
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment