| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 // Static. | 161 // Static. |
| 162 void File::WaitForPendingIO(int* num_pending_io) { | 162 void File::WaitForPendingIO(int* num_pending_io) { |
| 163 // We are running unit tests so we should wait for all callbacks. Sadly, the | 163 // We are running unit tests so we should wait for all callbacks. Sadly, the |
| 164 // worker pool only waits for tasks on the worker pool, not the "Reply" tasks | 164 // worker pool only waits for tasks on the worker pool, not the "Reply" tasks |
| 165 // so we have to let the current message loop to run. | 165 // so we have to let the current message loop to run. |
| 166 s_worker_pool.Get().FlushForTesting(); | 166 s_worker_pool.Get().FlushForTesting(); |
| 167 base::RunLoop().RunUntilIdle(); | 167 base::RunLoop().RunUntilIdle(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 // Static. |
| 171 void File::DropPendingIO() { |
| 172 } |
| 173 |
| 174 |
| 170 File::~File() { | 175 File::~File() { |
| 171 if (IsValid()) | 176 if (IsValid()) |
| 172 base::ClosePlatformFile(platform_file_); | 177 base::ClosePlatformFile(platform_file_); |
| 173 } | 178 } |
| 174 | 179 |
| 175 // Runs on a worker thread. | 180 // Runs on a worker thread. |
| 176 int File::DoRead(void* buffer, size_t buffer_len, size_t offset) { | 181 int File::DoRead(void* buffer, size_t buffer_len, size_t offset) { |
| 177 if (Read(const_cast<void*>(buffer), buffer_len, offset)) | 182 if (Read(const_cast<void*>(buffer), buffer_len, offset)) |
| 178 return static_cast<int>(buffer_len); | 183 return static_cast<int>(buffer_len); |
| 179 | 184 |
| 180 return net::ERR_CACHE_READ_FAILURE; | 185 return net::ERR_CACHE_READ_FAILURE; |
| 181 } | 186 } |
| 182 | 187 |
| 183 // Runs on a worker thread. | 188 // Runs on a worker thread. |
| 184 int File::DoWrite(const void* buffer, size_t buffer_len, size_t offset) { | 189 int File::DoWrite(const void* buffer, size_t buffer_len, size_t offset) { |
| 185 if (Write(const_cast<void*>(buffer), buffer_len, offset)) | 190 if (Write(const_cast<void*>(buffer), buffer_len, offset)) |
| 186 return static_cast<int>(buffer_len); | 191 return static_cast<int>(buffer_len); |
| 187 | 192 |
| 188 return net::ERR_CACHE_WRITE_FAILURE; | 193 return net::ERR_CACHE_WRITE_FAILURE; |
| 189 } | 194 } |
| 190 | 195 |
| 191 // This method actually makes sure that the last reference to the file doesn't | 196 // This method actually makes sure that the last reference to the file doesn't |
| 192 // go away on the worker pool. | 197 // go away on the worker pool. |
| 193 void File::OnOperationComplete(FileIOCallback* callback, int result) { | 198 void File::OnOperationComplete(FileIOCallback* callback, int result) { |
| 194 callback->OnFileIOComplete(result); | 199 callback->OnFileIOComplete(result); |
| 195 } | 200 } |
| 196 | 201 |
| 197 } // namespace disk_cache | 202 } // namespace disk_cache |
| OLD | NEW |