OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/disk_cache/file.h" | 5 #include "net/disk_cache/file.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // --------------------------------------------------------------------------- | 111 // --------------------------------------------------------------------------- |
112 | 112 |
113 void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len, | 113 void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len, |
114 size_t offset, disk_cache::FileIOCallback *callback) { | 114 size_t offset, disk_cache::FileIOCallback *callback) { |
115 scoped_refptr<FileBackgroundIO> operation( | 115 scoped_refptr<FileBackgroundIO> operation( |
116 new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); | 116 new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); |
117 file->AddRef(); // Balanced on OnOperationComplete() | 117 file->AddRef(); // Balanced on OnOperationComplete() |
118 | 118 |
119 base::WorkerPool::PostTask(FROM_HERE, | 119 base::WorkerPool::PostTask(FROM_HERE, |
120 base::Bind(&FileBackgroundIO::Read, operation.get()), true); | 120 base::Bind(&FileBackgroundIO::Read, operation.get()), true); |
121 OnOperationPosted(operation); | 121 OnOperationPosted(operation.get()); |
122 } | 122 } |
123 | 123 |
124 void FileInFlightIO::PostWrite(disk_cache::File* file, const void* buf, | 124 void FileInFlightIO::PostWrite(disk_cache::File* file, const void* buf, |
125 size_t buf_len, size_t offset, | 125 size_t buf_len, size_t offset, |
126 disk_cache::FileIOCallback* callback) { | 126 disk_cache::FileIOCallback* callback) { |
127 scoped_refptr<FileBackgroundIO> operation( | 127 scoped_refptr<FileBackgroundIO> operation( |
128 new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); | 128 new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); |
129 file->AddRef(); // Balanced on OnOperationComplete() | 129 file->AddRef(); // Balanced on OnOperationComplete() |
130 | 130 |
131 base::WorkerPool::PostTask(FROM_HERE, | 131 base::WorkerPool::PostTask(FROM_HERE, |
132 base::Bind(&FileBackgroundIO::Write, operation.get()), true); | 132 base::Bind(&FileBackgroundIO::Write, operation.get()), true); |
133 OnOperationPosted(operation); | 133 OnOperationPosted(operation.get()); |
134 } | 134 } |
135 | 135 |
136 // Runs on the IO thread. | 136 // Runs on the IO thread. |
137 void FileInFlightIO::OnOperationComplete(disk_cache::BackgroundIO* operation, | 137 void FileInFlightIO::OnOperationComplete(disk_cache::BackgroundIO* operation, |
138 bool cancel) { | 138 bool cancel) { |
139 FileBackgroundIO* op = static_cast<FileBackgroundIO*>(operation); | 139 FileBackgroundIO* op = static_cast<FileBackgroundIO*>(operation); |
140 | 140 |
141 disk_cache::FileIOCallback* callback = op->callback(); | 141 disk_cache::FileIOCallback* callback = op->callback(); |
142 int bytes = operation->result(); | 142 int bytes = operation->result(); |
143 | 143 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 return false; | 300 return false; |
301 | 301 |
302 GetFileInFlightIO()->PostWrite(this, buffer, buffer_len, offset, callback); | 302 GetFileInFlightIO()->PostWrite(this, buffer, buffer_len, offset, callback); |
303 | 303 |
304 if (completed) | 304 if (completed) |
305 *completed = false; | 305 *completed = false; |
306 return true; | 306 return true; |
307 } | 307 } |
308 | 308 |
309 } // namespace disk_cache | 309 } // namespace disk_cache |
OLD | NEW |