Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: webkit/blob/blob_url_request_job.cc

Issue 11103027: Support filesystem files from BlobURLRequestJob (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/blob/blob_url_request_job.h ('k') | webkit/blob/blob_url_request_job_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/blob/blob_url_request_job.cc
diff --git a/webkit/blob/blob_url_request_job.cc b/webkit/blob/blob_url_request_job.cc
index 07a4fc46c98286fbd16d573e3dbcda17f2fd8f18..279c1eec64f6e2e218bc1933d959db17d629ffc0 100644
--- a/webkit/blob/blob_url_request_job.cc
+++ b/webkit/blob/blob_url_request_job.cc
@@ -22,6 +22,8 @@
#include "net/url_request/url_request_error_job.h"
#include "net/url_request/url_request_status.h"
#include "webkit/blob/local_file_stream_reader.h"
+#include "webkit/fileapi/file_system_context.h"
+#include "webkit/fileapi/file_system_url.h"
namespace webkit_blob {
@@ -44,16 +46,28 @@ const char kHTTPRequestedRangeNotSatisfiableText[] =
"Requested Range Not Satisfiable";
const char kHTTPInternalErrorText[] = "Internal Server Error";
+bool IsFileType(BlobData::Item::Type type) {
+ switch (type) {
+ case BlobData::Item::TYPE_FILE:
+ case BlobData::Item::TYPE_FILE_FILESYSTEM:
+ return true;
+ default:
+ return false;
+ }
+}
+
} // namespace
BlobURLRequestJob::BlobURLRequestJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
BlobData* blob_data,
+ fileapi::FileSystemContext* file_system_context,
base::MessageLoopProxy* file_thread_proxy)
: net::URLRequestJob(request, network_delegate),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
blob_data_(blob_data),
+ file_system_context_(file_system_context),
file_thread_proxy_(file_thread_proxy),
total_size_(0),
remaining_bytes_(0),
@@ -177,7 +191,7 @@ void BlobURLRequestJob::CountSize() {
for (size_t i = 0; i < blob_data_->items().size(); ++i) {
const BlobData::Item& item = blob_data_->items().at(i);
- if (item.type() == BlobData::Item::TYPE_FILE) {
+ if (IsFileType(item.type())) {
++pending_get_file_info_count_;
GetFileStreamReader(i)->GetLength(
base::Bind(&BlobURLRequestJob::DidGetFileItemLength,
@@ -235,7 +249,7 @@ void BlobURLRequestJob::DidGetFileItemLength(size_t index, int64 result) {
DCHECK_LT(index, blob_data_->items().size());
const BlobData::Item& item = blob_data_->items().at(index);
- DCHECK(item.type() == BlobData::Item::TYPE_FILE);
+ DCHECK(IsFileType(item.type()));
// If item length is -1, we need to use the file size being resolved
// in the real time.
@@ -269,7 +283,7 @@ void BlobURLRequestJob::Seek(int64 offset) {
// Adjust the offset of the first stream if it is of file type.
const BlobData::Item& item = blob_data_->items().at(current_item_index_);
- if (item.type() == BlobData::Item::TYPE_FILE) {
+ if (IsFileType(item.type())) {
DeleteCurrentFileReader();
CreateFileStreamReader(current_item_index_, offset);
}
@@ -298,19 +312,14 @@ bool BlobURLRequestJob::ReadItem() {
// Do the reading.
const BlobData::Item& item = blob_data_->items().at(current_item_index_);
- switch (item.type()) {
- case BlobData::Item::TYPE_BYTES:
- return ReadBytesItem(item, bytes_to_read);
- case BlobData::Item::TYPE_FILE:
- return ReadFileItem(GetFileStreamReader(current_item_index_),
- bytes_to_read);
- case BlobData::Item::TYPE_FILE_FILESYSTEM:
- // TODO(kinuko): Support TYPE_FILE_FILESYSTEM case.
- // http://crbug.com/141835
- default:
- DCHECK(false);
- return false;
+ if (item.type() == BlobData::Item::TYPE_BYTES)
+ return ReadBytesItem(item, bytes_to_read);
+ if (IsFileType(item.type())) {
+ return ReadFileItem(GetFileStreamReader(current_item_index_),
+ bytes_to_read);
}
+ NOTREACHED();
+ return false;
}
void BlobURLRequestJob::AdvanceItem() {
@@ -351,7 +360,7 @@ bool BlobURLRequestJob::ReadBytesItem(const BlobData::Item& item,
return true;
}
-bool BlobURLRequestJob::ReadFileItem(LocalFileStreamReader* reader,
+bool BlobURLRequestJob::ReadFileItem(FileStreamReader* reader,
int bytes_to_read) {
DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read);
DCHECK(reader);
@@ -524,10 +533,10 @@ void BlobURLRequestJob::HeadersCompleted(int status_code,
NotifyHeadersComplete();
}
-LocalFileStreamReader* BlobURLRequestJob::GetFileStreamReader(size_t index) {
+FileStreamReader* BlobURLRequestJob::GetFileStreamReader(size_t index) {
DCHECK_LT(index, blob_data_->items().size());
const BlobData::Item& item = blob_data_->items().at(index);
- if (item.type() != BlobData::Item::TYPE_FILE)
+ if (!IsFileType(item.type()))
return NULL;
if (index_to_reader_.find(index) == index_to_reader_.end())
CreateFileStreamReader(index, 0);
@@ -539,15 +548,29 @@ void BlobURLRequestJob::CreateFileStreamReader(size_t index,
int64 additional_offset) {
DCHECK_LT(index, blob_data_->items().size());
const BlobData::Item& item = blob_data_->items().at(index);
- DCHECK_EQ(BlobData::Item::TYPE_FILE, item.type());
+ DCHECK(IsFileType(item.type()));
DCHECK_EQ(0U, index_to_reader_.count(index));
- // TODO(kinuko): Create appropriate FileStreamReader for TYPE_FILE_FILESYSTEM.
- // http://crbug.com/141835
- index_to_reader_[index] = new LocalFileStreamReader(
- file_thread_proxy_,
- item.path(),
- item.offset() + additional_offset,
- item.expected_modification_time());
+
+ FileStreamReader* reader = NULL;
+ switch (item.type()) {
+ case BlobData::Item::TYPE_FILE:
+ reader = new LocalFileStreamReader(
+ file_thread_proxy_,
+ item.path(),
+ item.offset() + additional_offset,
+ item.expected_modification_time());
+ break;
+ case BlobData::Item::TYPE_FILE_FILESYSTEM:
+ reader = file_system_context_->CreateFileStreamReader(
+ fileapi::FileSystemURL(item.url()),
+ item.offset() + additional_offset,
+ item.expected_modification_time());
+ break;
+ default:
+ NOTREACHED();
+ }
+ DCHECK(reader);
+ index_to_reader_[index] = reader;
}
} // namespace webkit_blob
« no previous file with comments | « webkit/blob/blob_url_request_job.h ('k') | webkit/blob/blob_url_request_job_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698