| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/simple/simple_backend_impl.h" | 5 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 #include <functional> | 9 #include <functional> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 const CompletionCallback& callback) { | 451 const CompletionCallback& callback) { |
| 452 return DoomEntriesBetween(initial_time, Time(), callback); | 452 return DoomEntriesBetween(initial_time, Time(), callback); |
| 453 } | 453 } |
| 454 | 454 |
| 455 int SimpleBackendImpl::CalculateSizeOfAllEntries( | 455 int SimpleBackendImpl::CalculateSizeOfAllEntries( |
| 456 const CompletionCallback& callback) { | 456 const CompletionCallback& callback) { |
| 457 return index_->ExecuteWhenReady(base::Bind( | 457 return index_->ExecuteWhenReady(base::Bind( |
| 458 &SimpleBackendImpl::IndexReadyForSizeCalculation, AsWeakPtr(), callback)); | 458 &SimpleBackendImpl::IndexReadyForSizeCalculation, AsWeakPtr(), callback)); |
| 459 } | 459 } |
| 460 | 460 |
| 461 int SimpleBackendImpl::CalculateSizeOfEntriesBetween( |
| 462 base::Time initial_time, |
| 463 base::Time end_time, |
| 464 const CompletionCallback& callback) { |
| 465 return index_->ExecuteWhenReady( |
| 466 base::Bind(&SimpleBackendImpl::IndexReadyForSizeBetweenCalculation, |
| 467 AsWeakPtr(), initial_time, end_time, callback)); |
| 468 } |
| 469 |
| 461 class SimpleBackendImpl::SimpleIterator final : public Iterator { | 470 class SimpleBackendImpl::SimpleIterator final : public Iterator { |
| 462 public: | 471 public: |
| 463 explicit SimpleIterator(base::WeakPtr<SimpleBackendImpl> backend) | 472 explicit SimpleIterator(base::WeakPtr<SimpleBackendImpl> backend) |
| 464 : backend_(backend), | 473 : backend_(backend), |
| 465 weak_factory_(this) { | 474 weak_factory_(this) { |
| 466 } | 475 } |
| 467 | 476 |
| 468 // From Backend::Iterator: | 477 // From Backend::Iterator: |
| 469 int OpenNextEntry(Entry** next_entry, | 478 int OpenNextEntry(Entry** next_entry, |
| 470 const CompletionCallback& callback) override { | 479 const CompletionCallback& callback) override { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 } | 575 } |
| 567 | 576 |
| 568 void SimpleBackendImpl::IndexReadyForSizeCalculation( | 577 void SimpleBackendImpl::IndexReadyForSizeCalculation( |
| 569 const CompletionCallback& callback, | 578 const CompletionCallback& callback, |
| 570 int result) { | 579 int result) { |
| 571 if (result == net::OK) | 580 if (result == net::OK) |
| 572 result = static_cast<int>(index_->GetCacheSize()); | 581 result = static_cast<int>(index_->GetCacheSize()); |
| 573 callback.Run(result); | 582 callback.Run(result); |
| 574 } | 583 } |
| 575 | 584 |
| 585 void SimpleBackendImpl::IndexReadyForSizeBetweenCalculation( |
| 586 base::Time initial_time, |
| 587 base::Time end_time, |
| 588 const CompletionCallback& callback, |
| 589 int result) { |
| 590 if (result == net::OK) { |
| 591 result = |
| 592 static_cast<int>(index_->GetCacheSizeBetween(initial_time, end_time)); |
| 593 } |
| 594 callback.Run(result); |
| 595 } |
| 596 |
| 576 // static | 597 // static |
| 577 SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk( | 598 SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk( |
| 578 const base::FilePath& path, | 599 const base::FilePath& path, |
| 579 uint64_t suggested_max_size, | 600 uint64_t suggested_max_size, |
| 580 const SimpleExperiment& experiment) { | 601 const SimpleExperiment& experiment) { |
| 581 DiskStatResult result; | 602 DiskStatResult result; |
| 582 result.max_size = suggested_max_size; | 603 result.max_size = suggested_max_size; |
| 583 result.net_error = net::OK; | 604 result.net_error = net::OK; |
| 584 if (!FileStructureConsistent(path, experiment)) { | 605 if (!FileStructureConsistent(path, experiment)) { |
| 585 LOG(ERROR) << "Simple Cache Backend: wrong file structure on disk: " | 606 LOG(ERROR) << "Simple Cache Backend: wrong file structure on disk: " |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 } | 747 } |
| 727 | 748 |
| 728 // static | 749 // static |
| 729 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 750 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
| 730 // We only need to do this if we there is an active task runner. | 751 // We only need to do this if we there is an active task runner. |
| 731 if (base::ThreadTaskRunnerHandle::IsSet()) | 752 if (base::ThreadTaskRunnerHandle::IsSet()) |
| 732 g_sequenced_worker_pool.Get().FlushForTesting(); | 753 g_sequenced_worker_pool.Get().FlushForTesting(); |
| 733 } | 754 } |
| 734 | 755 |
| 735 } // namespace disk_cache | 756 } // namespace disk_cache |
| OLD | NEW |