Commit 3e9fdd01 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Revert "Revert "Remove ByteStreamInputStream class""

This reverts commit 59639625.

Reason for revert: Fixing test for Chrome OS and cast

TBR=xingliu@chromium.org

Change-Id: I0a2c7aa5949e5a55ec8346fa8c673c9fb6dd7964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736987Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684187}
parent 3179e38f
...@@ -10,6 +10,10 @@ InputStream::~InputStream() = default; ...@@ -10,6 +10,10 @@ InputStream::~InputStream() = default;
void InputStream::Initialize() {} void InputStream::Initialize() {}
bool InputStream::IsEmpty() {
return true;
}
void InputStream::RegisterDataReadyCallback( void InputStream::RegisterDataReadyCallback(
const mojo::SimpleWatcher::ReadyCallback& callback) {} const mojo::SimpleWatcher::ReadyCallback& callback) {}
...@@ -17,4 +21,13 @@ void InputStream::ClearDataReadyCallback() {} ...@@ -17,4 +21,13 @@ void InputStream::ClearDataReadyCallback() {}
void InputStream::RegisterCompletionCallback(base::OnceClosure callback) {} void InputStream::RegisterCompletionCallback(base::OnceClosure callback) {}
InputStream::StreamState InputStream::Read(scoped_refptr<net::IOBuffer>* data,
size_t* length) {
return StreamState::EMPTY;
}
DownloadInterruptReason InputStream::GetCompletionStatus() {
return DOWNLOAD_INTERRUPT_REASON_NONE;
}
} // namespace download } // namespace download
...@@ -30,7 +30,7 @@ class COMPONENTS_DOWNLOAD_EXPORT InputStream { ...@@ -30,7 +30,7 @@ class COMPONENTS_DOWNLOAD_EXPORT InputStream {
virtual void Initialize(); virtual void Initialize();
// Returns true if the input stream contains no data, or false otherwise. // Returns true if the input stream contains no data, or false otherwise.
virtual bool IsEmpty() = 0; virtual bool IsEmpty();
// Register/clear callbacks when data become available. // Register/clear callbacks when data become available.
virtual void RegisterDataReadyCallback( virtual void RegisterDataReadyCallback(
...@@ -42,11 +42,10 @@ class COMPONENTS_DOWNLOAD_EXPORT InputStream { ...@@ -42,11 +42,10 @@ class COMPONENTS_DOWNLOAD_EXPORT InputStream {
// Reads data from the stream into |data|, |length| is the number of bytes // Reads data from the stream into |data|, |length| is the number of bytes
// returned. // returned.
virtual StreamState Read(scoped_refptr<net::IOBuffer>* data, virtual StreamState Read(scoped_refptr<net::IOBuffer>* data, size_t* length);
size_t* length) = 0;
// Returns the completion status. // Returns the completion status.
virtual DownloadInterruptReason GetCompletionStatus() = 0; virtual DownloadInterruptReason GetCompletionStatus();
}; };
} // namespace download } // namespace download
......
...@@ -810,14 +810,10 @@ jumbo_source_set("browser") { ...@@ -810,14 +810,10 @@ jumbo_source_set("browser") {
"dom_storage/session_storage_namespace_impl_mojo.h", "dom_storage/session_storage_namespace_impl_mojo.h",
"dom_storage/storage_area_impl.cc", "dom_storage/storage_area_impl.cc",
"dom_storage/storage_area_impl.h", "dom_storage/storage_area_impl.h",
"download/byte_stream_input_stream.cc",
"download/byte_stream_input_stream.h",
"download/download_item_utils.cc", "download/download_item_utils.cc",
"download/download_manager_impl.cc", "download/download_manager_impl.cc",
"download/download_manager_impl.h", "download/download_manager_impl.h",
"download/download_request_utils.cc", "download/download_request_utils.cc",
"download/download_utils.cc",
"download/download_utils.h",
"download/drag_download_file.cc", "download/drag_download_file.cc",
"download/drag_download_file.h", "download/drag_download_file.h",
"download/drag_download_util.cc", "download/drag_download_util.cc",
......
// Copyright 2018 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/download/byte_stream_input_stream.h"
#include "base/bind.h"
#include "components/download/public/common/download_task_runner.h"
#include "content/browser/byte_stream.h"
namespace content {
ByteStreamInputStream::ByteStreamInputStream(
std::unique_ptr<ByteStreamReader> stream_reader)
: stream_reader_(
stream_reader.release(),
base::OnTaskRunnerDeleter(download::GetDownloadTaskRunner())),
completion_status_(download::DOWNLOAD_INTERRUPT_REASON_NONE) {}
ByteStreamInputStream::~ByteStreamInputStream() = default;
bool ByteStreamInputStream::IsEmpty() {
return !stream_reader_;
}
void ByteStreamInputStream::RegisterDataReadyCallback(
const mojo::SimpleWatcher::ReadyCallback& callback) {
if (stream_reader_) {
stream_reader_->RegisterCallback(
base::BindRepeating(callback, MOJO_RESULT_OK));
}
}
void ByteStreamInputStream::ClearDataReadyCallback() {
if (stream_reader_)
stream_reader_->RegisterCallback(base::RepeatingClosure());
}
download::InputStream::StreamState ByteStreamInputStream::Read(
scoped_refptr<net::IOBuffer>* data,
size_t* length) {
if (!stream_reader_)
return download::InputStream::EMPTY;
ByteStreamReader::StreamState state = stream_reader_->Read(data, length);
switch (state) {
case ByteStreamReader::STREAM_EMPTY:
return download::InputStream::EMPTY;
case ByteStreamReader::STREAM_HAS_DATA:
return download::InputStream::HAS_DATA;
case ByteStreamReader::STREAM_COMPLETE:
completion_status_ = static_cast<download::DownloadInterruptReason>(
stream_reader_->GetStatus());
return download::InputStream::COMPLETE;
}
return download::InputStream::EMPTY;
}
download::DownloadInterruptReason ByteStreamInputStream::GetCompletionStatus() {
return completion_status_;
}
} // namespace content
// Copyright 2018 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_DOWNLOAD_BYTE_STREAM_INPUT_STREAM_H_
#define CONTENT_BROWSER_DOWNLOAD_BYTE_STREAM_INPUT_STREAM_H_
#include "components/download/public/common/input_stream.h"
#include "content/common/content_export.h"
namespace content {
class ByteStreamReader;
// Download input stream backed by a ByteStreamReader.
class CONTENT_EXPORT ByteStreamInputStream : public download::InputStream {
public:
explicit ByteStreamInputStream(
std::unique_ptr<ByteStreamReader> stream_reader);
~ByteStreamInputStream() override;
// download::InputStream
bool IsEmpty() override;
void RegisterDataReadyCallback(
const mojo::SimpleWatcher::ReadyCallback& callback) override;
void ClearDataReadyCallback() override;
download::InputStream::StreamState Read(scoped_refptr<net::IOBuffer>* data,
size_t* length) override;
download::DownloadInterruptReason GetCompletionStatus() override;
private:
// ByteStreamReader to read from.
std::unique_ptr<ByteStreamReader, base::OnTaskRunnerDeleter> stream_reader_;
// Status when the response completes.
download::DownloadInterruptReason completion_status_;
DISALLOW_COPY_AND_ASSIGN(ByteStreamInputStream);
};
} // namespace content
#endif // CONTENT_BROWSER_DOWNLOAD_BYTE_STREAM_INPUT_STREAM_H_
...@@ -36,14 +36,12 @@ ...@@ -36,14 +36,12 @@
#include "components/download/public/common/download_url_loader_factory_getter_impl.h" #include "components/download/public/common/download_url_loader_factory_getter_impl.h"
#include "components/download/public/common/download_url_parameters.h" #include "components/download/public/common/download_url_parameters.h"
#include "components/download/public/common/download_utils.h" #include "components/download/public/common/download_utils.h"
#include "components/download/public/common/input_stream.h"
#include "components/download/public/common/url_download_handler_factory.h" #include "components/download/public/common/url_download_handler_factory.h"
#include "content/browser/blob_storage/chrome_blob_storage_context.h" #include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/browser/byte_stream.h"
#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/data_url_loader_factory.h" #include "content/browser/data_url_loader_factory.h"
#include "content/browser/devtools/devtools_instrumentation.h" #include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/download/byte_stream_input_stream.h"
#include "content/browser/download/download_utils.h"
#include "content/browser/download/file_download_url_loader_factory_getter.h" #include "content/browser/download/file_download_url_loader_factory_getter.h"
#include "content/browser/download/file_system_download_url_loader_factory_getter.h" #include "content/browser/download/file_system_download_url_loader_factory_getter.h"
#include "content/browser/download/network_download_url_loader_factory_getter.h" #include "content/browser/download/network_download_url_loader_factory_getter.h"
...@@ -138,14 +136,12 @@ void CreateInterruptedDownload( ...@@ -138,14 +136,12 @@ void CreateInterruptedDownload(
base::Time::Now(), base::WrapUnique(new download::DownloadSaveInfo))); base::Time::Now(), base::WrapUnique(new download::DownloadSaveInfo)));
failed_created_info->url_chain.push_back(params->url()); failed_created_info->url_chain.push_back(params->url());
failed_created_info->result = reason; failed_created_info->result = reason;
std::unique_ptr<ByteStreamReader> empty_byte_stream;
base::PostTask( base::PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, {BrowserThread::UI},
base::BindOnce( base::BindOnce(&DownloadManager::StartDownload, download_manager,
&DownloadManager::StartDownload, download_manager, std::move(failed_created_info),
std::move(failed_created_info), std::make_unique<download::InputStream>(), nullptr,
std::make_unique<ByteStreamInputStream>(std::move(empty_byte_stream)), params->callback()));
nullptr, params->callback()));
} }
class DownloadItemFactoryImpl : public download::DownloadItemFactory { class DownloadItemFactoryImpl : public download::DownloadItemFactory {
......
...@@ -36,8 +36,7 @@ ...@@ -36,8 +36,7 @@
#include "components/download/public/common/download_request_handle_interface.h" #include "components/download/public/common/download_request_handle_interface.h"
#include "components/download/public/common/mock_download_file.h" #include "components/download/public/common/mock_download_file.h"
#include "components/download/public/common/mock_download_item_impl.h" #include "components/download/public/common/mock_download_item_impl.h"
#include "content/browser/byte_stream.h" #include "components/download/public/common/mock_input_stream.h"
#include "content/browser/download/byte_stream_input_stream.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/download_manager_delegate.h" #include "content/public/browser/download_manager_delegate.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
...@@ -66,7 +65,6 @@ ACTION_TEMPLATE(RunCallback, ...@@ -66,7 +65,6 @@ ACTION_TEMPLATE(RunCallback,
} }
namespace content { namespace content {
class ByteStreamReader;
namespace { namespace {
...@@ -356,14 +354,6 @@ class MockDownloadManagerObserver : public DownloadManager::Observer { ...@@ -356,14 +354,6 @@ class MockDownloadManagerObserver : public DownloadManager::Observer {
MOCK_METHOD2(SelectFileDialogDisplayed, void(DownloadManager*, int32_t)); MOCK_METHOD2(SelectFileDialogDisplayed, void(DownloadManager*, int32_t));
}; };
class MockByteStreamReader : public ByteStreamReader {
public:
~MockByteStreamReader() override {}
MOCK_METHOD2(Read, StreamState(scoped_refptr<net::IOBuffer>*, size_t*));
MOCK_CONST_METHOD0(GetStatus, int());
MOCK_METHOD1(RegisterCallback, void(const base::Closure&));
};
class TestInProgressManager : public download::InProgressDownloadManager { class TestInProgressManager : public download::InProgressDownloadManager {
public: public:
TestInProgressManager(); TestInProgressManager();
...@@ -570,7 +560,6 @@ class DownloadManagerTest : public testing::Test { ...@@ -570,7 +560,6 @@ class DownloadManagerTest : public testing::Test {
TEST_F(DownloadManagerTest, StartDownload) { TEST_F(DownloadManagerTest, StartDownload) {
std::unique_ptr<download::DownloadCreateInfo> info( std::unique_ptr<download::DownloadCreateInfo> info(
new download::DownloadCreateInfo); new download::DownloadCreateInfo);
std::unique_ptr<ByteStreamReader> stream(new MockByteStreamReader);
// Random value, a non 0 value means history db is properly loaded, and new // Random value, a non 0 value means history db is properly loaded, and new
// downloads should be persisted to the in-progress db. // downloads should be persisted to the in-progress db.
uint32_t local_id(5); uint32_t local_id(5);
...@@ -592,8 +581,8 @@ TEST_F(DownloadManagerTest, StartDownload) { ...@@ -592,8 +581,8 @@ TEST_F(DownloadManagerTest, StartDownload) {
ApplicationClientIdForFileScanning()) ApplicationClientIdForFileScanning())
.WillRepeatedly(Return("client-id")); .WillRepeatedly(Return("client-id"));
download::MockDownloadFile* mock_file = new download::MockDownloadFile; download::MockDownloadFile* mock_file = new download::MockDownloadFile;
auto input_stream = auto input_stream = std::make_unique<download::MockInputStream>();
std::make_unique<ByteStreamInputStream>(std::move(stream)); EXPECT_CALL(*input_stream, IsEmpty()).WillRepeatedly(Return(false));
EXPECT_CALL(*mock_download_file_factory_.get(), EXPECT_CALL(*mock_download_file_factory_.get(),
MockCreateFile(Ref(*info->save_info.get()), input_stream.get())) MockCreateFile(Ref(*info->save_info.get()), input_stream.get()))
.WillOnce(Return(mock_file)); .WillOnce(Return(mock_file));
...@@ -610,7 +599,6 @@ TEST_F(DownloadManagerTest, StartDownload) { ...@@ -610,7 +599,6 @@ TEST_F(DownloadManagerTest, StartDownload) {
TEST_F(DownloadManagerTest, StartDownloadWithoutHistoryDB) { TEST_F(DownloadManagerTest, StartDownloadWithoutHistoryDB) {
std::unique_ptr<download::DownloadCreateInfo> info( std::unique_ptr<download::DownloadCreateInfo> info(
new download::DownloadCreateInfo); new download::DownloadCreateInfo);
std::unique_ptr<ByteStreamReader> stream(new MockByteStreamReader);
base::FilePath download_path(FILE_PATH_LITERAL("download/path")); base::FilePath download_path(FILE_PATH_LITERAL("download/path"));
OnInProgressDownloadManagerInitialized(); OnInProgressDownloadManagerInitialized();
EXPECT_FALSE(download_manager_->GetDownload(1)); EXPECT_FALSE(download_manager_->GetDownload(1));
...@@ -629,8 +617,8 @@ TEST_F(DownloadManagerTest, StartDownloadWithoutHistoryDB) { ...@@ -629,8 +617,8 @@ TEST_F(DownloadManagerTest, StartDownloadWithoutHistoryDB) {
ApplicationClientIdForFileScanning()) ApplicationClientIdForFileScanning())
.WillRepeatedly(Return("client-id")); .WillRepeatedly(Return("client-id"));
download::MockDownloadFile* mock_file = new download::MockDownloadFile; download::MockDownloadFile* mock_file = new download::MockDownloadFile;
auto input_stream = auto input_stream = std::make_unique<download::MockInputStream>();
std::make_unique<ByteStreamInputStream>(std::move(stream)); EXPECT_CALL(*input_stream, IsEmpty()).WillRepeatedly(Return(false));
EXPECT_CALL(*mock_download_file_factory_.get(), EXPECT_CALL(*mock_download_file_factory_.get(),
MockCreateFile(Ref(*info->save_info.get()), input_stream.get())) MockCreateFile(Ref(*info->save_info.get()), input_stream.get()))
.WillOnce(Return(mock_file)); .WillOnce(Return(mock_file));
......
// Copyright 2017 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/download/download_utils.h"
#include "base/format_macros.h"
#include "base/process/process_handle.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/stringprintf.h"
#include "base/task/post_task.h"
#include "components/download/database/in_progress/download_entry.h"
#include "components/download/public/common/download_create_info.h"
#include "components/download/public/common/download_interrupt_reasons_utils.h"
#include "components/download/public/common/download_save_info.h"
#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/resource_context_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/download_manager_delegate.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "net/base/elements_upload_data_stream.h"
#include "net/base/upload_bytes_element_reader.h"
#include "net/http/http_request_headers.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
namespace content {
storage::BlobStorageContext* BlobStorageContextGetter(
ResourceContext* resource_context) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ChromeBlobStorageContext* blob_context =
GetChromeBlobStorageContextForResourceContext(resource_context);
return blob_context->context();
}
} // namespace content
// Copyright 2017 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_DOWNLOAD_DOWNLOAD_UTILS_H_
#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_UTILS_H_
#include <memory>
#include "base/memory/ref_counted.h"
#include "base/optional.h"
#include "content/common/content_export.h"
namespace storage {
class BlobStorageContext;
}
namespace content {
class ResourceContext;
storage::BlobStorageContext* BlobStorageContextGetter(
ResourceContext* resource_context);
} // namespace content
#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_UTILS_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