summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/loader/upload_data_stream_builder.cc4
-rw-r--r--content/browser/loader/upload_data_stream_builder_unittest.cc51
-rw-r--r--storage/browser/blob/upload_blob_element_reader.cc13
-rw-r--r--storage/browser/blob/upload_blob_element_reader.h15
4 files changed, 74 insertions, 9 deletions
diff --git a/content/browser/loader/upload_data_stream_builder.cc b/content/browser/loader/upload_data_stream_builder.cc
index 7f6b517..981d973 100644
--- a/content/browser/loader/upload_data_stream_builder.cc
+++ b/content/browser/loader/upload_data_stream_builder.cc
@@ -102,11 +102,9 @@ scoped_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build(
DCHECK_EQ(0ul, element.offset());
scoped_ptr<storage::BlobDataHandle> handle =
blob_context->GetBlobDataFromUUID(element.blob_uuid());
- storage::BlobDataHandle* handle_ptr = handle.get();
element_readers.push_back(
make_scoped_ptr(new storage::UploadBlobElementReader(
- handle_ptr->CreateReader(file_system_context, file_task_runner),
- std::move(handle))));
+ std::move(handle), file_system_context, file_task_runner)));
break;
}
case ResourceRequestBody::Element::TYPE_DISK_CACHE_ENTRY:
diff --git a/content/browser/loader/upload_data_stream_builder_unittest.cc b/content/browser/loader/upload_data_stream_builder_unittest.cc
index c8f6b77..f31e284 100644
--- a/content/browser/loader/upload_data_stream_builder_unittest.cc
+++ b/content/browser/loader/upload_data_stream_builder_unittest.cc
@@ -149,4 +149,55 @@ TEST(UploadDataStreamBuilderTest,
// Clean up for ASAN.
base::RunLoop().RunUntilIdle();
}
+
+TEST(UploadDataStreamBuilderTest, ResetUploadStreamWithBlob) {
+ base::MessageLoopForIO message_loop;
+ {
+ scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody;
+
+ const std::string kBlob = "blobuuid";
+ const std::string kBlobData = "blobdata";
+ const int kBlobDataLength = 8;
+ const int64 kIdentifier = 12345;
+
+ BlobStorageContext blob_storage_context;
+ BlobDataBuilder builder(kBlob);
+ builder.AppendData(kBlobData);
+ scoped_ptr<BlobDataHandle> handle =
+ blob_storage_context.AddFinishedBlob(&builder);
+ request_body->AppendBlob(kBlob);
+ request_body->set_identifier(kIdentifier);
+
+ scoped_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()));
+
+ // Read part of the data.
+ const int kBufferLength = 4;
+ scoped_refptr<net::IOBufferWithSize> buffer(
+ new 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()));
+
+ // Read all the data.
+ buffer = new 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
diff --git a/storage/browser/blob/upload_blob_element_reader.cc b/storage/browser/blob/upload_blob_element_reader.cc
index dd0058f..e4d6d4a 100644
--- a/storage/browser/blob/upload_blob_element_reader.cc
+++ b/storage/browser/blob/upload_blob_element_reader.cc
@@ -4,20 +4,27 @@
#include "storage/browser/blob/upload_blob_element_reader.h"
+#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"
+#include "storage/browser/fileapi/file_system_context.h"
namespace storage {
UploadBlobElementReader::UploadBlobElementReader(
- scoped_ptr<storage::BlobReader> reader,
- scoped_ptr<BlobDataHandle> handle)
- : reader_(reader.Pass()), handle_(handle.Pass()) {}
+ scoped_ptr<BlobDataHandle> handle,
+ FileSystemContext* file_system_context,
+ base::SingleThreadTaskRunner* file_task_runner)
+ : handle_(handle.Pass()),
+ file_system_context_(file_system_context),
+ file_runner_(file_task_runner) {}
UploadBlobElementReader::~UploadBlobElementReader() {}
int UploadBlobElementReader::Init(const net::CompletionCallback& callback) {
+ reader_ =
+ handle_->CreateReader(file_system_context_.get(), file_runner_.get());
BlobReader::Status status = reader_->CalculateSize(callback);
switch (status) {
case BlobReader::Status::NET_ERROR:
diff --git a/storage/browser/blob/upload_blob_element_reader.h b/storage/browser/blob/upload_blob_element_reader.h
index 72b7244..47ff90d 100644
--- a/storage/browser/blob/upload_blob_element_reader.h
+++ b/storage/browser/blob/upload_blob_element_reader.h
@@ -6,11 +6,16 @@
#define STORAGE_BROWSER_BLOB_UPLOAD_BLOB_ELEMENT_READER_H_
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "net/base/completion_callback.h"
#include "net/base/upload_element_reader.h"
#include "storage/browser/storage_browser_export.h"
+namespace base {
+class SingleThreadTaskRunner;
+}
+
namespace net {
class IOBuffer;
}
@@ -18,6 +23,7 @@ class IOBuffer;
namespace storage {
class BlobDataHandle;
class BlobReader;
+class FileSystemContext;
// This class is a wrapper around the BlobReader to make it conform
// to the net::UploadElementReader interface, and it also holds around the
@@ -25,8 +31,9 @@ class BlobReader;
class STORAGE_EXPORT UploadBlobElementReader
: NON_EXPORTED_BASE(public net::UploadElementReader) {
public:
- UploadBlobElementReader(scoped_ptr<BlobReader> reader,
- scoped_ptr<BlobDataHandle> handle);
+ UploadBlobElementReader(scoped_ptr<BlobDataHandle> handle,
+ FileSystemContext* file_system_context,
+ base::SingleThreadTaskRunner* file_task_runner);
~UploadBlobElementReader() override;
int Init(const net::CompletionCallback& callback) override;
@@ -44,8 +51,10 @@ class STORAGE_EXPORT UploadBlobElementReader
const std::string& uuid() const;
private:
- scoped_ptr<BlobReader> reader_;
scoped_ptr<BlobDataHandle> handle_;
+ scoped_refptr<FileSystemContext> file_system_context_;
+ scoped_refptr<base::SingleThreadTaskRunner> file_runner_;
+ scoped_ptr<BlobReader> reader_;
DISALLOW_COPY_AND_ASSIGN(UploadBlobElementReader);
};