OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/blockfile/file.h" | 5 #include "net/disk_cache/blockfile/file.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/threading/worker_pool.h" | 17 #include "base/task_scheduler/post_task.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/disk_cache/blockfile/in_flight_io.h" | 19 #include "net/disk_cache/blockfile/in_flight_io.h" |
20 #include "net/disk_cache/disk_cache.h" | 20 #include "net/disk_cache/disk_cache.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // This class represents a single asynchronous IO operation while it is being | 24 // This class represents a single asynchronous IO operation while it is being |
25 // bounced between threads. | 25 // bounced between threads. |
26 class FileBackgroundIO : public disk_cache::BackgroundIO { | 26 class FileBackgroundIO : public disk_cache::BackgroundIO { |
27 public: | 27 public: |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 114 } |
115 | 115 |
116 // --------------------------------------------------------------------------- | 116 // --------------------------------------------------------------------------- |
117 | 117 |
118 void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len, | 118 void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len, |
119 size_t offset, disk_cache::FileIOCallback *callback) { | 119 size_t offset, disk_cache::FileIOCallback *callback) { |
120 scoped_refptr<FileBackgroundIO> operation( | 120 scoped_refptr<FileBackgroundIO> operation( |
121 new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); | 121 new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); |
122 file->AddRef(); // Balanced on OnOperationComplete() | 122 file->AddRef(); // Balanced on OnOperationComplete() |
123 | 123 |
124 base::WorkerPool::PostTask(FROM_HERE, | 124 base::PostTaskWithTraits( |
125 base::Bind(&FileBackgroundIO::Read, operation.get()), true); | 125 FROM_HERE, base::TaskTraits() |
| 126 .WithShutdownBehavior( |
| 127 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 128 .MayBlock(), |
| 129 base::Bind(&FileBackgroundIO::Read, operation.get())); |
126 OnOperationPosted(operation.get()); | 130 OnOperationPosted(operation.get()); |
127 } | 131 } |
128 | 132 |
129 void FileInFlightIO::PostWrite(disk_cache::File* file, const void* buf, | 133 void FileInFlightIO::PostWrite(disk_cache::File* file, const void* buf, |
130 size_t buf_len, size_t offset, | 134 size_t buf_len, size_t offset, |
131 disk_cache::FileIOCallback* callback) { | 135 disk_cache::FileIOCallback* callback) { |
132 scoped_refptr<FileBackgroundIO> operation( | 136 scoped_refptr<FileBackgroundIO> operation( |
133 new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); | 137 new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); |
134 file->AddRef(); // Balanced on OnOperationComplete() | 138 file->AddRef(); // Balanced on OnOperationComplete() |
135 | 139 |
136 base::WorkerPool::PostTask(FROM_HERE, | 140 base::PostTaskWithTraits( |
137 base::Bind(&FileBackgroundIO::Write, operation.get()), true); | 141 FROM_HERE, base::TaskTraits() |
| 142 .WithShutdownBehavior( |
| 143 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 144 .MayBlock(), |
| 145 base::Bind(&FileBackgroundIO::Write, operation.get())); |
138 OnOperationPosted(operation.get()); | 146 OnOperationPosted(operation.get()); |
139 } | 147 } |
140 | 148 |
141 // Runs on the IO thread. | 149 // Runs on the IO thread. |
142 void FileInFlightIO::OnOperationComplete(disk_cache::BackgroundIO* operation, | 150 void FileInFlightIO::OnOperationComplete(disk_cache::BackgroundIO* operation, |
143 bool cancel) { | 151 bool cancel) { |
144 FileBackgroundIO* op = static_cast<FileBackgroundIO*>(operation); | 152 FileBackgroundIO* op = static_cast<FileBackgroundIO*>(operation); |
145 | 153 |
146 disk_cache::FileIOCallback* callback = op->callback(); | 154 disk_cache::FileIOCallback* callback = op->callback(); |
147 int bytes = operation->result(); | 155 int bytes = operation->result(); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 return false; | 302 return false; |
295 | 303 |
296 GetFileInFlightIO()->PostWrite(this, buffer, buffer_len, offset, callback); | 304 GetFileInFlightIO()->PostWrite(this, buffer, buffer_len, offset, callback); |
297 | 305 |
298 if (completed) | 306 if (completed) |
299 *completed = false; | 307 *completed = false; |
300 return true; | 308 return true; |
301 } | 309 } |
302 | 310 |
303 } // namespace disk_cache | 311 } // namespace disk_cache |
OLD | NEW |