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 in_memory_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 defer_op_(DEFER_NONE), | 79 defer_op_(DEFER_NONE), |
79 resume_return_code_(0) { | 80 resume_return_code_(0) { |
80 test_mode_ = GetTestModeForEntry(key); | 81 test_mode_ = GetTestModeForEntry(key); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 //----------------------------------------------------------------------------- | 388 //----------------------------------------------------------------------------- |
388 | 389 |
389 MockDiskCache::MockDiskCache() | 390 MockDiskCache::MockDiskCache() |
390 : open_count_(0), | 391 : open_count_(0), |
391 create_count_(0), | 392 create_count_(0), |
392 doomed_count_(0), | 393 doomed_count_(0), |
393 fail_requests_(false), | 394 fail_requests_(false), |
394 soft_failures_(false), | 395 soft_failures_(false), |
395 double_create_check_(true), | 396 double_create_check_(true), |
396 fail_sparse_requests_(false), | 397 fail_sparse_requests_(false), |
| 398 support_in_memory_entry_data_(true), |
397 defer_op_(MockDiskEntry::DEFER_NONE), | 399 defer_op_(MockDiskEntry::DEFER_NONE), |
398 resume_return_code_(0) {} | 400 resume_return_code_(0) {} |
399 | 401 |
400 MockDiskCache::~MockDiskCache() { | 402 MockDiskCache::~MockDiskCache() { |
401 ReleaseAll(); | 403 ReleaseAll(); |
402 } | 404 } |
403 | 405 |
404 CacheType MockDiskCache::GetCacheType() const { | 406 CacheType MockDiskCache::GetCacheType() const { |
405 return DISK_CACHE; | 407 return DISK_CACHE; |
406 } | 408 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 547 |
546 void MockDiskCache::OnExternalCacheHit(const std::string& key) { | 548 void MockDiskCache::OnExternalCacheHit(const std::string& key) { |
547 } | 549 } |
548 | 550 |
549 size_t MockDiskCache::DumpMemoryStats( | 551 size_t MockDiskCache::DumpMemoryStats( |
550 base::trace_event::ProcessMemoryDump* pmd, | 552 base::trace_event::ProcessMemoryDump* pmd, |
551 const std::string& parent_absolute_name) const { | 553 const std::string& parent_absolute_name) const { |
552 return 0u; | 554 return 0u; |
553 } | 555 } |
554 | 556 |
| 557 uint8_t MockDiskCache::GetEntryInMemoryData(const std::string& key) { |
| 558 if (!support_in_memory_entry_data_) |
| 559 return 0; |
| 560 |
| 561 EntryMap::iterator it = entries_.find(key); |
| 562 if (it != entries_.end()) |
| 563 return it->second->in_memory_data(); |
| 564 return 0; |
| 565 } |
| 566 |
| 567 void MockDiskCache::SetEntryInMemoryData(const std::string& key, uint8_t data) { |
| 568 EntryMap::iterator it = entries_.find(key); |
| 569 if (it != entries_.end()) |
| 570 it->second->set_in_memory_data(data); |
| 571 } |
| 572 |
555 void MockDiskCache::ReleaseAll() { | 573 void MockDiskCache::ReleaseAll() { |
556 for (auto entry : entries_) | 574 for (auto entry : entries_) |
557 entry.second->Release(); | 575 entry.second->Release(); |
558 entries_.clear(); | 576 entries_.clear(); |
559 } | 577 } |
560 | 578 |
561 void MockDiskCache::CallbackLater(const CompletionCallback& callback, | 579 void MockDiskCache::CallbackLater(const CompletionCallback& callback, |
562 int result) { | 580 int result) { |
563 base::ThreadTaskRunnerHandle::Get()->PostTask( | 581 base::ThreadTaskRunnerHandle::Get()->PostTask( |
564 FROM_HERE, base::Bind(&CallbackForwader, callback, result)); | 582 FROM_HERE, base::Bind(&CallbackForwader, callback, result)); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 if (!callback_.is_null()) { | 806 if (!callback_.is_null()) { |
789 if (!fail_) | 807 if (!fail_) |
790 backend_->reset(new MockDiskCache()); | 808 backend_->reset(new MockDiskCache()); |
791 CompletionCallback cb = callback_; | 809 CompletionCallback cb = callback_; |
792 callback_.Reset(); | 810 callback_.Reset(); |
793 cb.Run(Result()); // This object can be deleted here. | 811 cb.Run(Result()); // This object can be deleted here. |
794 } | 812 } |
795 } | 813 } |
796 | 814 |
797 } // namespace net | 815 } // namespace net |
OLD | NEW |