summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-02 11:02:30 +0000
committertyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-02 11:02:30 +0000
commit8d0c23eeb75151fc39ec6db2f58bcac097904bf4 (patch)
tree0fce5027e9b934673011b446d9cae52801c1c3b5
parent88a6f537e7b56479f2e758cea80029468011daec (diff)
downloadchromium_src-8d0c23eeb75151fc39ec6db2f58bcac097904bf4.zip
chromium_src-8d0c23eeb75151fc39ec6db2f58bcac097904bf4.tar.gz
chromium_src-8d0c23eeb75151fc39ec6db2f58bcac097904bf4.tar.bz2
Make ByteStream independent from DownloadInterruptReason
Change status type to int to make it portable to other component. After this change, ByteStream could be moved under src/net/base/ or src/base directory. - Comment fix (MaybePostToPeer -> Write) BUG=169957 Review URL: https://chromiumcodereview.appspot.com/18284005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215265 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/byte_stream.cc32
-rw-r--r--content/browser/byte_stream.h19
-rw-r--r--content/browser/byte_stream_unittest.cc32
-rw-r--r--content/browser/download/download_file_impl.cc3
-rw-r--r--content/browser/download/download_file_unittest.cc2
-rw-r--r--content/browser/streams/stream.cc2
6 files changed, 44 insertions, 46 deletions
diff --git a/content/browser/byte_stream.cc b/content/browser/byte_stream.cc
index 8031815..d1f5e17 100644
--- a/content/browser/byte_stream.cc
+++ b/content/browser/byte_stream.cc
@@ -56,7 +56,7 @@ class ByteStreamWriterImpl : public ByteStreamWriter {
virtual bool Write(scoped_refptr<net::IOBuffer> buffer,
size_t byte_count) OVERRIDE;
virtual void Flush() OVERRIDE;
- virtual void Close(DownloadInterruptReason status) OVERRIDE;
+ virtual void Close(int status) OVERRIDE;
virtual void RegisterCallback(const base::Closure& source_callback) OVERRIDE;
// PostTask target from |ByteStreamReaderImpl::MaybeUpdateInput|.
@@ -68,7 +68,7 @@ class ByteStreamWriterImpl : public ByteStreamWriter {
// Called from UpdateWindow when object existence has been validated.
void UpdateWindowInternal(size_t bytes_consumed);
- void PostToPeer(bool complete, DownloadInterruptReason status);
+ void PostToPeer(bool complete, int status);
const size_t total_buffer_size_;
@@ -114,10 +114,10 @@ class ByteStreamReaderImpl : public ByteStreamReader {
// Overridden from ByteStreamReader.
virtual StreamState Read(scoped_refptr<net::IOBuffer>* data,
size_t* length) OVERRIDE;
- virtual DownloadInterruptReason GetStatus() const OVERRIDE;
+ virtual int GetStatus() const OVERRIDE;
virtual void RegisterCallback(const base::Closure& sink_callback) OVERRIDE;
- // PostTask target from |ByteStreamWriterImpl::MaybePostToPeer| and
+ // PostTask target from |ByteStreamWriterImpl::Write| and
// |ByteStreamWriterImpl::Close|.
// Receive data from our peer.
// static because it may be called after the object it is targeting
@@ -129,7 +129,7 @@ class ByteStreamReaderImpl : public ByteStreamReader {
scoped_ptr<ContentVector> transfer_buffer,
size_t transfer_buffer_bytes,
bool source_complete,
- DownloadInterruptReason status);
+ int status);
private:
// Called from TransferData once object existence has been validated.
@@ -137,7 +137,7 @@ class ByteStreamReaderImpl : public ByteStreamReader {
scoped_ptr<ContentVector> transfer_buffer,
size_t transfer_buffer_bytes,
bool source_complete,
- DownloadInterruptReason status);
+ int status);
void MaybeUpdateInput();
@@ -151,7 +151,7 @@ class ByteStreamReaderImpl : public ByteStreamReader {
ContentVector available_contents_;
bool received_status_;
- DownloadInterruptReason status_;
+ int status_;
base::Closure data_available_callback_;
@@ -211,7 +211,7 @@ bool ByteStreamWriterImpl::Write(
// Arbitrarily, we buffer to a third of the total size before sending.
if (input_contents_size_ > total_buffer_size_ / kFractionBufferBeforeSending)
- PostToPeer(false, DOWNLOAD_INTERRUPT_REASON_NONE);
+ PostToPeer(false, 0);
return (input_contents_size_ + output_size_used_ <= total_buffer_size_);
}
@@ -219,11 +219,10 @@ bool ByteStreamWriterImpl::Write(
void ByteStreamWriterImpl::Flush() {
DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
if (input_contents_size_ > 0)
- PostToPeer(false, DOWNLOAD_INTERRUPT_REASON_NONE);
+ PostToPeer(false, 0);
}
-void ByteStreamWriterImpl::Close(
- DownloadInterruptReason status) {
+void ByteStreamWriterImpl::Close(int status) {
DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
PostToPeer(true, status);
}
@@ -259,8 +258,7 @@ void ByteStreamWriterImpl::UpdateWindowInternal(size_t bytes_consumed) {
space_available_callback_.Run();
}
-void ByteStreamWriterImpl::PostToPeer(
- bool complete, DownloadInterruptReason status) {
+void ByteStreamWriterImpl::PostToPeer(bool complete, int status) {
DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
// Valid contexts in which to call.
DCHECK(complete || 0 != input_contents_size_);
@@ -293,7 +291,7 @@ ByteStreamReaderImpl::ByteStreamReaderImpl(
my_task_runner_(task_runner),
my_lifetime_flag_(lifetime_flag),
received_status_(false),
- status_(DOWNLOAD_INTERRUPT_REASON_NONE),
+ status_(0),
unreported_consumed_bytes_(0),
peer_(NULL) {
DCHECK(my_lifetime_flag_.get());
@@ -333,7 +331,7 @@ ByteStreamReaderImpl::Read(scoped_refptr<net::IOBuffer>* data,
return STREAM_EMPTY;
}
-DownloadInterruptReason ByteStreamReaderImpl::GetStatus() const {
+int ByteStreamReaderImpl::GetStatus() const {
DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
DCHECK(received_status_);
return status_;
@@ -353,7 +351,7 @@ void ByteStreamReaderImpl::TransferData(
scoped_ptr<ContentVector> transfer_buffer,
size_t buffer_size,
bool source_complete,
- DownloadInterruptReason status) {
+ int status) {
// If our target is no longer alive, do nothing.
if (!object_lifetime_flag->is_alive) return;
@@ -365,7 +363,7 @@ void ByteStreamReaderImpl::TransferDataInternal(
scoped_ptr<ContentVector> transfer_buffer,
size_t buffer_size,
bool source_complete,
- DownloadInterruptReason status) {
+ int status) {
DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
bool was_empty = available_contents_.empty();
diff --git a/content/browser/byte_stream.h b/content/browser/byte_stream.h
index 973e80573..b16664f 100644
--- a/content/browser/byte_stream.h
+++ b/content/browser/byte_stream.h
@@ -12,7 +12,7 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
-#include "content/public/browser/download_interrupt_reasons.h"
+#include "content/common/content_export.h"
#include "net/base/io_buffer.h"
namespace base {
@@ -33,8 +33,10 @@ namespace content {
// and the sink retrieves bytes already written via |ByteStreamReader::Read|.
//
// When the source has no more data to add, it will call
-// |ByteStreamWriter::Close| to indicate that. Errors at the source
-// are indicated to the sink via a non-DOWNLOAD_INTERRUPT_REASON_NONE code.
+// |ByteStreamWriter::Close| to indicate that. Operation status at the source
+// is indicated to the sink via an int passed to the Close() method and returned
+// from the GetStatus() method. Source and sink must agree on the interpretation
+// of this int.
//
// Normally the source is not managed after the relationship is setup;
// it is expected to provide data and then close itself. If an error
@@ -113,7 +115,7 @@ namespace content {
// }
//
// if (ByteStreamReader::STREAM_COMPLETE == state) {
-// DownloadInterruptReason status = reader->GetStatus();
+// int status = reader->GetStatus();
// // Process error or successful completion in |status|.
// }
//
@@ -121,7 +123,7 @@ namespace content {
// // again when there's more data.
// }
class CONTENT_EXPORT ByteStreamWriter {
-public:
+ public:
// Inverse of the fraction of the stream buffer that must be full before
// a notification is sent to paired Reader that there's more data.
static const int kFractionBufferBeforeSending;
@@ -141,9 +143,8 @@ public:
virtual void Flush() = 0;
// Signal that all data that is going to be sent, has been sent,
- // and provide a status. |DOWNLOAD_INTERRUPT_REASON_NONE| should be
- // passed for successful completion.
- virtual void Close(DownloadInterruptReason status) = 0;
+ // and provide a status.
+ virtual void Close(int status) = 0;
// Register a callback to be called when the stream transitions from
// full to having space available. The callback will always be
@@ -178,7 +179,7 @@ class CONTENT_EXPORT ByteStreamReader {
size_t* length) = 0;
// Only valid to call if Read() has returned STREAM_COMPLETE.
- virtual DownloadInterruptReason GetStatus() const = 0;
+ virtual int GetStatus() const = 0;
// Register a callback to be called when data is added or the source
// completes. The callback will be always be called on the owning
diff --git a/content/browser/byte_stream_unittest.cc b/content/browser/byte_stream_unittest.cc
index a585fb7..925467c 100644
--- a/content/browser/byte_stream_unittest.cc
+++ b/content/browser/byte_stream_unittest.cc
@@ -115,7 +115,7 @@ TEST_F(ByteStreamTest, ByteStream_PushBack) {
EXPECT_FALSE(Write(byte_stream_input.get(), 1));
EXPECT_FALSE(Write(byte_stream_input.get(), 1024));
// Flush
- byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE);
+ byte_stream_input->Close(0);
message_loop_.RunUntilIdle();
// Pull the IO buffers out; do we get the same buffers and do they
@@ -178,7 +178,7 @@ TEST_F(ByteStreamTest, ByteStream_Flush) {
EXPECT_EQ(ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
- byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE);
+ byte_stream_input->Close(0);
message_loop_.RunUntilIdle();
EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE,
@@ -251,12 +251,11 @@ TEST_F(ByteStreamTest, ByteStream_CompleteTransmits) {
3 * 1024, &byte_stream_input, &byte_stream_output);
EXPECT_EQ(ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
- byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE);
+ byte_stream_input->Close(0);
message_loop_.RunUntilIdle();
ASSERT_EQ(ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
- EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE,
- byte_stream_output->GetStatus());
+ EXPECT_EQ(0, byte_stream_output->GetStatus());
// Non-empty stream, non-error case.
CreateByteStream(
@@ -265,45 +264,44 @@ TEST_F(ByteStreamTest, ByteStream_CompleteTransmits) {
EXPECT_EQ(ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(Write(byte_stream_input.get(), 1024));
- byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE);
+ byte_stream_input->Close(0);
message_loop_.RunUntilIdle();
EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
ASSERT_EQ(ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
- EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE,
- byte_stream_output->GetStatus());
+ EXPECT_EQ(0, byte_stream_output->GetStatus());
- // Empty stream, non-error case.
+ const int kFakeErrorCode = 22;
+
+ // Empty stream, error case.
CreateByteStream(
message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
3 * 1024, &byte_stream_input, &byte_stream_output);
EXPECT_EQ(ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
- byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED);
+ byte_stream_input->Close(kFakeErrorCode);
message_loop_.RunUntilIdle();
ASSERT_EQ(ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
- EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED,
- byte_stream_output->GetStatus());
+ EXPECT_EQ(kFakeErrorCode, byte_stream_output->GetStatus());
- // Non-empty stream, non-error case.
+ // Non-empty stream, error case.
CreateByteStream(
message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
3 * 1024, &byte_stream_input, &byte_stream_output);
EXPECT_EQ(ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(Write(byte_stream_input.get(), 1024));
- byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED);
+ byte_stream_input->Close(kFakeErrorCode);
message_loop_.RunUntilIdle();
EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
ASSERT_EQ(ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
- EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED,
- byte_stream_output->GetStatus());
+ EXPECT_EQ(kFakeErrorCode, byte_stream_output->GetStatus());
}
// Confirm that callbacks on the sink side are triggered when they should be.
@@ -538,7 +536,7 @@ TEST_F(ByteStreamTest, ByteStream_ZeroCallback) {
base::Bind(CountCallbacks, &num_callbacks));
// Immediately close the stream.
- byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE);
+ byte_stream_input->Close(0);
task_runner->RunUntilIdle();
EXPECT_EQ(1, num_callbacks);
}
diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc
index edd7fed..bbe317b 100644
--- a/content/browser/download/download_file_impl.cc
+++ b/content/browser/download/download_file_impl.cc
@@ -232,7 +232,8 @@ void DownloadFileImpl::StreamActive() {
break;
case ByteStreamReader::STREAM_COMPLETE:
{
- reason = stream_reader_->GetStatus();
+ reason = static_cast<DownloadInterruptReason>(
+ stream_reader_->GetStatus());
SendUpdate();
base::TimeTicks close_start(base::TimeTicks::Now());
file_.Finish();
diff --git a/content/browser/download/download_file_unittest.cc b/content/browser/download/download_file_unittest.cc
index a3aafff..ebf501d 100644
--- a/content/browser/download/download_file_unittest.cc
+++ b/content/browser/download/download_file_unittest.cc
@@ -41,7 +41,7 @@ class MockByteStreamReader : public ByteStreamReader {
// ByteStream functions
MOCK_METHOD2(Read, ByteStreamReader::StreamState(
scoped_refptr<net::IOBuffer>*, size_t*));
- MOCK_CONST_METHOD0(GetStatus, DownloadInterruptReason());
+ MOCK_CONST_METHOD0(GetStatus, int());
MOCK_METHOD1(RegisterCallback, void(const base::Closure&));
};
diff --git a/content/browser/streams/stream.cc b/content/browser/streams/stream.cc
index 38f91b82..f1fa104 100644
--- a/content/browser/streams/stream.cc
+++ b/content/browser/streams/stream.cc
@@ -72,7 +72,7 @@ void Stream::AddData(scoped_refptr<net::IOBuffer> buffer, size_t size) {
}
void Stream::Finalize() {
- writer_->Close(DOWNLOAD_INTERRUPT_REASON_NONE);
+ writer_->Close(0);
writer_.reset(NULL);
// Continue asynchronously.