OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/location.h" |
| 6 #include "base/message_loop_proxy.h" |
| 7 #include "base/task_runner_util.h" |
| 8 #include "net/base/io_buffer.h" |
| 9 #include "net/base/net_errors.h" |
| 10 #include "net/disk_cache/flash/flash_entry_impl.h" |
| 11 #include "net/disk_cache/flash/internal_entry.h" |
| 12 |
| 13 namespace disk_cache { |
| 14 |
| 15 FlashEntryImpl::FlashEntryImpl(const std::string& key, |
| 16 LogStore* store, |
| 17 base::MessageLoopProxy* cache_thread) |
| 18 : init_(false), |
| 19 key_(key), |
| 20 new_internal_entry_(new InternalEntry(key, store)), |
| 21 cache_thread_(cache_thread) { |
| 22 } |
| 23 |
| 24 FlashEntryImpl::FlashEntryImpl(int32 id, |
| 25 LogStore* store, |
| 26 base::MessageLoopProxy* cache_thread) |
| 27 : init_(false), |
| 28 old_internal_entry_(new InternalEntry(id, store)), |
| 29 cache_thread_(cache_thread) { |
| 30 } |
| 31 |
| 32 int FlashEntryImpl::Init(const CompletionCallback& callback) { |
| 33 if (new_internal_entry_) { |
| 34 DCHECK(callback.is_null()); |
| 35 init_ = true; |
| 36 return net::OK; |
| 37 } |
| 38 DCHECK(!callback.is_null() && old_internal_entry_); |
| 39 callback_ = callback; |
| 40 PostTaskAndReplyWithResult(cache_thread_, FROM_HERE, |
| 41 Bind(&InternalEntry::Init, old_internal_entry_), |
| 42 Bind(&FlashEntryImpl::OnInitComplete, this)); |
| 43 return net::ERR_IO_PENDING; |
| 44 } |
| 45 |
| 46 void FlashEntryImpl::Doom() { |
| 47 DCHECK(init_); |
| 48 NOTREACHED(); |
| 49 } |
| 50 |
| 51 void FlashEntryImpl::Close() { |
| 52 DCHECK(init_); |
| 53 Release(); |
| 54 } |
| 55 |
| 56 std::string FlashEntryImpl::GetKey() const { |
| 57 DCHECK(init_); |
| 58 return key_; |
| 59 } |
| 60 |
| 61 base::Time FlashEntryImpl::GetLastUsed() const { |
| 62 DCHECK(init_); |
| 63 NOTREACHED(); |
| 64 return base::Time::Now(); |
| 65 } |
| 66 |
| 67 base::Time FlashEntryImpl::GetLastModified() const { |
| 68 DCHECK(init_); |
| 69 NOTREACHED(); |
| 70 return base::Time::Now(); |
| 71 } |
| 72 |
| 73 int32 FlashEntryImpl::GetDataSize(int index) const { |
| 74 DCHECK(init_); |
| 75 return new_internal_entry_->GetDataSize(index); |
| 76 } |
| 77 |
| 78 int FlashEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, |
| 79 const CompletionCallback& callback) { |
| 80 DCHECK(init_); |
| 81 return new_internal_entry_->ReadData(index, offset, buf, buf_len, callback); |
| 82 } |
| 83 |
| 84 int FlashEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, |
| 85 const CompletionCallback& callback, |
| 86 bool truncate) { |
| 87 DCHECK(init_); |
| 88 return new_internal_entry_->WriteData(index, offset, buf, buf_len, callback); |
| 89 } |
| 90 |
| 91 int FlashEntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, |
| 92 const CompletionCallback& callback) { |
| 93 DCHECK(init_); |
| 94 NOTREACHED(); |
| 95 return net::ERR_FAILED; |
| 96 } |
| 97 |
| 98 int FlashEntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, |
| 99 const CompletionCallback& callback) { |
| 100 DCHECK(init_); |
| 101 NOTREACHED(); |
| 102 return net::ERR_FAILED; |
| 103 } |
| 104 |
| 105 int FlashEntryImpl::GetAvailableRange(int64 offset, int len, int64* start, |
| 106 const CompletionCallback& callback) { |
| 107 DCHECK(init_); |
| 108 NOTREACHED(); |
| 109 return net::ERR_FAILED; |
| 110 } |
| 111 |
| 112 bool FlashEntryImpl::CouldBeSparse() const { |
| 113 DCHECK(init_); |
| 114 NOTREACHED(); |
| 115 return false; |
| 116 } |
| 117 |
| 118 void FlashEntryImpl::CancelSparseIO() { |
| 119 DCHECK(init_); |
| 120 NOTREACHED(); |
| 121 } |
| 122 |
| 123 int FlashEntryImpl::ReadyForSparseIO(const CompletionCallback& callback) { |
| 124 DCHECK(init_); |
| 125 NOTREACHED(); |
| 126 return net::ERR_FAILED; |
| 127 } |
| 128 |
| 129 void FlashEntryImpl::OnInitComplete( |
| 130 scoped_ptr<KeyAndStreamSizes> key_and_stream_sizes) { |
| 131 DCHECK(!callback_.is_null()); |
| 132 if (!key_and_stream_sizes) { |
| 133 callback_.Run(net::ERR_FAILED); |
| 134 } else { |
| 135 key_ = key_and_stream_sizes->key; |
| 136 memcpy(stream_sizes_, key_and_stream_sizes->stream_sizes, |
| 137 sizeof(stream_sizes_)); |
| 138 init_ = true; |
| 139 callback_.Run(net::OK); |
| 140 } |
| 141 } |
| 142 |
| 143 FlashEntryImpl::~FlashEntryImpl() { |
| 144 cache_thread_->PostTask(FROM_HERE, |
| 145 Bind(&InternalEntry::Close, new_internal_entry_)); |
| 146 } |
| 147 |
| 148 } // namespace disk_cache |
OLD | NEW |