| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/backend_impl.h" | 5 #include "net/disk_cache/backend_impl.h" |
| 6 | 6 |
| 7 #include "base/field_trial.h" | 7 #include "base/field_trial.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 15 #include "base/timer.h" | 15 #include "base/timer.h" |
| 16 #include "base/worker_pool.h" | 16 #include "base/worker_pool.h" |
| 17 #include "net/base/net_errors.h" |
| 17 #include "net/disk_cache/cache_util.h" | 18 #include "net/disk_cache/cache_util.h" |
| 18 #include "net/disk_cache/entry_impl.h" | 19 #include "net/disk_cache/entry_impl.h" |
| 19 #include "net/disk_cache/errors.h" | 20 #include "net/disk_cache/errors.h" |
| 20 #include "net/disk_cache/hash.h" | 21 #include "net/disk_cache/hash.h" |
| 21 #include "net/disk_cache/file.h" | 22 #include "net/disk_cache/file.h" |
| 22 | 23 |
| 23 // This has to be defined before including histogram_macros.h from this file. | 24 // This has to be defined before including histogram_macros.h from this file. |
| 24 #define NET_DISK_CACHE_BACKEND_IMPL_CC_ | 25 #define NET_DISK_CACHE_BACKEND_IMPL_CC_ |
| 25 #include "net/disk_cache/histogram_macros.h" | 26 #include "net/disk_cache/histogram_macros.h" |
| 26 | 27 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 373 |
| 373 eviction_.OnOpenEntry(cache_entry); | 374 eviction_.OnOpenEntry(cache_entry); |
| 374 DCHECK(entry); | 375 DCHECK(entry); |
| 375 *entry = cache_entry; | 376 *entry = cache_entry; |
| 376 | 377 |
| 377 CACHE_UMA(AGE_MS, "OpenTime", GetSizeGroup(), start); | 378 CACHE_UMA(AGE_MS, "OpenTime", GetSizeGroup(), start); |
| 378 stats_.OnEvent(Stats::OPEN_HIT); | 379 stats_.OnEvent(Stats::OPEN_HIT); |
| 379 return true; | 380 return true; |
| 380 } | 381 } |
| 381 | 382 |
| 383 int BackendImpl::OpenEntry(const std::string& key, Entry** entry, |
| 384 CompletionCallback* callback) { |
| 385 if (OpenEntry(key, entry)) |
| 386 return net::OK; |
| 387 |
| 388 return net::ERR_FAILED; |
| 389 } |
| 390 |
| 382 bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) { | 391 bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) { |
| 383 if (disabled_ || key.empty()) | 392 if (disabled_ || key.empty()) |
| 384 return false; | 393 return false; |
| 385 | 394 |
| 386 DCHECK(entry); | 395 DCHECK(entry); |
| 387 *entry = NULL; | 396 *entry = NULL; |
| 388 | 397 |
| 389 Time start = Time::Now(); | 398 Time start = Time::Now(); |
| 390 uint32 hash = Hash(key); | 399 uint32 hash = Hash(key); |
| 391 | 400 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 data_->table[hash & mask_] = entry_address.value(); | 463 data_->table[hash & mask_] = entry_address.value(); |
| 455 | 464 |
| 456 cache_entry.swap(reinterpret_cast<EntryImpl**>(entry)); | 465 cache_entry.swap(reinterpret_cast<EntryImpl**>(entry)); |
| 457 | 466 |
| 458 CACHE_UMA(AGE_MS, "CreateTime", GetSizeGroup(), start); | 467 CACHE_UMA(AGE_MS, "CreateTime", GetSizeGroup(), start); |
| 459 stats_.OnEvent(Stats::CREATE_HIT); | 468 stats_.OnEvent(Stats::CREATE_HIT); |
| 460 Trace("create entry hit "); | 469 Trace("create entry hit "); |
| 461 return true; | 470 return true; |
| 462 } | 471 } |
| 463 | 472 |
| 473 int BackendImpl::CreateEntry(const std::string& key, Entry** entry, |
| 474 CompletionCallback* callback) { |
| 475 if (CreateEntry(key, entry)) |
| 476 return net::OK; |
| 477 |
| 478 return net::ERR_FAILED; |
| 479 } |
| 480 |
| 464 bool BackendImpl::DoomEntry(const std::string& key) { | 481 bool BackendImpl::DoomEntry(const std::string& key) { |
| 465 if (disabled_) | 482 if (disabled_) |
| 466 return false; | 483 return false; |
| 467 | 484 |
| 468 Entry* entry; | 485 Entry* entry; |
| 469 if (!OpenEntry(key, &entry)) | 486 if (!OpenEntry(key, &entry)) |
| 470 return false; | 487 return false; |
| 471 | 488 |
| 472 // Note that you'd think you could just pass &entry_impl to OpenEntry, | 489 // Note that you'd think you could just pass &entry_impl to OpenEntry, |
| 473 // but that triggers strict aliasing problems with gcc. | 490 // but that triggers strict aliasing problems with gcc. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 485 } else { | 502 } else { |
| 486 if (disabled_) | 503 if (disabled_) |
| 487 return false; | 504 return false; |
| 488 | 505 |
| 489 eviction_.TrimCache(true); | 506 eviction_.TrimCache(true); |
| 490 stats_.OnEvent(Stats::DOOM_CACHE); | 507 stats_.OnEvent(Stats::DOOM_CACHE); |
| 491 return true; | 508 return true; |
| 492 } | 509 } |
| 493 } | 510 } |
| 494 | 511 |
| 512 int BackendImpl::DoomAllEntries(CompletionCallback* callback) { |
| 513 if (DoomAllEntries()) |
| 514 return net::OK; |
| 515 |
| 516 return net::ERR_FAILED; |
| 517 } |
| 518 |
| 495 bool BackendImpl::DoomEntriesBetween(const Time initial_time, | 519 bool BackendImpl::DoomEntriesBetween(const Time initial_time, |
| 496 const Time end_time) { | 520 const Time end_time) { |
| 497 if (end_time.is_null()) | 521 if (end_time.is_null()) |
| 498 return DoomEntriesSince(initial_time); | 522 return DoomEntriesSince(initial_time); |
| 499 | 523 |
| 500 DCHECK(end_time >= initial_time); | 524 DCHECK(end_time >= initial_time); |
| 501 | 525 |
| 502 if (disabled_) | 526 if (disabled_) |
| 503 return false; | 527 return false; |
| 504 | 528 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 521 next = NULL; | 545 next = NULL; |
| 522 EndEnumeration(&iter); | 546 EndEnumeration(&iter); |
| 523 } | 547 } |
| 524 | 548 |
| 525 node->Close(); | 549 node->Close(); |
| 526 } | 550 } |
| 527 | 551 |
| 528 return true; | 552 return true; |
| 529 } | 553 } |
| 530 | 554 |
| 555 int BackendImpl::DoomEntriesBetween(const base::Time initial_time, |
| 556 const base::Time end_time, |
| 557 CompletionCallback* callback) { |
| 558 if (DoomEntriesBetween(initial_time, end_time)) |
| 559 return net::OK; |
| 560 |
| 561 return net::ERR_FAILED; |
| 562 } |
| 563 |
| 531 // We use OpenNextEntry to retrieve elements from the cache, until we get | 564 // We use OpenNextEntry to retrieve elements from the cache, until we get |
| 532 // entries that are too old. | 565 // entries that are too old. |
| 533 bool BackendImpl::DoomEntriesSince(const Time initial_time) { | 566 bool BackendImpl::DoomEntriesSince(const Time initial_time) { |
| 534 if (disabled_) | 567 if (disabled_) |
| 535 return false; | 568 return false; |
| 536 | 569 |
| 537 for (;;) { | 570 for (;;) { |
| 538 Entry* entry; | 571 Entry* entry; |
| 539 void* iter = NULL; | 572 void* iter = NULL; |
| 540 if (!OpenNextEntry(&iter, &entry)) | 573 if (!OpenNextEntry(&iter, &entry)) |
| 541 return true; | 574 return true; |
| 542 | 575 |
| 543 if (initial_time > entry->GetLastUsed()) { | 576 if (initial_time > entry->GetLastUsed()) { |
| 544 entry->Close(); | 577 entry->Close(); |
| 545 EndEnumeration(&iter); | 578 EndEnumeration(&iter); |
| 546 return true; | 579 return true; |
| 547 } | 580 } |
| 548 | 581 |
| 549 entry->Doom(); | 582 entry->Doom(); |
| 550 entry->Close(); | 583 entry->Close(); |
| 551 EndEnumeration(&iter); // Dooming the entry invalidates the iterator. | 584 EndEnumeration(&iter); // Dooming the entry invalidates the iterator. |
| 552 } | 585 } |
| 553 } | 586 } |
| 554 | 587 |
| 588 int BackendImpl::DoomEntriesSince(const base::Time initial_time, |
| 589 CompletionCallback* callback) { |
| 590 if (DoomEntriesSince(initial_time)) |
| 591 return net::OK; |
| 592 |
| 593 return net::ERR_FAILED; |
| 594 } |
| 595 |
| 555 bool BackendImpl::OpenNextEntry(void** iter, Entry** next_entry) { | 596 bool BackendImpl::OpenNextEntry(void** iter, Entry** next_entry) { |
| 556 return OpenFollowingEntry(true, iter, next_entry); | 597 return OpenFollowingEntry(true, iter, next_entry); |
| 557 } | 598 } |
| 558 | 599 |
| 600 int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry, |
| 601 CompletionCallback* callback) { |
| 602 if (OpenNextEntry(iter, next_entry)) |
| 603 return net::OK; |
| 604 |
| 605 return net::ERR_FAILED; |
| 606 } |
| 607 |
| 559 void BackendImpl::EndEnumeration(void** iter) { | 608 void BackendImpl::EndEnumeration(void** iter) { |
| 560 scoped_ptr<Rankings::Iterator> iterator( | 609 scoped_ptr<Rankings::Iterator> iterator( |
| 561 reinterpret_cast<Rankings::Iterator*>(*iter)); | 610 reinterpret_cast<Rankings::Iterator*>(*iter)); |
| 562 *iter = NULL; | 611 *iter = NULL; |
| 563 } | 612 } |
| 564 | 613 |
| 565 void BackendImpl::GetStats(StatsItems* stats) { | 614 void BackendImpl::GetStats(StatsItems* stats) { |
| 566 if (disabled_) | 615 if (disabled_) |
| 567 return; | 616 return; |
| 568 | 617 |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 | 1667 |
| 1619 return num_dirty; | 1668 return num_dirty; |
| 1620 } | 1669 } |
| 1621 | 1670 |
| 1622 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { | 1671 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { |
| 1623 RankingsNode* rankings = cache_entry->rankings()->Data(); | 1672 RankingsNode* rankings = cache_entry->rankings()->Data(); |
| 1624 return !rankings->dummy; | 1673 return !rankings->dummy; |
| 1625 } | 1674 } |
| 1626 | 1675 |
| 1627 } // namespace disk_cache | 1676 } // namespace disk_cache |
| OLD | NEW |