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