| 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/http/mock_http_cache.h" | 5 #include "net/http/mock_http_cache.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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 //----------------------------------------------------------------------------- | 61 //----------------------------------------------------------------------------- |
| 62 | 62 |
| 63 struct MockDiskEntry::CallbackInfo { | 63 struct MockDiskEntry::CallbackInfo { |
| 64 scoped_refptr<MockDiskEntry> entry; | 64 scoped_refptr<MockDiskEntry> entry; |
| 65 CompletionCallback callback; | 65 CompletionCallback callback; |
| 66 int result; | 66 int result; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 MockDiskEntry::MockDiskEntry(const std::string& key) | 69 MockDiskEntry::MockDiskEntry(const std::string& key) |
| 70 : key_(key), | 70 : key_(key), |
| 71 memory_entry_data_(0), |
| 71 doomed_(false), | 72 doomed_(false), |
| 72 sparse_(false), | 73 sparse_(false), |
| 73 fail_requests_(false), | 74 fail_requests_(false), |
| 74 fail_sparse_requests_(false), | 75 fail_sparse_requests_(false), |
| 75 busy_(false), | 76 busy_(false), |
| 76 delayed_(false), | 77 delayed_(false), |
| 77 cancel_(false) { | 78 cancel_(false) { |
| 78 test_mode_ = GetTestModeForEntry(key); | 79 test_mode_ = GetTestModeForEntry(key); |
| 79 } | 80 } |
| 80 | 81 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 callback_list.clear(); | 364 callback_list.clear(); |
| 364 } | 365 } |
| 365 } | 366 } |
| 366 | 367 |
| 367 // Statics. | 368 // Statics. |
| 368 bool MockDiskEntry::ignore_callbacks_ = false; | 369 bool MockDiskEntry::ignore_callbacks_ = false; |
| 369 | 370 |
| 370 //----------------------------------------------------------------------------- | 371 //----------------------------------------------------------------------------- |
| 371 | 372 |
| 372 MockDiskCache::MockDiskCache() | 373 MockDiskCache::MockDiskCache() |
| 373 : open_count_(0), create_count_(0), fail_requests_(false), | 374 : open_count_(0), |
| 374 soft_failures_(false), double_create_check_(true), | 375 create_count_(0), |
| 375 fail_sparse_requests_(false) { | 376 fail_requests_(false), |
| 376 } | 377 soft_failures_(false), |
| 378 double_create_check_(true), |
| 379 fail_sparse_requests_(false), |
| 380 support_memory_entry_data_(true) {} |
| 377 | 381 |
| 378 MockDiskCache::~MockDiskCache() { | 382 MockDiskCache::~MockDiskCache() { |
| 379 ReleaseAll(); | 383 ReleaseAll(); |
| 380 } | 384 } |
| 381 | 385 |
| 382 CacheType MockDiskCache::GetCacheType() const { | 386 CacheType MockDiskCache::GetCacheType() const { |
| 383 return DISK_CACHE; | 387 return DISK_CACHE; |
| 384 } | 388 } |
| 385 | 389 |
| 386 int32_t MockDiskCache::GetEntryCount() const { | 390 int32_t MockDiskCache::GetEntryCount() const { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 518 |
| 515 void MockDiskCache::OnExternalCacheHit(const std::string& key) { | 519 void MockDiskCache::OnExternalCacheHit(const std::string& key) { |
| 516 } | 520 } |
| 517 | 521 |
| 518 size_t MockDiskCache::DumpMemoryStats( | 522 size_t MockDiskCache::DumpMemoryStats( |
| 519 base::trace_event::ProcessMemoryDump* pmd, | 523 base::trace_event::ProcessMemoryDump* pmd, |
| 520 const std::string& parent_absolute_name) const { | 524 const std::string& parent_absolute_name) const { |
| 521 return 0u; | 525 return 0u; |
| 522 } | 526 } |
| 523 | 527 |
| 528 uint8_t MockDiskCache::GetMemoryEntryData(const std::string& key) { |
| 529 if (!support_memory_entry_data_) |
| 530 return 0; |
| 531 |
| 532 EntryMap::iterator it = entries_.find(key); |
| 533 if (it != entries_.end()) |
| 534 return it->second->memory_entry_data(); |
| 535 return 0; |
| 536 } |
| 537 |
| 538 void MockDiskCache::SetMemoryEntryData(const std::string& key, uint8_t data) { |
| 539 EntryMap::iterator it = entries_.find(key); |
| 540 if (it != entries_.end()) |
| 541 it->second->set_memory_entry_data(data); |
| 542 } |
| 543 |
| 524 void MockDiskCache::ReleaseAll() { | 544 void MockDiskCache::ReleaseAll() { |
| 525 EntryMap::iterator it = entries_.begin(); | 545 EntryMap::iterator it = entries_.begin(); |
| 526 for (; it != entries_.end(); ++it) | 546 for (; it != entries_.end(); ++it) |
| 527 it->second->Release(); | 547 it->second->Release(); |
| 528 entries_.clear(); | 548 entries_.clear(); |
| 529 } | 549 } |
| 530 | 550 |
| 531 void MockDiskCache::CallbackLater(const CompletionCallback& callback, | 551 void MockDiskCache::CallbackLater(const CompletionCallback& callback, |
| 532 int result) { | 552 int result) { |
| 533 base::ThreadTaskRunnerHandle::Get()->PostTask( | 553 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 if (!callback_.is_null()) { | 762 if (!callback_.is_null()) { |
| 743 if (!fail_) | 763 if (!fail_) |
| 744 backend_->reset(new MockDiskCache()); | 764 backend_->reset(new MockDiskCache()); |
| 745 CompletionCallback cb = callback_; | 765 CompletionCallback cb = callback_; |
| 746 callback_.Reset(); | 766 callback_.Reset(); |
| 747 cb.Run(Result()); // This object can be deleted here. | 767 cb.Run(Result()); // This object can be deleted here. |
| 748 } | 768 } |
| 749 } | 769 } |
| 750 | 770 |
| 751 } // namespace net | 771 } // namespace net |
| OLD | NEW |