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