summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 14:27:59 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 14:27:59 +0000
commit59c51f15f2eaba24e3571e24a7302b0c8f963c40 (patch)
tree156c659e966a022ca4170e641bf41251c898f325
parentc204ff5c7869a0db2ecc9b9722aabe5b85e1d998 (diff)
downloadchromium_src-59c51f15f2eaba24e3571e24a7302b0c8f963c40.zip
chromium_src-59c51f15f2eaba24e3571e24a7302b0c8f963c40.tar.gz
chromium_src-59c51f15f2eaba24e3571e24a7302b0c8f963c40.tar.bz2
Add fileapi::FileSystemFileStreamReader::GetLength()
BUG=141835 TEST=content_unittests --gtest_filter="FileSystemURLRequestJobTest.*" Review URL: https://chromiumcodereview.appspot.com/11087048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161114 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/blob/file_stream_reader.h8
-rw-r--r--webkit/blob/local_file_stream_reader.h10
-rw-r--r--webkit/fileapi/file_system_file_stream_reader.cc45
-rw-r--r--webkit/fileapi/file_system_file_stream_reader.h10
4 files changed, 55 insertions, 18 deletions
diff --git a/webkit/blob/file_stream_reader.h b/webkit/blob/file_stream_reader.h
index 83b8972..95e3571 100644
--- a/webkit/blob/file_stream_reader.h
+++ b/webkit/blob/file_stream_reader.h
@@ -38,6 +38,14 @@ class BLOB_EXPORT FileStreamReader {
// |callback| will not be called.
virtual int Read(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) = 0;
+
+ // Returns the length of the file if it could successfully retrieve the
+ // file info *and* its last modification time equals to
+ // expected_modification_time_ (rv >= 0 cases).
+ // Otherwise, a negative error code is returned (rv < 0 cases).
+ // If the stream is deleted while it has an in-flight GetLength operation
+ // |callback| will not be called.
+ virtual int GetLength(const net::Int64CompletionCallback& callback) = 0;
};
} // namespace webkit_blob
diff --git a/webkit/blob/local_file_stream_reader.h b/webkit/blob/local_file_stream_reader.h
index 0e7d150..97e08fb 100644
--- a/webkit/blob/local_file_stream_reader.h
+++ b/webkit/blob/local_file_stream_reader.h
@@ -47,14 +47,8 @@ class BLOB_EXPORT LocalFileStreamReader : public FileStreamReader {
// FileStreamReader overrides.
virtual int Read(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
-
- // Returns the length of the file if it could successfully retrieve the
- // file info *and* its last modification time equals to
- // expected_modification_time_ (rv >= 0 cases).
- // Otherwise, a negative error code is returned (rv < 0 cases).
- // If the stream is deleted while it has an in-flight GetLength operation
- // |callback| will not be called.
- int GetLength(const net::Int64CompletionCallback& callback);
+ virtual int GetLength(
+ const net::Int64CompletionCallback& callback) OVERRIDE;
private:
int Open(const net::CompletionCallback& callback);
diff --git a/webkit/fileapi/file_system_file_stream_reader.cc b/webkit/fileapi/file_system_file_stream_reader.cc
index ef0a915..0241662 100644
--- a/webkit/fileapi/file_system_file_stream_reader.cc
+++ b/webkit/fileapi/file_system_file_stream_reader.cc
@@ -31,6 +31,20 @@ void ReadAdapter(base::WeakPtr<FileSystemFileStreamReader> reader,
callback.Run(rv);
}
+void GetLengthAdapter(base::WeakPtr<FileSystemFileStreamReader> reader,
+ const net::Int64CompletionCallback& callback) {
+ if (!reader.get())
+ return;
+ int rv = reader->GetLength(callback);
+ if (rv != net::ERR_IO_PENDING)
+ callback.Run(rv);
+}
+
+void Int64CallbackAdapter(const net::Int64CompletionCallback& callback,
+ int value) {
+ callback.Run(value);
+}
+
} // namespace
FileSystemFileStreamReader::FileSystemFileStreamReader(
@@ -52,6 +66,24 @@ int FileSystemFileStreamReader::Read(
const net::CompletionCallback& callback) {
if (local_file_reader_.get())
return local_file_reader_->Read(buf, buf_len, callback);
+ return CreateSnapshot(
+ base::Bind(&ReadAdapter, weak_factory_.GetWeakPtr(),
+ make_scoped_refptr(buf), buf_len, callback),
+ callback);
+}
+
+int FileSystemFileStreamReader::GetLength(
+ const net::Int64CompletionCallback& callback) {
+ if (local_file_reader_.get())
+ return local_file_reader_->GetLength(callback);
+ return CreateSnapshot(
+ base::Bind(&GetLengthAdapter, weak_factory_.GetWeakPtr(), callback),
+ base::Bind(&Int64CallbackAdapter, callback));
+}
+
+int FileSystemFileStreamReader::CreateSnapshot(
+ const base::Closure& callback,
+ const net::CompletionCallback& error_callback) {
DCHECK(!has_pending_create_snapshot_);
base::PlatformFileError error_code;
FileSystemOperation* operation =
@@ -63,15 +95,14 @@ int FileSystemFileStreamReader::Read(
url_,
base::Bind(&FileSystemFileStreamReader::DidCreateSnapshot,
weak_factory_.GetWeakPtr(),
- base::Bind(&ReadAdapter, weak_factory_.GetWeakPtr(),
- make_scoped_refptr(buf), buf_len, callback),
- callback));
+ callback,
+ error_callback));
return net::ERR_IO_PENDING;
}
void FileSystemFileStreamReader::DidCreateSnapshot(
- const base::Closure& read_closure,
- const net::CompletionCallback& callback,
+ const base::Closure& callback,
+ const net::CompletionCallback& error_callback,
base::PlatformFileError file_error,
const base::PlatformFileInfo& file_info,
const FilePath& platform_path,
@@ -81,7 +112,7 @@ void FileSystemFileStreamReader::DidCreateSnapshot(
has_pending_create_snapshot_ = false;
if (file_error != base::PLATFORM_FILE_OK) {
- callback.Run(net::PlatformFileErrorToNetError(file_error));
+ error_callback.Run(net::PlatformFileErrorToNetError(file_error));
return;
}
@@ -93,7 +124,7 @@ void FileSystemFileStreamReader::DidCreateSnapshot(
file_system_context_->task_runners()->file_task_runner(),
platform_path, initial_offset_, base::Time()));
- read_closure.Run();
+ callback.Run();
}
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_file_stream_reader.h b/webkit/fileapi/file_system_file_stream_reader.h
index a1a06a9..219c106 100644
--- a/webkit/fileapi/file_system_file_stream_reader.h
+++ b/webkit/fileapi/file_system_file_stream_reader.h
@@ -38,14 +38,18 @@ class FileSystemFileStreamReader : public webkit_blob::FileStreamReader {
int64 initial_offset);
virtual ~FileSystemFileStreamReader();
- // FileReader override.
+ // FileStreamReader overrides.
virtual int Read(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
+ virtual int GetLength(
+ const net::Int64CompletionCallback& callback) OVERRIDE;
private:
+ int CreateSnapshot(const base::Closure& callback,
+ const net::CompletionCallback& error_callback);
void DidCreateSnapshot(
- const base::Closure& read_closure,
- const net::CompletionCallback& callback,
+ const base::Closure& callback,
+ const net::CompletionCallback& error_callback,
base::PlatformFileError file_error,
const base::PlatformFileInfo& file_info,
const FilePath& platform_path,