summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Murphy <dmurph@chromium.org>2015-12-22 16:11:05 -0800
committerDaniel Murphy <dmurph@chromium.org>2015-12-23 00:13:04 +0000
commit1152c76dea7c82b846569958886b6cbb0b9a1a43 (patch)
tree0224289fb757d1fe847cc9906152439b0a162035
parenta6418335744aa31db28d17257daefac1bf3c23ac (diff)
downloadchromium_src-1152c76dea7c82b846569958886b6cbb0b9a1a43.zip
chromium_src-1152c76dea7c82b846569958886b6cbb0b9a1a43.tar.gz
chromium_src-1152c76dea7c82b846569958886b6cbb0b9a1a43.tar.bz2
[Blob] Fix for resetting reader.
TBR=michaeln@chromium.org,mmenke@chromium.org BUG=567692 Committed-First-Time: https://crrev.com/ebf7a6b19a7a468195a5606fbd2bbd6d07a26ea2 Cr-Commit-Position-First-Time: refs/heads/master@{#365177} Review URL: https://codereview.chromium.org/1513783005 Cr-Commit-Position: refs/heads/master@{#365316} (cherry picked from commit f01c1228c9cca9b4078443438dfa868f7b972ac2) Conflicts: content/browser/loader/upload_data_stream_builder.cc Review URL: https://codereview.chromium.org/1539693003 . Cr-Commit-Position: refs/branch-heads/2564@{#384} Cr-Branched-From: 1283eca15bd9f772387f75241576cde7bdec7f54-refs/heads/master@{#359700} (cherry picked from commit 0ee4d4457a902c929814b17eab584fd2c94794d1) Review URL: https://codereview.chromium.org/1543073002 . Cr-Commit-Position: refs/branch-heads/2526@{#538} Cr-Branched-From: cb947c0153db0ec02a8abbcb3ca086d88bf6006f-refs/heads/master@{#352221}
-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 12b4b80..2f30f94 100644
--- a/content/browser/loader/upload_data_stream_builder.cc
+++ b/content/browser/loader/upload_data_stream_builder.cc
@@ -104,10 +104,8 @@ 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(new storage::UploadBlobElementReader(
- handle_ptr->CreateReader(file_system_context, file_task_runner),
- handle.Pass()));
+ handle.Pass(), 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 e323a4e..ae79dd9 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);
};