OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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/disk_cache_test_base.h" | 5 #include "net/disk_cache/disk_cache_test_base.h" |
6 | 6 |
7 #include "net/base/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
10 #include "net/disk_cache/backend_impl.h" | 10 #include "net/disk_cache/backend_impl.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return cb.GetResult(rv); | 229 return cb.GetResult(rv); |
230 } | 230 } |
231 | 231 |
232 int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry, | 232 int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry, |
233 int64 offset, | 233 int64 offset, |
234 net::IOBuffer* buf, int len) { | 234 net::IOBuffer* buf, int len) { |
235 TestCompletionCallback cb; | 235 TestCompletionCallback cb; |
236 int rv = entry->WriteSparseData(offset, buf, len, &cb); | 236 int rv = entry->WriteSparseData(offset, buf, len, &cb); |
237 return cb.GetResult(rv); | 237 return cb.GetResult(rv); |
238 } | 238 } |
| 239 |
| 240 // Simple task to run part of a test from the cache thread. |
| 241 class TrimTask : public Task { |
| 242 public: |
| 243 TrimTask(disk_cache::BackendImpl* backend, bool deleted, bool empty) |
| 244 : backend_(backend), |
| 245 deleted_(deleted), |
| 246 empty_(empty) {} |
| 247 |
| 248 virtual void Run() { |
| 249 if (deleted_) |
| 250 backend_->TrimDeletedListForTest(empty_); |
| 251 else |
| 252 backend_->TrimForTest(empty_); |
| 253 } |
| 254 |
| 255 protected: |
| 256 disk_cache::BackendImpl* backend_; |
| 257 bool deleted_; |
| 258 bool empty_; |
| 259 }; |
| 260 |
| 261 void DiskCacheTestWithCache::TrimForTest(bool empty) { |
| 262 RunTaskForTest(new TrimTask(cache_impl_, false, empty)); |
| 263 } |
| 264 |
| 265 void DiskCacheTestWithCache::TrimDeletedListForTest(bool empty) { |
| 266 RunTaskForTest(new TrimTask(cache_impl_, true, empty)); |
| 267 } |
OLD | NEW |