Commit 59639625 authored by Findit's avatar Findit

Revert "Remove ByteStreamInputStream class"

This reverts commit 4020c38f.

Reason for revert:

Findit (https://goo.gl/kROfz5) identified CL at revision 684103 as the
culprit for failures in the build cycles as shown on:
https://analysis.chromium.org/waterfall/culprit?key=ag9zfmZpbmRpdC1mb3ItbWVyRAsSDVdmU3VzcGVjdGVkQ0wiMWNocm9taXVtLzQwMjBjMzhmZmVkOWIzYWRhMWMyMTZjYjM0NTE2NDQwNWQ1ZmNlOGEM

Sample Failed Build: https://ci.chromium.org/buildbot/chromium.linux/Cast%20Audio%20Linux/49342

Sample Failed Step: content_unittests

Original change's description:
> Remove ByteStreamInputStream class
> 
> This class was previously used by DownloadRequestCore in
> non network service code path. We no longer need this now.
> 
> BUG=934009
> 
> Change-Id: I827d2f644eed739fd95f544b3f402e1bc7e957f7
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1733420
> Commit-Queue: Min Qin <qinmin@chromium.org>
> Reviewed-by: Xing Liu <xingliu@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#684103}


No-Presubmit: true
No-Tree-Checks: true
No-Try: true
BUG=934009

Change-Id: I3defc99d39a42b49118f38196956911fa78e2c57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1737626
Cr-Commit-Position: refs/heads/master@{#684139}
parent 73d3b625
......@@ -10,10 +10,6 @@ InputStream::~InputStream() = default;
void InputStream::Initialize() {}
bool InputStream::IsEmpty() {
return true;
}
void InputStream::RegisterDataReadyCallback(
const mojo::SimpleWatcher::ReadyCallback& callback) {}
......@@ -21,13 +17,4 @@ void InputStream::ClearDataReadyCallback() {}
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
......@@ -30,7 +30,7 @@ class COMPONENTS_DOWNLOAD_EXPORT InputStream {
virtual void Initialize();
// Returns true if the input stream contains no data, or false otherwise.
virtual bool IsEmpty();
virtual bool IsEmpty() = 0;
// Register/clear callbacks when data become available.
virtual void RegisterDataReadyCallback(
......@@ -42,10 +42,11 @@ class COMPONENTS_DOWNLOAD_EXPORT InputStream {
// Reads data from the stream into |data|, |length| is the number of bytes
// returned.
virtual StreamState Read(scoped_refptr<net::IOBuffer>* data, size_t* length);
virtual StreamState Read(scoped_refptr<net::IOBuffer>* data,
size_t* length) = 0;
// Returns the completion status.
virtual DownloadInterruptReason GetCompletionStatus();
virtual DownloadInterruptReason GetCompletionStatus() = 0;
};
} // namespace download
......
......@@ -810,10 +810,14 @@ jumbo_source_set("browser") {
"dom_storage/session_storage_namespace_impl_mojo.h",
"dom_storage/storage_area_impl.cc",
"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_manager_impl.cc",
"download/download_manager_impl.h",
"download/download_request_utils.cc",
"download/download_utils.cc",
"download/download_utils.h",
"download/drag_download_file.cc",
"download/drag_download_file.h",
"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,12 +36,14 @@
#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_utils.h"
#include "components/download/public/common/input_stream.h"
#include "components/download/public/common/url_download_handler_factory.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/data_url_loader_factory.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_system_download_url_loader_factory_getter.h"
#include "content/browser/download/network_download_url_loader_factory_getter.h"
......@@ -136,12 +138,14 @@ void CreateInterruptedDownload(
base::Time::Now(), base::WrapUnique(new download::DownloadSaveInfo)));
failed_created_info->url_chain.push_back(params->url());
failed_created_info->result = reason;
std::unique_ptr<ByteStreamReader> empty_byte_stream;
base::PostTask(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&DownloadManager::StartDownload, download_manager,
std::move(failed_created_info),
std::make_unique<download::InputStream>(), nullptr,
params->callback()));
base::BindOnce(
&DownloadManager::StartDownload, download_manager,
std::move(failed_created_info),
std::make_unique<ByteStreamInputStream>(std::move(empty_byte_stream)),
nullptr, params->callback()));
}
class DownloadItemFactoryImpl : public download::DownloadItemFactory {
......
......@@ -36,7 +36,8 @@
#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_item_impl.h"
#include "components/download/public/common/mock_input_stream.h"
#include "content/browser/byte_stream.h"
#include "content/browser/download/byte_stream_input_stream.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_manager_delegate.h"
#include "content/public/browser/storage_partition.h"
......@@ -65,6 +66,7 @@ ACTION_TEMPLATE(RunCallback,
}
namespace content {
class ByteStreamReader;
namespace {
......@@ -354,6 +356,14 @@ class MockDownloadManagerObserver : public DownloadManager::Observer {
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 {
public:
TestInProgressManager();
......@@ -560,6 +570,7 @@ class DownloadManagerTest : public testing::Test {
TEST_F(DownloadManagerTest, StartDownload) {
std::unique_ptr<download::DownloadCreateInfo> info(
new download::DownloadCreateInfo);
std::unique_ptr<ByteStreamReader> stream(new MockByteStreamReader);
// Random value, a non 0 value means history db is properly loaded, and new
// downloads should be persisted to the in-progress db.
uint32_t local_id(5);
......@@ -581,8 +592,8 @@ TEST_F(DownloadManagerTest, StartDownload) {
ApplicationClientIdForFileScanning())
.WillRepeatedly(Return("client-id"));
download::MockDownloadFile* mock_file = new download::MockDownloadFile;
auto input_stream = std::make_unique<download::MockInputStream>();
EXPECT_CALL(*input_stream, IsEmpty()).WillOnce(Return(false));
auto input_stream =
std::make_unique<ByteStreamInputStream>(std::move(stream));
EXPECT_CALL(*mock_download_file_factory_.get(),
MockCreateFile(Ref(*info->save_info.get()), input_stream.get()))
.WillOnce(Return(mock_file));
......@@ -599,6 +610,7 @@ TEST_F(DownloadManagerTest, StartDownload) {
TEST_F(DownloadManagerTest, StartDownloadWithoutHistoryDB) {
std::unique_ptr<download::DownloadCreateInfo> info(
new download::DownloadCreateInfo);
std::unique_ptr<ByteStreamReader> stream(new MockByteStreamReader);
base::FilePath download_path(FILE_PATH_LITERAL("download/path"));
OnInProgressDownloadManagerInitialized();
EXPECT_FALSE(download_manager_->GetDownload(1));
......@@ -617,8 +629,8 @@ TEST_F(DownloadManagerTest, StartDownloadWithoutHistoryDB) {
ApplicationClientIdForFileScanning())
.WillRepeatedly(Return("client-id"));
download::MockDownloadFile* mock_file = new download::MockDownloadFile;
auto input_stream = std::make_unique<download::MockInputStream>();
EXPECT_CALL(*input_stream, IsEmpty()).WillOnce(Return(false));
auto input_stream =
std::make_unique<ByteStreamInputStream>(std::move(stream));
EXPECT_CALL(*mock_download_file_factory_.get(),
MockCreateFile(Ref(*info->save_info.get()), input_stream.get()))
.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