Commit 39503361 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Remove some dead code in content/browser/loader.

Bug: 934009
Change-Id: I0a70decdec255d4f635124751d9b1478662324ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1726949
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Auto-Submit: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682406}
parent 2466dcec
......@@ -1143,8 +1143,6 @@ jumbo_source_set("browser") {
"loader/single_request_url_loader_factory.h",
"loader/source_stream_to_data_pipe.cc",
"loader/source_stream_to_data_pipe.h",
"loader/upload_data_stream_builder.cc",
"loader/upload_data_stream_builder.h",
"loader/webrtc_connections_observer.cc",
"loader/webrtc_connections_observer.h",
"locks/lock_manager.cc",
......
......@@ -16,7 +16,6 @@
#include "components/download/public/common/download_url_parameters.h"
#include "components/download/public/common/download_utils.h"
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/browser/loader/upload_data_stream_builder.h"
#include "content/browser/resource_context_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
......
// 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.
#include "content/browser/loader/upload_data_stream_builder.h"
#include <stdint.h>
#include <limits>
#include <utility>
#include <vector>
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "net/base/elements_upload_data_stream.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_file_element_reader.h"
#include "services/network/public/cpp/resource_request_body.h"
#include "storage/browser/blob/blob_data_handle.h"
#include "storage/browser/blob/blob_reader.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/blob/upload_blob_element_reader.h"
namespace base {
class TaskRunner;
}
namespace disk_cache {
class Entry;
}
namespace content {
namespace {
// A subclass of net::UploadBytesElementReader which owns
// ResourceRequestBody.
class BytesElementReader : public net::UploadBytesElementReader {
public:
BytesElementReader(network::ResourceRequestBody* resource_request_body,
const network::DataElement& element)
: net::UploadBytesElementReader(element.bytes(), element.length()),
resource_request_body_(resource_request_body) {
DCHECK_EQ(network::mojom::DataElementType::kBytes, element.type());
}
~BytesElementReader() override {}
private:
scoped_refptr<network::ResourceRequestBody> resource_request_body_;
DISALLOW_COPY_AND_ASSIGN(BytesElementReader);
};
// A subclass of net::UploadFileElementReader which owns
// ResourceRequestBody.
// This class is necessary to ensure the BlobData and any attached shareable
// files survive until upload completion.
class FileElementReader : public net::UploadFileElementReader {
public:
FileElementReader(network::ResourceRequestBody* resource_request_body,
base::TaskRunner* task_runner,
const network::DataElement& element)
: net::UploadFileElementReader(task_runner,
element.path(),
element.offset(),
element.length(),
element.expected_modification_time()),
resource_request_body_(resource_request_body) {
DCHECK_EQ(network::mojom::DataElementType::kFile, element.type());
}
~FileElementReader() override {}
private:
scoped_refptr<network::ResourceRequestBody> resource_request_body_;
DISALLOW_COPY_AND_ASSIGN(FileElementReader);
};
} // namespace
std::unique_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build(
network::ResourceRequestBody* body,
storage::BlobStorageContext* blob_context,
storage::FileSystemContext* file_system_context,
base::SingleThreadTaskRunner* file_task_runner) {
std::vector<std::unique_ptr<net::UploadElementReader>> element_readers;
for (const auto& element : *body->elements()) {
switch (element.type()) {
case network::mojom::DataElementType::kBytes:
element_readers.push_back(
std::make_unique<BytesElementReader>(body, element));
break;
case network::mojom::DataElementType::kFile:
element_readers.push_back(std::make_unique<FileElementReader>(
body, file_task_runner, element));
break;
case network::mojom::DataElementType::kBlob: {
DCHECK_EQ(0ul, element.offset());
std::unique_ptr<storage::BlobDataHandle> handle =
blob_context->GetBlobDataFromUUID(element.blob_uuid());
DCHECK(element.length() == std::numeric_limits<uint64_t>::max() ||
element.length() == handle->size());
element_readers.push_back(
std::make_unique<storage::UploadBlobElementReader>(
std::move(handle)));
break;
}
case network::mojom::DataElementType::kRawFile:
case network::mojom::DataElementType::kDataPipe:
case network::mojom::DataElementType::kChunkedDataPipe:
case network::mojom::DataElementType::kUnknown:
NOTREACHED();
break;
}
}
return std::make_unique<net::ElementsUploadDataStream>(
std::move(element_readers), body->identifier());
}
} // namespace content
// 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 CONTENT_BROWSER_LOADER_UPLOAD_DATA_STREAM_BUILDER_H_
#define CONTENT_BROWSER_LOADER_UPLOAD_DATA_STREAM_BUILDER_H_
#include <memory>
#include "content/common/content_export.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace storage {
class FileSystemContext;
}
namespace net {
class UploadDataStream;
}
namespace network {
class ResourceRequestBody;
}
namespace storage {
class BlobStorageContext;
}
namespace content {
class CONTENT_EXPORT UploadDataStreamBuilder {
public:
// Creates a new UploadDataStream from this request body.
//
// If |body| contains any blob references, the caller is responsible for
// making sure them outlive the returned value of UploadDataStream. We do this
// by binding the BlobDataHandles of them to ResourceRequestBody in
// ResourceDispatcherHostImpl::BeginRequest().
//
// |file_system_context| is used to create a FileStreamReader for files with
// filesystem URLs. |file_task_runner| is used to perform file operations
// when the data gets uploaded.
static std::unique_ptr<net::UploadDataStream> Build(
network::ResourceRequestBody* body,
storage::BlobStorageContext* blob_context,
storage::FileSystemContext* file_system_context,
base::SingleThreadTaskRunner* file_task_runner);
};
} // namespace content
#endif // CONTENT_BROWSER_LOADER_UPLOAD_DATA_STREAM_BUILDER_H_
// 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.
#include "content/browser/loader/upload_data_stream_builder.h"
#include <stdint.h>
#include <algorithm>
#include <string>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_data_stream.h"
#include "net/base/upload_file_element_reader.h"
#include "net/log/net_log_with_source.h"
#include "services/network/public/cpp/resource_request_body.h"
#include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/blob/blob_data_handle.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/blob/upload_blob_element_reader.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
using storage::BlobDataBuilder;
using storage::BlobDataHandle;
using storage::BlobStorageContext;
namespace content {
TEST(UploadDataStreamBuilderTest, CreateUploadDataStream) {
base::test::ScopedTaskEnvironment scoped_task_environment_;
{
scoped_refptr<network::ResourceRequestBody> request_body =
new network::ResourceRequestBody;
const std::string kBlob = "blobuuid";
const std::string kBlobData = "blobdata";
const char kData[] = "123";
const base::FilePath::StringType kFilePath = FILE_PATH_LITERAL("abc");
const uint64_t kFileOffset = 10U;
const uint64_t kFileLength = 100U;
const base::Time kFileTime = base::Time::FromDoubleT(999);
const int64_t kIdentifier = 12345;
BlobStorageContext context;
auto builder = std::make_unique<BlobDataBuilder>(kBlob);
builder->AppendData(kBlobData);
std::unique_ptr<BlobDataHandle> handle =
context.AddFinishedBlob(std::move(builder));
request_body->AppendBytes(kData, base::size(kData) - 1);
request_body->AppendFileRange(base::FilePath(kFilePath), kFileOffset,
kFileLength, kFileTime);
request_body->AppendBlob(kBlob);
request_body->set_identifier(kIdentifier);
std::unique_ptr<net::UploadDataStream> upload(
UploadDataStreamBuilder::Build(
request_body.get(), &context, nullptr,
base::ThreadTaskRunnerHandle::Get().get()));
EXPECT_EQ(kIdentifier, upload->identifier());
ASSERT_TRUE(upload->GetElementReaders());
ASSERT_EQ(request_body->elements()->size(),
upload->GetElementReaders()->size());
const net::UploadBytesElementReader* r1 =
(*upload->GetElementReaders())[0]->AsBytesReader();
ASSERT_TRUE(r1);
EXPECT_EQ(kData, std::string(r1->bytes(), r1->length()));
const net::UploadFileElementReader* r2 =
(*upload->GetElementReaders())[1]->AsFileReader();
ASSERT_TRUE(r2);
EXPECT_EQ(kFilePath, r2->path().value());
EXPECT_EQ(kFileOffset, r2->range_offset());
EXPECT_EQ(kFileLength, r2->range_length());
EXPECT_EQ(kFileTime, r2->expected_modification_time());
const storage::UploadBlobElementReader* r3 =
static_cast<storage::UploadBlobElementReader*>(
(*upload->GetElementReaders())[2].get());
ASSERT_TRUE(r3);
EXPECT_EQ("blobuuid", r3->uuid());
}
// Clean up for ASAN.
base::RunLoop().RunUntilIdle();
}
TEST(UploadDataStreamBuilderTest,
WriteUploadDataStreamWithEmptyFileBackedBlob) {
base::test::ScopedTaskEnvironment scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::IO);
{
base::FilePath test_blob_path;
ASSERT_TRUE(base::CreateTemporaryFile(&test_blob_path));
const uint64_t kZeroLength = 0;
base::Time blob_time;
ASSERT_TRUE(
base::Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", &blob_time));
ASSERT_TRUE(base::TouchFile(test_blob_path, blob_time, blob_time));
BlobStorageContext blob_storage_context;
// A blob created from an empty file added several times.
const std::string blob_id("id-0");
std::unique_ptr<BlobDataBuilder> blob_data_builder(
new BlobDataBuilder(blob_id));
blob_data_builder->AppendFile(test_blob_path, 0, kZeroLength, blob_time);
std::unique_ptr<BlobDataHandle> handle =
blob_storage_context.AddFinishedBlob(std::move(blob_data_builder));
scoped_refptr<network::ResourceRequestBody> request_body(
new network::ResourceRequestBody());
std::unique_ptr<net::UploadDataStream> upload(
UploadDataStreamBuilder::Build(
request_body.get(), &blob_storage_context, nullptr,
base::ThreadTaskRunnerHandle::Get().get()));
request_body = new network::ResourceRequestBody();
request_body->AppendBlob(blob_id);
request_body->AppendBlob(blob_id);
request_body->AppendBlob(blob_id);
upload = UploadDataStreamBuilder::Build(
request_body.get(), &blob_storage_context, nullptr,
base::ThreadTaskRunnerHandle::Get().get());
ASSERT_TRUE(upload->GetElementReaders());
const auto& readers = *upload->GetElementReaders();
ASSERT_EQ(3U, readers.size());
net::TestCompletionCallback init_callback;
ASSERT_EQ(net::ERR_IO_PENDING,
upload->Init(init_callback.callback(), net::NetLogWithSource()));
EXPECT_EQ(net::OK, init_callback.WaitForResult());
EXPECT_EQ(kZeroLength, upload->size());
// Purposely (try to) read more than what is in the stream. If we try to
// read zero bytes then UploadDataStream::Read will fail a DCHECK.
int kBufferLength = kZeroLength + 1;
std::unique_ptr<char[]> buffer(new char[kBufferLength]);
scoped_refptr<net::IOBuffer> io_buffer =
base::MakeRefCounted<net::WrappedIOBuffer>(buffer.get());
net::TestCompletionCallback read_callback;
int result =
upload->Read(io_buffer.get(), kBufferLength, read_callback.callback());
EXPECT_EQ(static_cast<int>(kZeroLength), read_callback.GetResult(result));
base::DeleteFile(test_blob_path, false);
}
// Clean up for ASAN.
base::RunLoop().RunUntilIdle();
}
TEST(UploadDataStreamBuilderTest, ResetUploadStreamWithBlob) {
base::test::ScopedTaskEnvironment scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::IO);
{
scoped_refptr<network::ResourceRequestBody> request_body =
new network::ResourceRequestBody;
const std::string kBlob = "blobuuid";
const std::string kBlobData = "blobdata";
const int kBlobDataLength = 8;
const int64_t kIdentifier = 12345;
BlobStorageContext blob_storage_context;
auto builder = std::make_unique<BlobDataBuilder>(kBlob);
builder->AppendData(kBlobData);
std::unique_ptr<BlobDataHandle> handle =
blob_storage_context.AddFinishedBlob(std::move(builder));
request_body->AppendBlob(kBlob);
request_body->set_identifier(kIdentifier);
std::unique_ptr<net::UploadDataStream> upload(
UploadDataStreamBuilder::Build(
request_body.get(), &blob_storage_context, nullptr,
base::ThreadTaskRunnerHandle::Get().get()));
net::TestCompletionCallback init_callback;
ASSERT_EQ(net::OK,
upload->Init(init_callback.callback(), net::NetLogWithSource()));
// Read part of the data.
const int kBufferLength = 4;
scoped_refptr<net::IOBufferWithSize> buffer =
base::MakeRefCounted<net::IOBufferWithSize>(kBufferLength);
net::TestCompletionCallback read_callback;
int result =
upload->Read(buffer.get(), buffer->size(), read_callback.callback());
EXPECT_EQ(kBufferLength, read_callback.GetResult(result));
EXPECT_EQ(0,
std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size()));
// Reset.
ASSERT_EQ(net::OK,
upload->Init(init_callback.callback(), net::NetLogWithSource()));
// Read all the data.
buffer = base::MakeRefCounted<net::IOBufferWithSize>(kBlobDataLength);
result =
upload->Read(buffer.get(), buffer->size(), read_callback.callback());
EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result));
EXPECT_EQ(0,
std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size()));
}
// Clean up for ASAN.
base::RunLoop().RunUntilIdle();
}
} // namespace content
......@@ -1647,7 +1647,6 @@ test("content_unittests") {
"../browser/loader/navigation_url_loader_impl_unittest.cc",
"../browser/loader/navigation_url_loader_unittest.cc",
"../browser/loader/source_stream_to_data_pipe_unittest.cc",
"../browser/loader/upload_data_stream_builder_unittest.cc",
"../browser/manifest/manifest_icon_downloader_unittest.cc",
"../browser/media/audible_metrics_unittest.cc",
"../browser/media/audio_input_stream_broker_unittest.cc",
......
......@@ -53,8 +53,6 @@ jumbo_component("browser") {
"blob/shareable_blob_data_item.h",
"blob/shareable_file_reference.cc",
"blob/shareable_file_reference.h",
"blob/upload_blob_element_reader.cc",
"blob/upload_blob_element_reader.h",
"blob/view_blob_internals_job.cc",
"blob/view_blob_internals_job.h",
"database/database_quota_client.cc",
......
// Copyright 2015 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.
#include "storage/browser/blob/upload_blob_element_reader.h"
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/single_thread_task_runner.h"
#include "net/base/net_errors.h"
#include "storage/browser/blob/blob_data_handle.h"
#include "storage/browser/blob/blob_reader.h"
namespace storage {
UploadBlobElementReader::UploadBlobElementReader(
std::unique_ptr<BlobDataHandle> handle)
: handle_(std::move(handle)) {}
UploadBlobElementReader::~UploadBlobElementReader() = default;
int UploadBlobElementReader::Init(net::CompletionOnceCallback callback) {
reader_ = handle_->CreateReader();
BlobReader::Status status = reader_->CalculateSize(std::move(callback));
switch (status) {
case BlobReader::Status::NET_ERROR:
return reader_->net_error();
case BlobReader::Status::IO_PENDING:
return net::ERR_IO_PENDING;
case BlobReader::Status::DONE:
return net::OK;
}
NOTREACHED();
return net::ERR_FAILED;
}
uint64_t UploadBlobElementReader::GetContentLength() const {
return reader_->total_size();
}
uint64_t UploadBlobElementReader::BytesRemaining() const {
return reader_->remaining_bytes();
}
bool UploadBlobElementReader::IsInMemory() const {
return reader_->IsInMemory();
}
int UploadBlobElementReader::Read(net::IOBuffer* buf,
int buf_length,
net::CompletionOnceCallback callback) {
int length = 0;
BlobReader::Status status =
reader_->Read(buf, buf_length, &length, std::move(callback));
switch (status) {
case BlobReader::Status::NET_ERROR:
return reader_->net_error();
case BlobReader::Status::IO_PENDING:
return net::ERR_IO_PENDING;
case BlobReader::Status::DONE:
return length;
}
NOTREACHED();
return net::ERR_FAILED;
}
const std::string& UploadBlobElementReader::uuid() const {
return handle_->uuid();
}
} // namespace storage
// Copyright 2015 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 STORAGE_BROWSER_BLOB_UPLOAD_BLOB_ELEMENT_READER_H_
#define STORAGE_BROWSER_BLOB_UPLOAD_BLOB_ELEMENT_READER_H_
#include <stdint.h>
#include <memory>
#include "base/component_export.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "net/base/completion_once_callback.h"
#include "net/base/upload_element_reader.h"
namespace net {
class IOBuffer;
}
namespace storage {
class BlobDataHandle;
class BlobReader;
// This class is a wrapper around the BlobReader to make it conform
// to the net::UploadElementReader interface, and it also holds around the
// handle to the blob so it stays in memory while we read it.
class COMPONENT_EXPORT(STORAGE_BROWSER) UploadBlobElementReader
: public net::UploadElementReader {
public:
explicit UploadBlobElementReader(std::unique_ptr<BlobDataHandle> handle);
~UploadBlobElementReader() override;
int Init(net::CompletionOnceCallback callback) override;
uint64_t GetContentLength() const override;
uint64_t BytesRemaining() const override;
bool IsInMemory() const override;
int Read(net::IOBuffer* buf,
int buf_length,
net::CompletionOnceCallback callback) override;
const std::string& uuid() const;
private:
std::unique_ptr<BlobDataHandle> handle_;
std::unique_ptr<BlobReader> reader_;
DISALLOW_COPY_AND_ASSIGN(UploadBlobElementReader);
};
} // namespace storage
#endif // STORAGE_BROWSER_BLOB_UPLOAD_BLOB_ELEMENT_READER_H_
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