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 17 matching lines...) Expand all Loading... |
28 // is keeping track of all operations. When done, we notify the controller | 28 // is keeping track of all operations. When done, we notify the controller |
29 // (we do NOT invoke the callback), in the worker thead that completed the | 29 // (we do NOT invoke the callback), in the worker thead that completed the |
30 // operation. | 30 // operation. |
31 BackgroundIO(disk_cache::File* file, const void* buf, size_t buf_len, | 31 BackgroundIO(disk_cache::File* file, const void* buf, size_t buf_len, |
32 size_t offset, disk_cache::FileIOCallback* callback, | 32 size_t offset, disk_cache::FileIOCallback* callback, |
33 InFlightIO* controller) | 33 InFlightIO* controller) |
34 : io_completed_(true, false), callback_(callback), file_(file), buf_(buf), | 34 : io_completed_(true, false), callback_(callback), file_(file), buf_(buf), |
35 buf_len_(buf_len), offset_(offset), controller_(controller), | 35 buf_len_(buf_len), offset_(offset), controller_(controller), |
36 bytes_(0) {} | 36 bytes_(0) {} |
37 | 37 |
38 ~BackgroundIO() {} | |
39 | |
40 // Read and Write are the operations that can be performed asynchronously. | 38 // Read and Write are the operations that can be performed asynchronously. |
41 // The actual parameters for the operation are setup in the constructor of | 39 // The actual parameters for the operation are setup in the constructor of |
42 // the object, with the exception of |delete_buffer|, that allows a write | 40 // the object, with the exception of |delete_buffer|, that allows a write |
43 // without a callback. Both methods should be called from a worker thread, by | 41 // without a callback. Both methods should be called from a worker thread, by |
44 // posting a task to the WorkerPool (they are RunnableMethods). When finished, | 42 // posting a task to the WorkerPool (they are RunnableMethods). When finished, |
45 // controller->OnIOComplete() is called. | 43 // controller->OnIOComplete() is called. |
46 void Read(); | 44 void Read(); |
47 void Write(bool delete_buffer); | 45 void Write(bool delete_buffer); |
48 | 46 |
49 // This method signals the controller that this operation is finished, in the | 47 // This method signals the controller that this operation is finished, in the |
(...skipping 18 matching lines...) Expand all Loading... |
68 | 66 |
69 disk_cache::FileIOCallback* callback() { | 67 disk_cache::FileIOCallback* callback() { |
70 return callback_; | 68 return callback_; |
71 } | 69 } |
72 | 70 |
73 disk_cache::File* file() { | 71 disk_cache::File* file() { |
74 return file_; | 72 return file_; |
75 } | 73 } |
76 | 74 |
77 private: | 75 private: |
| 76 friend class base::RefCountedThreadSafe<BackgroundIO>; |
| 77 ~BackgroundIO() {} |
| 78 |
78 // An event to signal when the operation completes, and the user callback that | 79 // An event to signal when the operation completes, and the user callback that |
79 // has to be invoked. These members are accessed directly by the controller. | 80 // has to be invoked. These members are accessed directly by the controller. |
80 base::WaitableEvent io_completed_; | 81 base::WaitableEvent io_completed_; |
81 disk_cache::FileIOCallback* callback_; | 82 disk_cache::FileIOCallback* callback_; |
82 | 83 |
83 disk_cache::File* file_; | 84 disk_cache::File* file_; |
84 const void* buf_; | 85 const void* buf_; |
85 size_t buf_len_; | 86 size_t buf_len_; |
86 size_t offset_; | 87 size_t offset_; |
87 InFlightIO* controller_; // The controller that tracks all operations. | 88 InFlightIO* controller_; // The controller that tracks all operations. |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 return ret; | 370 return ret; |
370 } | 371 } |
371 | 372 |
372 // Static. | 373 // Static. |
373 void File::WaitForPendingIO(int* num_pending_io) { | 374 void File::WaitForPendingIO(int* num_pending_io) { |
374 if (*num_pending_io) | 375 if (*num_pending_io) |
375 Singleton<InFlightIO>::get()->WaitForPendingIO(); | 376 Singleton<InFlightIO>::get()->WaitForPendingIO(); |
376 } | 377 } |
377 | 378 |
378 } // namespace disk_cache | 379 } // namespace disk_cache |
OLD | NEW |