| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/disk_cache/simple/simple_entry_impl.h" | 5 #include "net/disk_cache/simple/simple_entry_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Entry::Close() is expected to release this entry. See disk_cache.h for | 103 // Entry::Close() is expected to release this entry. See disk_cache.h for |
| 104 // details. | 104 // details. |
| 105 delete this; | 105 delete this; |
| 106 } | 106 } |
| 107 | 107 |
| 108 std::string SimpleEntryImpl::GetKey() const { | 108 std::string SimpleEntryImpl::GetKey() const { |
| 109 return key_; | 109 return key_; |
| 110 } | 110 } |
| 111 | 111 |
| 112 Time SimpleEntryImpl::GetLastUsed() const { | 112 Time SimpleEntryImpl::GetLastUsed() const { |
| 113 if (synchronous_entry_in_use_by_worker_) { | 113 return last_used_; |
| 114 NOTIMPLEMENTED(); | |
| 115 CHECK(false); | |
| 116 } | |
| 117 return synchronous_entry_->last_used(); | |
| 118 } | 114 } |
| 119 | 115 |
| 120 Time SimpleEntryImpl::GetLastModified() const { | 116 Time SimpleEntryImpl::GetLastModified() const { |
| 121 if (synchronous_entry_in_use_by_worker_) { | 117 return last_modified_; |
| 122 NOTIMPLEMENTED(); | |
| 123 CHECK(false); | |
| 124 } | |
| 125 return synchronous_entry_->last_modified(); | |
| 126 } | 118 } |
| 127 | 119 |
| 128 int32 SimpleEntryImpl::GetDataSize(int index) const { | 120 int32 SimpleEntryImpl::GetDataSize(int index) const { |
| 129 if (synchronous_entry_in_use_by_worker_) { | 121 return data_size_[index]; |
| 130 NOTIMPLEMENTED(); | |
| 131 CHECK(false); | |
| 132 } | |
| 133 return synchronous_entry_->data_size(index); | |
| 134 } | 122 } |
| 135 | 123 |
| 136 int SimpleEntryImpl::ReadData(int index, | 124 int SimpleEntryImpl::ReadData(int index, |
| 137 int offset, | 125 int offset, |
| 138 net::IOBuffer* buf, | 126 net::IOBuffer* buf, |
| 139 int buf_len, | 127 int buf_len, |
| 140 const CompletionCallback& callback) { | 128 const CompletionCallback& callback) { |
| 141 // TODO(gavinp): Add support for overlapping reads. The net::HttpCache does | 129 // TODO(gavinp): Add support for overlapping reads. The net::HttpCache does |
| 142 // make overlapping read requests when multiple transactions access the same | 130 // make overlapping read requests when multiple transactions access the same |
| 143 // entry as read only. | 131 // entry as read only. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 208 |
| 221 int SimpleEntryImpl::ReadyForSparseIO(const CompletionCallback& callback) { | 209 int SimpleEntryImpl::ReadyForSparseIO(const CompletionCallback& callback) { |
| 222 // TODO(gavinp): Determine if the simple backend should support sparse data. | 210 // TODO(gavinp): Determine if the simple backend should support sparse data. |
| 223 NOTIMPLEMENTED(); | 211 NOTIMPLEMENTED(); |
| 224 return net::ERR_FAILED; | 212 return net::ERR_FAILED; |
| 225 } | 213 } |
| 226 | 214 |
| 227 SimpleEntryImpl::SimpleEntryImpl( | 215 SimpleEntryImpl::SimpleEntryImpl( |
| 228 SimpleSynchronousEntry* synchronous_entry) | 216 SimpleSynchronousEntry* synchronous_entry) |
| 229 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 217 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 218 path_(synchronous_entry->path()), |
| 230 key_(synchronous_entry->key()), | 219 key_(synchronous_entry->key()), |
| 231 synchronous_entry_(synchronous_entry), | 220 synchronous_entry_(synchronous_entry), |
| 232 synchronous_entry_in_use_by_worker_(false), | 221 synchronous_entry_in_use_by_worker_(false), |
| 233 has_been_doomed_(false) { | 222 has_been_doomed_(false) { |
| 234 DCHECK(synchronous_entry); | 223 DCHECK(synchronous_entry); |
| 224 SetSynchronousData(); |
| 235 } | 225 } |
| 236 | 226 |
| 237 SimpleEntryImpl::~SimpleEntryImpl() { | 227 SimpleEntryImpl::~SimpleEntryImpl() { |
| 238 DCHECK(!synchronous_entry_); | 228 DCHECK(!synchronous_entry_); |
| 239 } | 229 } |
| 240 | 230 |
| 241 // static | 231 // static |
| 242 void SimpleEntryImpl::CreationOperationComplete( | 232 void SimpleEntryImpl::CreationOperationComplete( |
| 243 const CompletionCallback& completion_callback, | 233 const CompletionCallback& completion_callback, |
| 244 Entry** out_entry, | 234 Entry** out_entry, |
| 245 SimpleSynchronousEntry* sync_entry) { | 235 SimpleSynchronousEntry* sync_entry) { |
| 246 if (!sync_entry) { | 236 if (!sync_entry) { |
| 247 completion_callback.Run(net::ERR_FAILED); | 237 completion_callback.Run(net::ERR_FAILED); |
| 248 return; | 238 return; |
| 249 } | 239 } |
| 250 *out_entry = new SimpleEntryImpl(sync_entry); | 240 *out_entry = new SimpleEntryImpl(sync_entry); |
| 251 completion_callback.Run(net::OK); | 241 completion_callback.Run(net::OK); |
| 252 } | 242 } |
| 253 | 243 |
| 254 // static | 244 // static |
| 255 void SimpleEntryImpl::EntryOperationComplete( | 245 void SimpleEntryImpl::EntryOperationComplete( |
| 256 const CompletionCallback& completion_callback, | 246 const CompletionCallback& completion_callback, |
| 257 base::WeakPtr<SimpleEntryImpl> entry, | 247 base::WeakPtr<SimpleEntryImpl> entry, |
| 258 int result) { | 248 int result) { |
| 259 if (entry) { | 249 if (entry) { |
| 260 DCHECK(entry->synchronous_entry_in_use_by_worker_); | 250 DCHECK(entry->synchronous_entry_in_use_by_worker_); |
| 261 entry->synchronous_entry_in_use_by_worker_ = false; | 251 entry->synchronous_entry_in_use_by_worker_ = false; |
| 252 entry->SetSynchronousData(); |
| 262 } | 253 } |
| 263 completion_callback.Run(result); | 254 completion_callback.Run(result); |
| 264 } | 255 } |
| 265 | 256 |
| 257 void SimpleEntryImpl::SetSynchronousData() { |
| 258 DCHECK(!synchronous_entry_in_use_by_worker_); |
| 259 |
| 260 // TODO(felipeg): These copies to avoid data races are not optimal. While |
| 261 // adding an IO thread index (for fast misses etc...), we can store this data |
| 262 // in that structure. This also solves problems with last_used() on ext4 |
| 263 // filesystems not being accurate. |
| 264 |
| 265 last_used_ = synchronous_entry_->last_used(); |
| 266 last_modified_ = synchronous_entry_->last_modified(); |
| 267 for (int i = 0; i < kSimpleEntryFileCount; ++i) |
| 268 data_size_[i] = synchronous_entry_->data_size(i); |
| 269 } |
| 270 |
| 266 } // namespace disk_cache | 271 } // namespace disk_cache |
| OLD | NEW |