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

Unified Diff: webkit/fileapi/file_system_url_request_job.cc

Issue 10066043: Revert 132134 - Use LocalFileReader in FileSystemURLRequestJob (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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/fileapi/file_system_url_request_job.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/file_system_url_request_job.cc
===================================================================
--- webkit/fileapi/file_system_url_request_job.cc (revision 132160)
+++ webkit/fileapi/file_system_url_request_job.cc (working copy)
@@ -4,6 +4,8 @@
#include "webkit/fileapi/file_system_url_request_job.h"
+#include <vector>
+
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/file_path.h"
@@ -11,7 +13,6 @@
#include "base/message_loop.h"
#include "base/platform_file.h"
#include "base/threading/thread_restrictions.h"
-#include "base/time.h"
#include "build/build_config.h"
#include "googleurl/src/gurl.h"
#include "net/base/file_stream.h"
@@ -23,7 +24,6 @@
#include "net/http/http_response_info.h"
#include "net/http/http_util.h"
#include "net/url_request/url_request.h"
-#include "webkit/blob/local_file_reader.h"
#include "webkit/blob/shareable_file_reference.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
@@ -32,10 +32,13 @@
using net::URLRequest;
using net::URLRequestJob;
using net::URLRequestStatus;
-using webkit_blob::LocalFileReader;
namespace fileapi {
+static const int kFileFlags = base::PLATFORM_FILE_OPEN |
+ base::PLATFORM_FILE_READ |
+ base::PLATFORM_FILE_ASYNC;
+
static net::HttpResponseHeaders* CreateHttpResponseHeaders() {
// HttpResponseHeaders expects its input string to be terminated by two NULs.
static const char kStatus[] = "HTTP/1.1 200 OK\0";
@@ -59,11 +62,20 @@
file_system_context_(file_system_context),
file_thread_proxy_(file_thread_proxy),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
+ stream_(NULL),
is_directory_(false),
remaining_bytes_(0) {
}
-FileSystemURLRequestJob::~FileSystemURLRequestJob() {}
+FileSystemURLRequestJob::~FileSystemURLRequestJob() {
+ // Since we use the two-arg constructor of FileStream, we need to call Close()
+ // manually: ~FileStream won't call it for us.
+ if (stream_ != NULL) {
+ // Close() performs file IO: crbug.com/113300.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ stream_->CloseSync();
+ }
+}
void FileSystemURLRequestJob::Start() {
MessageLoop::current()->PostTask(
@@ -73,8 +85,12 @@
}
void FileSystemURLRequestJob::Kill() {
- if (reader_.get() != NULL)
- reader_.reset();
+ if (stream_ != NULL) {
+ // Close() performs file IO: crbug.com/113300.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ stream_->CloseSync();
+ stream_.reset(NULL);
+ }
URLRequestJob::Kill();
weak_factory_.InvalidateWeakPtrs();
}
@@ -85,7 +101,7 @@
DCHECK(bytes_read);
DCHECK_GE(remaining_bytes_, 0);
- if (reader_.get() == NULL)
+ if (stream_ == NULL)
return false;
if (remaining_bytes_ < dest_size)
@@ -96,9 +112,18 @@
return true;
}
- const int rv = reader_->Read(dest, dest_size,
- base::Bind(&FileSystemURLRequestJob::DidRead,
- base::Unretained(this)));
+ int rv = stream_->Read(dest, dest_size,
+ base::Bind(&FileSystemURLRequestJob::DidRead,
+ base::Unretained(this)));
+ if (rv >= 0) {
+ // Data is immediately available.
+ *bytes_read = rv;
+ remaining_bytes_ -= rv;
+ DCHECK_GE(remaining_bytes_, 0);
+ return true;
+ }
+
+ // Otherwise, a read error occured. We may just need to wait...
if (rv == net::ERR_IO_PENDING)
SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
else
@@ -189,24 +214,47 @@
return;
}
- if (is_directory_) {
+ if (!is_directory_) {
+ base::FileUtilProxy::CreateOrOpen(
+ file_thread_proxy_, platform_path, kFileFlags,
+ base::Bind(&FileSystemURLRequestJob::DidOpen,
+ weak_factory_.GetWeakPtr()));
+ } else {
NotifyHeadersComplete();
+ }
+}
+
+void FileSystemURLRequestJob::DidOpen(base::PlatformFileError error_code,
+ base::PassPlatformFile file,
+ bool created) {
+ if (error_code != base::PLATFORM_FILE_OK) {
+ NotifyFailed(error_code);
return;
}
+ stream_.reset(new net::FileStream(file.ReleaseValue(), kFileFlags, NULL));
+
remaining_bytes_ = byte_range_.last_byte_position() -
byte_range_.first_byte_position() + 1;
DCHECK_GE(remaining_bytes_, 0);
- DCHECK(!reader_.get());
- reader_.reset(new LocalFileReader(
- file_thread_proxy_, platform_path,
- byte_range_.first_byte_position(),
- base::Time()));
+ // TODO(adamk): Please remove this ScopedAllowIO once we support async seek
+ // on FileStream. crbug.com/113300
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ // Do the seek at the beginning of the request.
+ if (remaining_bytes_ > 0 &&
+ byte_range_.first_byte_position() != 0 &&
+ byte_range_.first_byte_position() !=
+ stream_->SeekSync(net::FROM_BEGIN,
+ byte_range_.first_byte_position())) {
+ NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
+ return;
+ }
set_expected_content_size(remaining_bytes_);
response_info_.reset(new net::HttpResponseInfo());
response_info_->headers = CreateHttpResponseHeaders();
+
NotifyHeadersComplete();
}
Property changes on: webkit/fileapi/file_system_url_request_job.cc
___________________________________________________________________
Added: svn:mergeinfo
Merged /branches/chrome_webkit_merge_branch/src/webkit/fileapi/file_system_url_request_job.cc:r3734-4217,4606-5108,5177-5263
« no previous file with comments | « webkit/fileapi/file_system_url_request_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698