| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 base::Time MockDiskEntry::GetLastModified() const { | 85 base::Time MockDiskEntry::GetLastModified() const { |
| 86 return base::Time::FromInternalValue(0); | 86 return base::Time::FromInternalValue(0); |
| 87 } | 87 } |
| 88 | 88 |
| 89 int32 MockDiskEntry::GetDataSize(int index) const { | 89 int32 MockDiskEntry::GetDataSize(int index) const { |
| 90 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); | 90 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); |
| 91 return static_cast<int32>(data_[index].size()); | 91 return static_cast<int32>(data_[index].size()); |
| 92 } | 92 } |
| 93 | 93 |
| 94 int MockDiskEntry::GetEntrySize() const { |
| 95 int result = 0; |
| 96 for (int i = 0; i < kNumCacheEntryDataIndices; ++i) { |
| 97 result += GetDataSize(i); |
| 98 } |
| 99 return result; |
| 100 } |
| 101 |
| 94 int MockDiskEntry::ReadData(int index, | 102 int MockDiskEntry::ReadData(int index, |
| 95 int offset, | 103 int offset, |
| 96 IOBuffer* buf, | 104 IOBuffer* buf, |
| 97 int buf_len, | 105 int buf_len, |
| 98 const CompletionCallback& callback) { | 106 const CompletionCallback& callback) { |
| 99 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); | 107 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); |
| 100 DCHECK(!callback.is_null()); | 108 DCHECK(!callback.is_null()); |
| 101 | 109 |
| 102 if (fail_requests_) | 110 if (fail_requests_) |
| 103 return ERR_CACHE_READ_FAILURE; | 111 return ERR_CACHE_READ_FAILURE; |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 const base::Time end_time, | 478 const base::Time end_time, |
| 471 const CompletionCallback& callback) { | 479 const CompletionCallback& callback) { |
| 472 return ERR_NOT_IMPLEMENTED; | 480 return ERR_NOT_IMPLEMENTED; |
| 473 } | 481 } |
| 474 | 482 |
| 475 int MockDiskCache::DoomEntriesSince(const base::Time initial_time, | 483 int MockDiskCache::DoomEntriesSince(const base::Time initial_time, |
| 476 const CompletionCallback& callback) { | 484 const CompletionCallback& callback) { |
| 477 return ERR_NOT_IMPLEMENTED; | 485 return ERR_NOT_IMPLEMENTED; |
| 478 } | 486 } |
| 479 | 487 |
| 488 int MockDiskCache::CalculateSizeOfEntriesBetween( |
| 489 base::Time initial_time, |
| 490 base::Time end_time, |
| 491 const CompletionCallback& callback) { |
| 492 return ERR_NOT_IMPLEMENTED; |
| 493 } |
| 494 |
| 480 class MockDiskCache::NotImplementedIterator : public Iterator { | 495 class MockDiskCache::NotImplementedIterator : public Iterator { |
| 481 public: | 496 public: |
| 482 int OpenNextEntry(disk_cache::Entry** next_entry, | 497 int OpenNextEntry(disk_cache::Entry** next_entry, |
| 483 const CompletionCallback& callback) override { | 498 const CompletionCallback& callback) override { |
| 484 return ERR_NOT_IMPLEMENTED; | 499 return ERR_NOT_IMPLEMENTED; |
| 485 } | 500 } |
| 486 }; | 501 }; |
| 487 | 502 |
| 488 scoped_ptr<disk_cache::Backend::Iterator> MockDiskCache::CreateIterator() { | 503 scoped_ptr<disk_cache::Backend::Iterator> MockDiskCache::CreateIterator() { |
| 489 return scoped_ptr<Iterator>(new NotImplementedIterator()); | 504 return scoped_ptr<Iterator>(new NotImplementedIterator()); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 if (!callback_.is_null()) { | 676 if (!callback_.is_null()) { |
| 662 if (!fail_) | 677 if (!fail_) |
| 663 backend_->reset(new MockDiskCache()); | 678 backend_->reset(new MockDiskCache()); |
| 664 CompletionCallback cb = callback_; | 679 CompletionCallback cb = callback_; |
| 665 callback_.Reset(); | 680 callback_.Reset(); |
| 666 cb.Run(Result()); // This object can be deleted here. | 681 cb.Run(Result()); // This object can be deleted here. |
| 667 } | 682 } |
| 668 } | 683 } |
| 669 | 684 |
| 670 } // namespace net | 685 } // namespace net |
| OLD | NEW |