Chromium Code Reviews| 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 if (disabled_) | |
| 443 return net::ERR_FAILED; | |
| 444 | |
| 445 if (initial_time.is_null() && end_time.is_null()) | |
| 446 return data_->header.num_bytes; | |
| 447 | |
| 448 const base::Time effective_end_time = | |
| 449 end_time.is_null() ? base::Time::Max() : end_time; | |
| 450 DCHECK_GE(effective_end_time, initial_time); | |
| 451 | |
| 452 EntryImpl* node; | |
| 453 scoped_ptr<Rankings::Iterator> iterator(new Rankings::Iterator()); | |
| 454 EntryImpl* next = OpenNextEntryImpl(iterator.get()); | |
| 455 if (!next) | |
| 456 return net::OK; | |
|
rvargas (doing something else)
2015/09/12 00:13:02
nit: This would be 0 (a size).
msramek
2015/09/15 11:42:36
Done.
| |
| 457 | |
| 458 int size = 0; | |
| 459 while (next) { | |
| 460 node = next; | |
| 461 next = OpenNextEntryImpl(iterator.get()); | |
| 462 | |
| 463 if (node->GetLastUsed() >= initial_time && | |
| 464 node->GetLastUsed() < effective_end_time) { | |
| 465 size += node->GetEntrySize(); | |
| 466 } else if (node->GetLastUsed() < initial_time) { | |
| 467 if (next) | |
| 468 next->Release(); | |
| 469 next = NULL; | |
| 470 SyncEndEnumeration(iterator.Pass()); | |
| 471 } | |
| 472 | |
| 473 node->Release(); | |
| 474 } | |
| 475 | |
| 476 return size; | |
| 477 } | |
| 478 | |
| 439 int BackendImpl::SyncOpenNextEntry(Rankings::Iterator* iterator, | 479 int BackendImpl::SyncOpenNextEntry(Rankings::Iterator* iterator, |
| 440 Entry** next_entry) { | 480 Entry** next_entry) { |
| 441 *next_entry = OpenNextEntryImpl(iterator); | 481 *next_entry = OpenNextEntryImpl(iterator); |
| 442 return (*next_entry) ? net::OK : net::ERR_FAILED; | 482 return (*next_entry) ? net::OK : net::ERR_FAILED; |
| 443 } | 483 } |
| 444 | 484 |
| 445 void BackendImpl::SyncEndEnumeration(scoped_ptr<Rankings::Iterator> iterator) { | 485 void BackendImpl::SyncEndEnumeration(scoped_ptr<Rankings::Iterator> iterator) { |
| 446 iterator->Reset(); | 486 iterator->Reset(); |
| 447 } | 487 } |
| 448 | 488 |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1247 return net::ERR_IO_PENDING; | 1287 return net::ERR_IO_PENDING; |
| 1248 } | 1288 } |
| 1249 | 1289 |
| 1250 int BackendImpl::DoomEntriesSince(const base::Time initial_time, | 1290 int BackendImpl::DoomEntriesSince(const base::Time initial_time, |
| 1251 const CompletionCallback& callback) { | 1291 const CompletionCallback& callback) { |
| 1252 DCHECK(!callback.is_null()); | 1292 DCHECK(!callback.is_null()); |
| 1253 background_queue_.DoomEntriesSince(initial_time, callback); | 1293 background_queue_.DoomEntriesSince(initial_time, callback); |
| 1254 return net::ERR_IO_PENDING; | 1294 return net::ERR_IO_PENDING; |
| 1255 } | 1295 } |
| 1256 | 1296 |
| 1297 int BackendImpl::CalculateSizeOfEntriesBetween( | |
| 1298 base::Time initial_time, | |
| 1299 base::Time end_time, | |
| 1300 const CompletionCallback& callback) { | |
| 1301 DCHECK(!callback.is_null()); | |
| 1302 background_queue_.CalculateSizeOfEntriesBetween( | |
| 1303 initial_time, end_time, callback); | |
| 1304 return net::ERR_IO_PENDING; | |
| 1305 } | |
| 1306 | |
| 1257 class BackendImpl::IteratorImpl : public Backend::Iterator { | 1307 class BackendImpl::IteratorImpl : public Backend::Iterator { |
| 1258 public: | 1308 public: |
| 1259 explicit IteratorImpl(base::WeakPtr<InFlightBackendIO> background_queue) | 1309 explicit IteratorImpl(base::WeakPtr<InFlightBackendIO> background_queue) |
| 1260 : background_queue_(background_queue), | 1310 : background_queue_(background_queue), |
| 1261 iterator_(new Rankings::Iterator()) { | 1311 iterator_(new Rankings::Iterator()) { |
| 1262 } | 1312 } |
| 1263 | 1313 |
| 1264 ~IteratorImpl() override { | 1314 ~IteratorImpl() override { |
| 1265 if (background_queue_) | 1315 if (background_queue_) |
| 1266 background_queue_->EndEnumeration(iterator_.Pass()); | 1316 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) | 2141 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
| 2092 total_memory = kMaxBuffersSize; | 2142 total_memory = kMaxBuffersSize; |
| 2093 | 2143 |
| 2094 done = true; | 2144 done = true; |
| 2095 } | 2145 } |
| 2096 | 2146 |
| 2097 return static_cast<int>(total_memory); | 2147 return static_cast<int>(total_memory); |
| 2098 } | 2148 } |
| 2099 | 2149 |
| 2100 } // namespace disk_cache | 2150 } // namespace disk_cache |
| OLD | NEW |