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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 | 515 |
515 void MockDiskCache::OnExternalCacheHit(const std::string& key) { | 516 void MockDiskCache::OnExternalCacheHit(const std::string& key) { |
516 } | 517 } |
517 | 518 |
518 size_t MockDiskCache::DumpMemoryStats( | 519 size_t MockDiskCache::DumpMemoryStats( |
519 base::trace_event::ProcessMemoryDump* pmd, | 520 base::trace_event::ProcessMemoryDump* pmd, |
520 const std::string& parent_absolute_name) const { | 521 const std::string& parent_absolute_name) const { |
521 return 0u; | 522 return 0u; |
522 } | 523 } |
523 | 524 |
| 525 uint8_t MockDiskCache::GetMemoryEntryData(const std::string& key) { |
| 526 EntryMap::iterator it = entries_.find(key); |
| 527 if (it != entries_.end()) |
| 528 return it->second->memory_entry_data(); |
| 529 return 0; |
| 530 } |
| 531 |
| 532 void MockDiskCache::SetMemoryEntryData(const std::string& key, uint8_t data) { |
| 533 EntryMap::iterator it = entries_.find(key); |
| 534 if (it != entries_.end()) |
| 535 it->second->set_memory_entry_data(data); |
| 536 } |
| 537 |
524 void MockDiskCache::ReleaseAll() { | 538 void MockDiskCache::ReleaseAll() { |
525 EntryMap::iterator it = entries_.begin(); | 539 EntryMap::iterator it = entries_.begin(); |
526 for (; it != entries_.end(); ++it) | 540 for (; it != entries_.end(); ++it) |
527 it->second->Release(); | 541 it->second->Release(); |
528 entries_.clear(); | 542 entries_.clear(); |
529 } | 543 } |
530 | 544 |
531 void MockDiskCache::CallbackLater(const CompletionCallback& callback, | 545 void MockDiskCache::CallbackLater(const CompletionCallback& callback, |
532 int result) { | 546 int result) { |
533 base::ThreadTaskRunnerHandle::Get()->PostTask( | 547 base::ThreadTaskRunnerHandle::Get()->PostTask( |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 if (!callback_.is_null()) { | 752 if (!callback_.is_null()) { |
739 if (!fail_) | 753 if (!fail_) |
740 backend_->reset(new MockDiskCache()); | 754 backend_->reset(new MockDiskCache()); |
741 CompletionCallback cb = callback_; | 755 CompletionCallback cb = callback_; |
742 callback_.Reset(); | 756 callback_.Reset(); |
743 cb.Run(Result()); // This object can be deleted here. | 757 cb.Run(Result()); // This object can be deleted here. |
744 } | 758 } |
745 } | 759 } |
746 | 760 |
747 } // namespace net | 761 } // namespace net |
OLD | NEW |