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 | 10 |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 } | 435 } |
436 scoped_refptr<SimpleEntryImpl> simple_entry = | 436 scoped_refptr<SimpleEntryImpl> simple_entry = |
437 CreateOrFindActiveEntry(entry_hash, key); | 437 CreateOrFindActiveEntry(entry_hash, key); |
438 return simple_entry->DoomEntry(callback); | 438 return simple_entry->DoomEntry(callback); |
439 } | 439 } |
440 | 440 |
441 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) { | 441 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) { |
442 return DoomEntriesBetween(Time(), Time(), callback); | 442 return DoomEntriesBetween(Time(), Time(), callback); |
443 } | 443 } |
444 | 444 |
445 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, | |
446 Time end_time, | |
447 const CompletionCallback& callback, | |
448 int result) { | |
449 if (result != net::OK) { | |
450 callback.Run(result); | |
451 return; | |
452 } | |
453 scoped_ptr<std::vector<uint64> > removed_key_hashes( | |
454 index_->GetEntriesBetween(initial_time, end_time).release()); | |
455 DoomEntries(removed_key_hashes.get(), callback); | |
456 } | |
457 | |
458 int SimpleBackendImpl::DoomEntriesBetween( | 445 int SimpleBackendImpl::DoomEntriesBetween( |
459 const Time initial_time, | 446 const Time initial_time, |
460 const Time end_time, | 447 const Time end_time, |
461 const CompletionCallback& callback) { | 448 const CompletionCallback& callback) { |
462 return index_->ExecuteWhenReady( | 449 return index_->ExecuteWhenReady( |
463 base::Bind(&SimpleBackendImpl::IndexReadyForDoom, AsWeakPtr(), | 450 base::Bind(&SimpleBackendImpl::IndexReadyForDoom, AsWeakPtr(), |
464 initial_time, end_time, callback)); | 451 initial_time, end_time, callback)); |
465 } | 452 } |
466 | 453 |
467 int SimpleBackendImpl::DoomEntriesSince( | 454 int SimpleBackendImpl::DoomEntriesSince( |
468 const Time initial_time, | 455 const Time initial_time, |
469 const CompletionCallback& callback) { | 456 const CompletionCallback& callback) { |
470 return DoomEntriesBetween(initial_time, Time(), callback); | 457 return DoomEntriesBetween(initial_time, Time(), callback); |
471 } | 458 } |
472 | 459 |
473 int SimpleBackendImpl::CalculateSizeOfAllEntries( | 460 int SimpleBackendImpl::CalculateSizeOfAllEntries( |
474 const CompletionCallback& callback) { | 461 const CompletionCallback& callback) { |
475 // TODO(msramek): Implement. | 462 return index_->ExecuteWhenReady(base::Bind( |
476 return net::ERR_NOT_IMPLEMENTED; | 463 &SimpleBackendImpl::IndexReadyForSizeCalculation, AsWeakPtr(), callback)); |
477 } | 464 } |
478 | 465 |
479 class SimpleBackendImpl::SimpleIterator final : public Iterator { | 466 class SimpleBackendImpl::SimpleIterator final : public Iterator { |
480 public: | 467 public: |
481 explicit SimpleIterator(base::WeakPtr<SimpleBackendImpl> backend) | 468 explicit SimpleIterator(base::WeakPtr<SimpleBackendImpl> backend) |
482 : backend_(backend), | 469 : backend_(backend), |
483 weak_factory_(this) { | 470 weak_factory_(this) { |
484 } | 471 } |
485 | 472 |
486 // From Backend::Iterator: | 473 // From Backend::Iterator: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 550 |
564 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, | 551 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, |
565 const DiskStatResult& result) { | 552 const DiskStatResult& result) { |
566 if (result.net_error == net::OK) { | 553 if (result.net_error == net::OK) { |
567 index_->SetMaxSize(result.max_size); | 554 index_->SetMaxSize(result.max_size); |
568 index_->Initialize(result.cache_dir_mtime); | 555 index_->Initialize(result.cache_dir_mtime); |
569 } | 556 } |
570 callback.Run(result.net_error); | 557 callback.Run(result.net_error); |
571 } | 558 } |
572 | 559 |
| 560 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, |
| 561 Time end_time, |
| 562 const CompletionCallback& callback, |
| 563 int result) { |
| 564 if (result != net::OK) { |
| 565 callback.Run(result); |
| 566 return; |
| 567 } |
| 568 scoped_ptr<std::vector<uint64>> removed_key_hashes( |
| 569 index_->GetEntriesBetween(initial_time, end_time).release()); |
| 570 DoomEntries(removed_key_hashes.get(), callback); |
| 571 } |
| 572 |
| 573 void SimpleBackendImpl::IndexReadyForSizeCalculation( |
| 574 const CompletionCallback& callback, |
| 575 int result) { |
| 576 if (result == net::OK) |
| 577 result = static_cast<int>(index_->GetCacheSize()); |
| 578 callback.Run(result); |
| 579 } |
| 580 |
573 SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk( | 581 SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk( |
574 const base::FilePath& path, | 582 const base::FilePath& path, |
575 uint64 suggested_max_size) { | 583 uint64 suggested_max_size) { |
576 DiskStatResult result; | 584 DiskStatResult result; |
577 result.max_size = suggested_max_size; | 585 result.max_size = suggested_max_size; |
578 result.net_error = net::OK; | 586 result.net_error = net::OK; |
579 if (!FileStructureConsistent(path)) { | 587 if (!FileStructureConsistent(path)) { |
580 LOG(ERROR) << "Simple Cache Backend: wrong file structure on disk: " | 588 LOG(ERROR) << "Simple Cache Backend: wrong file structure on disk: " |
581 << path.LossyDisplayName(); | 589 << path.LossyDisplayName(); |
582 result.net_error = net::ERR_FAILED; | 590 result.net_error = net::ERR_FAILED; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 } | 747 } |
740 | 748 |
741 // static | 749 // static |
742 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 750 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
743 // 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. |
744 if (base::ThreadTaskRunnerHandle::IsSet()) | 752 if (base::ThreadTaskRunnerHandle::IsSet()) |
745 g_sequenced_worker_pool.Get().FlushForTesting(); | 753 g_sequenced_worker_pool.Get().FlushForTesting(); |
746 } | 754 } |
747 | 755 |
748 } // namespace disk_cache | 756 } // namespace disk_cache |
OLD | NEW |