OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <set> | 9 #include <set> |
10 | 10 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if (controller_) | 177 if (controller_) |
178 controller_->InvokeCallback(this, false); | 178 controller_->InvokeCallback(this, false); |
179 } | 179 } |
180 | 180 |
181 // --------------------------------------------------------------------------- | 181 // --------------------------------------------------------------------------- |
182 | 182 |
183 void InFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len, | 183 void InFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len, |
184 size_t offset, disk_cache::FileIOCallback *callback) { | 184 size_t offset, disk_cache::FileIOCallback *callback) { |
185 scoped_refptr<BackgroundIO> operation( | 185 scoped_refptr<BackgroundIO> operation( |
186 new BackgroundIO(file, buf, buf_len, offset, callback, this)); | 186 new BackgroundIO(file, buf, buf_len, offset, callback, this)); |
187 io_list_.insert(operation.get()); | 187 io_list_.insert(operation); |
188 file->AddRef(); // Balanced on InvokeCallback() | 188 file->AddRef(); // Balanced on InvokeCallback() |
189 | 189 |
190 if (!callback_thread_) | 190 if (!callback_thread_) |
191 callback_thread_ = MessageLoop::current(); | 191 callback_thread_ = MessageLoop::current(); |
192 | 192 |
193 WorkerPool::PostTask(FROM_HERE, | 193 WorkerPool::PostTask(FROM_HERE, |
194 NewRunnableMethod(operation.get(), &BackgroundIO::Read), | 194 NewRunnableMethod(operation.get(), &BackgroundIO::Read), |
195 true); | 195 true); |
196 } | 196 } |
197 | 197 |
198 void InFlightIO::PostWrite(disk_cache::File* file, const void* buf, | 198 void InFlightIO::PostWrite(disk_cache::File* file, const void* buf, |
199 size_t buf_len, size_t offset, | 199 size_t buf_len, size_t offset, |
200 disk_cache::FileIOCallback* callback) { | 200 disk_cache::FileIOCallback* callback) { |
201 scoped_refptr<BackgroundIO> operation( | 201 scoped_refptr<BackgroundIO> operation( |
202 new BackgroundIO(file, buf, buf_len, offset, callback, this)); | 202 new BackgroundIO(file, buf, buf_len, offset, callback, this)); |
203 io_list_.insert(operation.get()); | 203 io_list_.insert(operation); |
204 file->AddRef(); // Balanced on InvokeCallback() | 204 file->AddRef(); // Balanced on InvokeCallback() |
205 | 205 |
206 if (!callback_thread_) | 206 if (!callback_thread_) |
207 callback_thread_ = MessageLoop::current(); | 207 callback_thread_ = MessageLoop::current(); |
208 | 208 |
209 WorkerPool::PostTask(FROM_HERE, | 209 WorkerPool::PostTask(FROM_HERE, |
210 NewRunnableMethod(operation.get(), &BackgroundIO::Write), | 210 NewRunnableMethod(operation.get(), &BackgroundIO::Write), |
211 true); | 211 true); |
212 } | 212 } |
213 | 213 |
(...skipping 20 matching lines...) Expand all Loading... |
234 operation->io_completed()->Wait(); | 234 operation->io_completed()->Wait(); |
235 | 235 |
236 if (cancel_task) | 236 if (cancel_task) |
237 operation->Cancel(); | 237 operation->Cancel(); |
238 | 238 |
239 disk_cache::FileIOCallback* callback = operation->callback(); | 239 disk_cache::FileIOCallback* callback = operation->callback(); |
240 int bytes = operation->Result(); | 240 int bytes = operation->Result(); |
241 | 241 |
242 // Release the references acquired in PostRead / PostWrite. | 242 // Release the references acquired in PostRead / PostWrite. |
243 operation->file()->Release(); | 243 operation->file()->Release(); |
244 io_list_.erase(operation); | 244 io_list_.erase(make_scoped_refptr(operation)); |
245 callback->OnFileIOComplete(bytes); | 245 callback->OnFileIOComplete(bytes); |
246 } | 246 } |
247 | 247 |
248 } // namespace | 248 } // namespace |
249 | 249 |
250 namespace disk_cache { | 250 namespace disk_cache { |
251 | 251 |
252 File::File(base::PlatformFile file) | 252 File::File(base::PlatformFile file) |
253 : init_(true), | 253 : init_(true), |
254 mixed_(true), | 254 mixed_(true), |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 369 } |
370 | 370 |
371 // Static. | 371 // Static. |
372 void File::WaitForPendingIO(int* num_pending_io) { | 372 void File::WaitForPendingIO(int* num_pending_io) { |
373 // We may be running unit tests so we should allow InFlightIO to reset the | 373 // We may be running unit tests so we should allow InFlightIO to reset the |
374 // message loop. | 374 // message loop. |
375 Singleton<InFlightIO>::get()->WaitForPendingIO(); | 375 Singleton<InFlightIO>::get()->WaitForPendingIO(); |
376 } | 376 } |
377 | 377 |
378 } // namespace disk_cache | 378 } // namespace disk_cache |
OLD | NEW |