| Index: net/disk_cache/blockfile/file_ios.cc
|
| diff --git a/net/disk_cache/blockfile/file_ios.cc b/net/disk_cache/blockfile/file_ios.cc
|
| index 4659e75c652e3fdfea2399a463951360a4eb227a..0e3303e3426e4cc7bf43205ed5764295f02881fa 100644
|
| --- a/net/disk_cache/blockfile/file_ios.cc
|
| +++ b/net/disk_cache/blockfile/file_ios.cc
|
| @@ -23,20 +23,22 @@ class FileBackgroundIO : public disk_cache::BackgroundIO {
|
| // is keeping track of all operations. When done, we notify the controller
|
| // (we do NOT invoke the callback), in the worker thead that completed the
|
| // operation.
|
| - FileBackgroundIO(disk_cache::File* file, const void* buf, size_t buf_len,
|
| - size_t offset, disk_cache::FileIOCallback* callback,
|
| + FileBackgroundIO(disk_cache::File* file,
|
| + const void* buf,
|
| + size_t buf_len,
|
| + size_t offset,
|
| + disk_cache::FileIOCallback* callback,
|
| disk_cache::InFlightIO* controller)
|
| - : disk_cache::BackgroundIO(controller), callback_(callback), file_(file),
|
| - buf_(buf), buf_len_(buf_len), offset_(offset) {
|
| - }
|
| + : disk_cache::BackgroundIO(controller),
|
| + callback_(callback),
|
| + file_(file),
|
| + buf_(buf),
|
| + buf_len_(buf_len),
|
| + offset_(offset) {}
|
|
|
| - disk_cache::FileIOCallback* callback() {
|
| - return callback_;
|
| - }
|
| + disk_cache::FileIOCallback* callback() { return callback_; }
|
|
|
| - disk_cache::File* file() {
|
| - return file_;
|
| - }
|
| + disk_cache::File* file() { return file_; }
|
|
|
| // Read and Write are the operations that can be performed asynchronously.
|
| // The actual parameters for the operation are setup in the constructor of
|
| @@ -59,7 +61,6 @@ class FileBackgroundIO : public disk_cache::BackgroundIO {
|
| DISALLOW_COPY_AND_ASSIGN(FileBackgroundIO);
|
| };
|
|
|
| -
|
| // The specialized controller that keeps track of current operations.
|
| class FileInFlightIO : public disk_cache::InFlightIO {
|
| public:
|
| @@ -69,10 +70,16 @@ class FileInFlightIO : public disk_cache::InFlightIO {
|
| // These methods start an asynchronous operation. The arguments have the same
|
| // semantics of the File asynchronous operations, with the exception that the
|
| // operation never finishes synchronously.
|
| - void PostRead(disk_cache::File* file, void* buf, size_t buf_len,
|
| - size_t offset, disk_cache::FileIOCallback* callback);
|
| - void PostWrite(disk_cache::File* file, const void* buf, size_t buf_len,
|
| - size_t offset, disk_cache::FileIOCallback* callback);
|
| + void PostRead(disk_cache::File* file,
|
| + void* buf,
|
| + size_t buf_len,
|
| + size_t offset,
|
| + disk_cache::FileIOCallback* callback);
|
| + void PostWrite(disk_cache::File* file,
|
| + const void* buf,
|
| + size_t buf_len,
|
| + size_t offset,
|
| + disk_cache::FileIOCallback* callback);
|
|
|
| protected:
|
| // Invokes the users' completion callback at the end of the IO operation.
|
| @@ -108,26 +115,31 @@ void FileBackgroundIO::Write() {
|
|
|
| // ---------------------------------------------------------------------------
|
|
|
| -void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len,
|
| - size_t offset, disk_cache::FileIOCallback *callback) {
|
| +void FileInFlightIO::PostRead(disk_cache::File* file,
|
| + void* buf,
|
| + size_t buf_len,
|
| + size_t offset,
|
| + disk_cache::FileIOCallback* callback) {
|
| scoped_refptr<FileBackgroundIO> operation(
|
| new FileBackgroundIO(file, buf, buf_len, offset, callback, this));
|
| file->AddRef(); // Balanced on OnOperationComplete()
|
|
|
| - base::WorkerPool::PostTask(FROM_HERE,
|
| - base::Bind(&FileBackgroundIO::Read, operation.get()), true);
|
| + base::WorkerPool::PostTask(
|
| + FROM_HERE, base::Bind(&FileBackgroundIO::Read, operation.get()), true);
|
| OnOperationPosted(operation.get());
|
| }
|
|
|
| -void FileInFlightIO::PostWrite(disk_cache::File* file, const void* buf,
|
| - size_t buf_len, size_t offset,
|
| - disk_cache::FileIOCallback* callback) {
|
| +void FileInFlightIO::PostWrite(disk_cache::File* file,
|
| + const void* buf,
|
| + size_t buf_len,
|
| + size_t offset,
|
| + disk_cache::FileIOCallback* callback) {
|
| scoped_refptr<FileBackgroundIO> operation(
|
| new FileBackgroundIO(file, buf, buf_len, offset, callback, this));
|
| file->AddRef(); // Balanced on OnOperationComplete()
|
|
|
| - base::WorkerPool::PostTask(FROM_HERE,
|
| - base::Bind(&FileBackgroundIO::Write, operation.get()), true);
|
| + base::WorkerPool::PostTask(
|
| + FROM_HERE, base::Bind(&FileBackgroundIO::Write, operation.get()), true);
|
| OnOperationPosted(operation.get());
|
| }
|
|
|
| @@ -167,17 +179,15 @@ void DeleteFileInFlightIO() {
|
| namespace disk_cache {
|
|
|
| File::File(base::File file)
|
| - : init_(true),
|
| - mixed_(true),
|
| - base_file_(file.Pass()) {
|
| + : init_(true), mixed_(true), base_file_(file.Pass()) {
|
| }
|
|
|
| bool File::Init(const base::FilePath& name) {
|
| if (base_file_.IsValid())
|
| return false;
|
|
|
| - int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
|
| - base::File::FLAG_WRITE;
|
| + int flags =
|
| + base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE;
|
| base_file_.Initialize(name, flags);
|
| return base_file_.IsValid();
|
| }
|
| @@ -204,16 +214,19 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset) {
|
| return false;
|
| }
|
|
|
| - int ret = base_file_.Write(offset, static_cast<const char*>(buffer),
|
| - buffer_len);
|
| + int ret =
|
| + base_file_.Write(offset, static_cast<const char*>(buffer), buffer_len);
|
| return (static_cast<size_t>(ret) == buffer_len);
|
| }
|
|
|
| // We have to increase the ref counter of the file before performing the IO to
|
| // prevent the completion to happen with an invalid handle (if the file is
|
| // closed while the IO is in flight).
|
| -bool File::Read(void* buffer, size_t buffer_len, size_t offset,
|
| - FileIOCallback* callback, bool* completed) {
|
| +bool File::Read(void* buffer,
|
| + size_t buffer_len,
|
| + size_t offset,
|
| + FileIOCallback* callback,
|
| + bool* completed) {
|
| DCHECK(base_file_.IsValid());
|
| if (!callback) {
|
| if (completed)
|
| @@ -230,8 +243,11 @@ bool File::Read(void* buffer, size_t buffer_len, size_t offset,
|
| return true;
|
| }
|
|
|
| -bool File::Write(const void* buffer, size_t buffer_len, size_t offset,
|
| - FileIOCallback* callback, bool* completed) {
|
| +bool File::Write(const void* buffer,
|
| + size_t buffer_len,
|
| + size_t offset,
|
| + FileIOCallback* callback,
|
| + bool* completed) {
|
| DCHECK(base_file_.IsValid());
|
| if (!callback) {
|
| if (completed)
|
| @@ -281,8 +297,11 @@ base::PlatformFile File::platform_file() const {
|
| return base_file_.GetPlatformFile();
|
| }
|
|
|
| -bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
|
| - FileIOCallback* callback, bool* completed) {
|
| +bool File::AsyncWrite(const void* buffer,
|
| + size_t buffer_len,
|
| + size_t offset,
|
| + FileIOCallback* callback,
|
| + bool* completed) {
|
| DCHECK(base_file_.IsValid());
|
| if (buffer_len > ULONG_MAX || offset > ULONG_MAX)
|
| return false;
|
|
|