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/blockfile/backend_impl.h" | 5 #include "net/disk_cache/blockfile/backend_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 SyncEndEnumeration(iterator.Pass()); | 429 SyncEndEnumeration(iterator.Pass()); |
430 return net::OK; | 430 return net::OK; |
431 } | 431 } |
432 | 432 |
433 entry->DoomImpl(); | 433 entry->DoomImpl(); |
434 entry->Release(); | 434 entry->Release(); |
435 SyncEndEnumeration(iterator.Pass()); // The doom invalidated the iterator. | 435 SyncEndEnumeration(iterator.Pass()); // The doom invalidated the iterator. |
436 } | 436 } |
437 } | 437 } |
438 | 438 |
| 439 int BackendImpl::SyncCalculateSizeOfEntriesBetween( |
| 440 const base::Time initial_time, const base::Time end_time) { |
| 441 DCHECK_NE(net::APP_CACHE, cache_type_); |
| 442 DCHECK_GE(end_time, initial_time); |
| 443 if (disabled_) |
| 444 return net::ERR_FAILED; |
| 445 |
| 446 EntryImpl* node; |
| 447 scoped_ptr<Rankings::Iterator> iterator(new Rankings::Iterator()); |
| 448 EntryImpl* next = OpenNextEntryImpl(iterator.get()); |
| 449 if (!next) |
| 450 return net::OK; |
| 451 |
| 452 int size = 0; |
| 453 while (next) { |
| 454 node = next; |
| 455 next = OpenNextEntryImpl(iterator.get()); |
| 456 |
| 457 if (node->GetLastUsed() >= initial_time && |
| 458 node->GetLastUsed() < end_time) { |
| 459 size += node->GetEntrySize(); |
| 460 } else if (node->GetLastUsed() < initial_time) { |
| 461 if (next) |
| 462 next->Release(); |
| 463 next = NULL; |
| 464 SyncEndEnumeration(iterator.Pass()); |
| 465 } |
| 466 |
| 467 node->Release(); |
| 468 } |
| 469 |
| 470 return size; |
| 471 } |
| 472 |
439 int BackendImpl::SyncOpenNextEntry(Rankings::Iterator* iterator, | 473 int BackendImpl::SyncOpenNextEntry(Rankings::Iterator* iterator, |
440 Entry** next_entry) { | 474 Entry** next_entry) { |
441 *next_entry = OpenNextEntryImpl(iterator); | 475 *next_entry = OpenNextEntryImpl(iterator); |
442 return (*next_entry) ? net::OK : net::ERR_FAILED; | 476 return (*next_entry) ? net::OK : net::ERR_FAILED; |
443 } | 477 } |
444 | 478 |
445 void BackendImpl::SyncEndEnumeration(scoped_ptr<Rankings::Iterator> iterator) { | 479 void BackendImpl::SyncEndEnumeration(scoped_ptr<Rankings::Iterator> iterator) { |
446 iterator->Reset(); | 480 iterator->Reset(); |
447 } | 481 } |
448 | 482 |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 return net::ERR_IO_PENDING; | 1281 return net::ERR_IO_PENDING; |
1248 } | 1282 } |
1249 | 1283 |
1250 int BackendImpl::DoomEntriesSince(const base::Time initial_time, | 1284 int BackendImpl::DoomEntriesSince(const base::Time initial_time, |
1251 const CompletionCallback& callback) { | 1285 const CompletionCallback& callback) { |
1252 DCHECK(!callback.is_null()); | 1286 DCHECK(!callback.is_null()); |
1253 background_queue_.DoomEntriesSince(initial_time, callback); | 1287 background_queue_.DoomEntriesSince(initial_time, callback); |
1254 return net::ERR_IO_PENDING; | 1288 return net::ERR_IO_PENDING; |
1255 } | 1289 } |
1256 | 1290 |
| 1291 int BackendImpl::CalculateSizeOfEntriesBetween( |
| 1292 base::Time initial_time, |
| 1293 base::Time end_time, |
| 1294 const CompletionCallback& callback) { |
| 1295 DCHECK(!callback.is_null()); |
| 1296 background_queue_.CalculateSizeOfEntriesBetween( |
| 1297 initial_time, end_time, callback); |
| 1298 return net::ERR_IO_PENDING; |
| 1299 } |
| 1300 |
1257 class BackendImpl::IteratorImpl : public Backend::Iterator { | 1301 class BackendImpl::IteratorImpl : public Backend::Iterator { |
1258 public: | 1302 public: |
1259 explicit IteratorImpl(base::WeakPtr<InFlightBackendIO> background_queue) | 1303 explicit IteratorImpl(base::WeakPtr<InFlightBackendIO> background_queue) |
1260 : background_queue_(background_queue), | 1304 : background_queue_(background_queue), |
1261 iterator_(new Rankings::Iterator()) { | 1305 iterator_(new Rankings::Iterator()) { |
1262 } | 1306 } |
1263 | 1307 |
1264 ~IteratorImpl() override { | 1308 ~IteratorImpl() override { |
1265 if (background_queue_) | 1309 if (background_queue_) |
1266 background_queue_->EndEnumeration(iterator_.Pass()); | 1310 background_queue_->EndEnumeration(iterator_.Pass()); |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 2135 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
2092 total_memory = kMaxBuffersSize; | 2136 total_memory = kMaxBuffersSize; |
2093 | 2137 |
2094 done = true; | 2138 done = true; |
2095 } | 2139 } |
2096 | 2140 |
2097 return static_cast<int>(total_memory); | 2141 return static_cast<int>(total_memory); |
2098 } | 2142 } |
2099 | 2143 |
2100 } // namespace disk_cache | 2144 } // namespace disk_cache |
OLD | NEW |