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 <limits> | 7 #include <limits> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 DCHECK_NE(net::APP_CACHE, cache_type_); | 380 DCHECK_NE(net::APP_CACHE, cache_type_); |
381 if (end_time.is_null()) | 381 if (end_time.is_null()) |
382 return SyncDoomEntriesSince(initial_time); | 382 return SyncDoomEntriesSince(initial_time); |
383 | 383 |
384 DCHECK(end_time >= initial_time); | 384 DCHECK(end_time >= initial_time); |
385 | 385 |
386 if (disabled_) | 386 if (disabled_) |
387 return net::ERR_FAILED; | 387 return net::ERR_FAILED; |
388 | 388 |
389 EntryImpl* node; | 389 EntryImpl* node; |
390 scoped_ptr<Rankings::Iterator> iterator(new Rankings::Iterator()); | 390 std::unique_ptr<Rankings::Iterator> iterator(new Rankings::Iterator()); |
391 EntryImpl* next = OpenNextEntryImpl(iterator.get()); | 391 EntryImpl* next = OpenNextEntryImpl(iterator.get()); |
392 if (!next) | 392 if (!next) |
393 return net::OK; | 393 return net::OK; |
394 | 394 |
395 while (next) { | 395 while (next) { |
396 node = next; | 396 node = next; |
397 next = OpenNextEntryImpl(iterator.get()); | 397 next = OpenNextEntryImpl(iterator.get()); |
398 | 398 |
399 if (node->GetLastUsed() >= initial_time && | 399 if (node->GetLastUsed() >= initial_time && |
400 node->GetLastUsed() < end_time) { | 400 node->GetLastUsed() < end_time) { |
(...skipping 21 matching lines...) Expand all Loading... |
422 | 422 |
423 // We use OpenNextEntryImpl to retrieve elements from the cache, until we get | 423 // We use OpenNextEntryImpl to retrieve elements from the cache, until we get |
424 // entries that are too old. | 424 // entries that are too old. |
425 int BackendImpl::SyncDoomEntriesSince(const base::Time initial_time) { | 425 int BackendImpl::SyncDoomEntriesSince(const base::Time initial_time) { |
426 DCHECK_NE(net::APP_CACHE, cache_type_); | 426 DCHECK_NE(net::APP_CACHE, cache_type_); |
427 if (disabled_) | 427 if (disabled_) |
428 return net::ERR_FAILED; | 428 return net::ERR_FAILED; |
429 | 429 |
430 stats_.OnEvent(Stats::DOOM_RECENT); | 430 stats_.OnEvent(Stats::DOOM_RECENT); |
431 for (;;) { | 431 for (;;) { |
432 scoped_ptr<Rankings::Iterator> iterator(new Rankings::Iterator()); | 432 std::unique_ptr<Rankings::Iterator> iterator(new Rankings::Iterator()); |
433 EntryImpl* entry = OpenNextEntryImpl(iterator.get()); | 433 EntryImpl* entry = OpenNextEntryImpl(iterator.get()); |
434 if (!entry) | 434 if (!entry) |
435 return net::OK; | 435 return net::OK; |
436 | 436 |
437 if (initial_time > entry->GetLastUsed()) { | 437 if (initial_time > entry->GetLastUsed()) { |
438 entry->Release(); | 438 entry->Release(); |
439 SyncEndEnumeration(std::move(iterator)); | 439 SyncEndEnumeration(std::move(iterator)); |
440 return net::OK; | 440 return net::OK; |
441 } | 441 } |
442 | 442 |
443 entry->DoomImpl(); | 443 entry->DoomImpl(); |
444 entry->Release(); | 444 entry->Release(); |
445 SyncEndEnumeration( | 445 SyncEndEnumeration( |
446 std::move(iterator)); // The doom invalidated the iterator. | 446 std::move(iterator)); // The doom invalidated the iterator. |
447 } | 447 } |
448 } | 448 } |
449 | 449 |
450 int BackendImpl::SyncOpenNextEntry(Rankings::Iterator* iterator, | 450 int BackendImpl::SyncOpenNextEntry(Rankings::Iterator* iterator, |
451 Entry** next_entry) { | 451 Entry** next_entry) { |
452 *next_entry = OpenNextEntryImpl(iterator); | 452 *next_entry = OpenNextEntryImpl(iterator); |
453 return (*next_entry) ? net::OK : net::ERR_FAILED; | 453 return (*next_entry) ? net::OK : net::ERR_FAILED; |
454 } | 454 } |
455 | 455 |
456 void BackendImpl::SyncEndEnumeration(scoped_ptr<Rankings::Iterator> iterator) { | 456 void BackendImpl::SyncEndEnumeration( |
| 457 std::unique_ptr<Rankings::Iterator> iterator) { |
457 iterator->Reset(); | 458 iterator->Reset(); |
458 } | 459 } |
459 | 460 |
460 void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { | 461 void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { |
461 if (disabled_) | 462 if (disabled_) |
462 return; | 463 return; |
463 | 464 |
464 uint32_t hash = base::Hash(key); | 465 uint32_t hash = base::Hash(key); |
465 bool error; | 466 bool error; |
466 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); | 467 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1289 int OpenNextEntry(Entry** next_entry, | 1290 int OpenNextEntry(Entry** next_entry, |
1290 const net::CompletionCallback& callback) override { | 1291 const net::CompletionCallback& callback) override { |
1291 if (!background_queue_) | 1292 if (!background_queue_) |
1292 return net::ERR_FAILED; | 1293 return net::ERR_FAILED; |
1293 background_queue_->OpenNextEntry(iterator_.get(), next_entry, callback); | 1294 background_queue_->OpenNextEntry(iterator_.get(), next_entry, callback); |
1294 return net::ERR_IO_PENDING; | 1295 return net::ERR_IO_PENDING; |
1295 } | 1296 } |
1296 | 1297 |
1297 private: | 1298 private: |
1298 const base::WeakPtr<InFlightBackendIO> background_queue_; | 1299 const base::WeakPtr<InFlightBackendIO> background_queue_; |
1299 scoped_ptr<Rankings::Iterator> iterator_; | 1300 std::unique_ptr<Rankings::Iterator> iterator_; |
1300 }; | 1301 }; |
1301 | 1302 |
1302 scoped_ptr<Backend::Iterator> BackendImpl::CreateIterator() { | 1303 std::unique_ptr<Backend::Iterator> BackendImpl::CreateIterator() { |
1303 return scoped_ptr<Backend::Iterator>(new IteratorImpl(GetBackgroundQueue())); | 1304 return std::unique_ptr<Backend::Iterator>( |
| 1305 new IteratorImpl(GetBackgroundQueue())); |
1304 } | 1306 } |
1305 | 1307 |
1306 void BackendImpl::GetStats(StatsItems* stats) { | 1308 void BackendImpl::GetStats(StatsItems* stats) { |
1307 if (disabled_) | 1309 if (disabled_) |
1308 return; | 1310 return; |
1309 | 1311 |
1310 std::pair<std::string, std::string> item; | 1312 std::pair<std::string, std::string> item; |
1311 | 1313 |
1312 item.first = "Entries"; | 1314 item.first = "Entries"; |
1313 item.second = base::IntToString(data_->header.num_entries); | 1315 item.second = base::IntToString(data_->header.num_entries); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 NOTREACHED(); | 1451 NOTREACHED(); |
1450 return false; | 1452 return false; |
1451 } | 1453 } |
1452 | 1454 |
1453 // Load the required data. | 1455 // Load the required data. |
1454 size = address.num_blocks() * address.BlockSize(); | 1456 size = address.num_blocks() * address.BlockSize(); |
1455 MappedFile* file = File(address); | 1457 MappedFile* file = File(address); |
1456 if (!file) | 1458 if (!file) |
1457 return false; | 1459 return false; |
1458 | 1460 |
1459 scoped_ptr<char[]> data(new char[size]); | 1461 std::unique_ptr<char[]> data(new char[size]); |
1460 size_t offset = address.start_block() * address.BlockSize() + | 1462 size_t offset = address.start_block() * address.BlockSize() + |
1461 kBlockHeaderSize; | 1463 kBlockHeaderSize; |
1462 if (!file->Read(data.get(), size, offset)) | 1464 if (!file->Read(data.get(), size, offset)) |
1463 return false; | 1465 return false; |
1464 | 1466 |
1465 if (!stats_.Init(data.get(), size, address)) | 1467 if (!stats_.Init(data.get(), size, address)) |
1466 return false; | 1468 return false; |
1467 if (cache_type_ == net::DISK_CACHE && ShouldReportAgain()) | 1469 if (cache_type_ == net::DISK_CACHE && ShouldReportAgain()) |
1468 stats_.InitSizeHistogram(); | 1470 stats_.InitSizeHistogram(); |
1469 return true; | 1471 return true; |
1470 } | 1472 } |
1471 | 1473 |
1472 void BackendImpl::StoreStats() { | 1474 void BackendImpl::StoreStats() { |
1473 int size = stats_.StorageSize(); | 1475 int size = stats_.StorageSize(); |
1474 scoped_ptr<char[]> data(new char[size]); | 1476 std::unique_ptr<char[]> data(new char[size]); |
1475 Addr address; | 1477 Addr address; |
1476 size = stats_.SerializeStats(data.get(), size, &address); | 1478 size = stats_.SerializeStats(data.get(), size, &address); |
1477 DCHECK(size); | 1479 DCHECK(size); |
1478 if (!address.is_initialized()) | 1480 if (!address.is_initialized()) |
1479 return; | 1481 return; |
1480 | 1482 |
1481 MappedFile* file = File(address); | 1483 MappedFile* file = File(address); |
1482 if (!file) | 1484 if (!file) |
1483 return; | 1485 return; |
1484 | 1486 |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2114 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 2116 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
2115 total_memory = kMaxBuffersSize; | 2117 total_memory = kMaxBuffersSize; |
2116 | 2118 |
2117 done = true; | 2119 done = true; |
2118 } | 2120 } |
2119 | 2121 |
2120 return static_cast<int>(total_memory); | 2122 return static_cast<int>(total_memory); |
2121 } | 2123 } |
2122 | 2124 |
2123 } // namespace disk_cache | 2125 } // namespace disk_cache |
OLD | NEW |