diff options
author | paivanof@gmail.com <paivanof@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-06 00:29:51 +0000 |
---|---|---|
committer | paivanof@gmail.com <paivanof@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-06 00:29:51 +0000 |
commit | aab1b9ead19f21af4f752c4a52beed65009d96fb (patch) | |
tree | 3679bc3c3bd80678a9fb2ab383aa6834679506d0 /net/url_request/url_request_file_job.cc | |
parent | 25524c044d4aefd6902d4245b66980c46669e145 (diff) | |
download | chromium_src-aab1b9ead19f21af4f752c4a52beed65009d96fb.zip chromium_src-aab1b9ead19f21af4f752c4a52beed65009d96fb.tar.gz chromium_src-aab1b9ead19f21af4f752c4a52beed65009d96fb.tar.bz2 |
net: Implement canceling of all async operations in FileStream.
Canceling of async operations allows to not wait for their completion
in FileStream's destructor. Other related changes include:
- Got rid of FileStream::Close() and FileStream::CloseSync() methods because
reuse of FileStream object doesn't make much sense, it should be destroyed
instead.
- Changed FileStream to always acquire ownership of the PlatformFile it was
given. Fixed usages of FileStream where no ownership was assumed, introduced
new helper functions in base/platform_file.h on the way.
- FileStream's destructor now always closes the file. If file was opened with
PLATFORM_FILE_ASYNC then actual closing is done asynchronously, destructor
doesn't wait for that and returns immediately. When file was opened without
PLATFORM_FILE_ASYNC closing is done synchronously and the thread doing that
should be allowed to do IO operations.
- Implementation of FileStream is refactored. FileStream is now just a wrapper
around internal object that does all actual work and that can be easily
orphaned in the destructor to not block on the actual file descriptor closing.
All platform-independent code is extracted into a special file and amount of
platform-dependent code is minimized.
BUG=115067, 112474
TEST=net_unittests
Review URL: https://chromiumcodereview.appspot.com/10701050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166091 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request/url_request_file_job.cc')
-rw-r--r-- | net/url_request/url_request_file_job.cc | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc index 90512dc..c60b313 100644 --- a/net/url_request/url_request_file_job.cc +++ b/net/url_request/url_request_file_job.cc @@ -29,6 +29,7 @@ #include "base/threading/thread_restrictions.h" #include "build/build_config.h" #include "googleurl/src/gurl.h" +#include "net/base/file_stream.h" #include "net/base/io_buffer.h" #include "net/base/load_flags.h" #include "net/base/mime_util.h" @@ -90,7 +91,6 @@ URLRequestFileJob::URLRequestFileJob(URLRequest* request, const FilePath& file_path) : URLRequestJob(request, network_delegate), file_path_(file_path), - stream_(NULL), is_directory_(false), remaining_bytes_(0) { } @@ -133,10 +133,7 @@ void URLRequestFileJob::Start() { } void URLRequestFileJob::Kill() { - // URL requests should not block on the disk! - // http://code.google.com/p/chromium/issues/detail?id=59849 - base::ThreadRestrictions::ScopedAllowIO allow_io; - stream_.CloseSync(); + stream_.reset(); if (async_resolver_) { async_resolver_->Cancel(); @@ -162,9 +159,9 @@ bool URLRequestFileJob::ReadRawData(IOBuffer* dest, int dest_size, return true; } - int rv = stream_.Read(dest, dest_size, - base::Bind(&URLRequestFileJob::DidRead, - base::Unretained(this))); + int rv = stream_->Read(dest, dest_size, + base::Bind(&URLRequestFileJob::DidRead, + base::Unretained(this))); if (rv >= 0) { // Data is immediately available. *bytes_read = rv; @@ -281,6 +278,8 @@ void URLRequestFileJob::DidResolve( if (!exists) { rv = ERR_FILE_NOT_FOUND; } else if (!is_directory_) { + stream_.reset(new FileStream(NULL)); + // URL requests should not block on the disk! // http://code.google.com/p/chromium/issues/detail?id=59849 base::ThreadRestrictions::ScopedAllowIO allow_io; @@ -288,7 +287,7 @@ void URLRequestFileJob::DidResolve( int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ | base::PLATFORM_FILE_ASYNC; - rv = stream_.OpenSync(file_path_, flags); + rv = stream_->OpenSync(file_path_, flags); } if (rv != OK) { @@ -314,7 +313,7 @@ void URLRequestFileJob::DidResolve( if (remaining_bytes_ > 0 && byte_range_.first_byte_position() != 0 && byte_range_.first_byte_position() != - stream_.SeekSync(FROM_BEGIN, byte_range_.first_byte_position())) { + stream_->SeekSync(FROM_BEGIN, byte_range_.first_byte_position())) { NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, ERR_REQUEST_RANGE_NOT_SATISFIABLE)); return; |