Chromium Code Reviews| 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_), | |
|
rvargas (doing something else)
2013/03/28 18:36:25
This requires InternalEntry to be RefCountedThread
agayev
2013/04/04 22:07:57
Done.
| |
| 42 Bind(&FlashEntryImpl::OnInitComplete, this)); | |
|
rvargas (doing something else)
2013/03/28 18:36:25
Ditto
agayev
2013/04/04 22:07:57
Done.
| |
| 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(scoped_ptr<KeyAndStreamSizes> rv) { | |
|
rvargas (doing something else)
2013/03/28 18:36:25
nit: result? use the same name you used on the dec
agayev
2013/04/04 22:07:57
Done.
| |
| 130 DCHECK(!callback_.is_null()); | |
| 131 if (!rv) { | |
| 132 callback_.Run(net::ERR_FAILED); | |
| 133 } else { | |
| 134 key_ = rv->key; | |
| 135 memcpy(stream_sizes_, rv->stream_sizes, sizeof(stream_sizes_)); | |
| 136 init_ = true; | |
| 137 callback_.Run(net::OK); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 FlashEntryImpl::~FlashEntryImpl() { | |
| 142 cache_thread_->PostTask(FROM_HERE, | |
| 143 Bind(&InternalEntry::Close, new_internal_entry_)); | |
| 144 } | |
| 145 | |
| 146 } // namespace disk_cache | |
| OLD | NEW |