Chromium Code Reviews| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 delete this; | 204 delete this; |
| 205 } | 205 } |
| 206 | 206 |
| 207 std::string SimpleEntryImpl::GetKey() const { | 207 std::string SimpleEntryImpl::GetKey() const { |
| 208 DCHECK(thread_checker_.CalledOnValidThread()); | 208 DCHECK(thread_checker_.CalledOnValidThread()); |
| 209 return key_; | 209 return key_; |
| 210 } | 210 } |
| 211 | 211 |
| 212 Time SimpleEntryImpl::GetLastUsed() const { | 212 Time SimpleEntryImpl::GetLastUsed() const { |
| 213 DCHECK(thread_checker_.CalledOnValidThread()); | 213 DCHECK(thread_checker_.CalledOnValidThread()); |
| 214 if (!synchronous_entry_) { | 214 return last_used_; |
| 215 NOTIMPLEMENTED() << ": Synchronous operations overlapping an asynchronous " | |
| 216 << "operation."; | |
| 217 NOTREACHED(); | |
| 218 } | |
| 219 return synchronous_entry_->last_used(); | |
|
felipeg
2013/02/12 14:47:48
If we never set synchronous_entry_ to NULL as my c
pasko-google - do not use
2013/02/12 15:07:12
I disagree. Data races are never a good excuse for
| |
| 220 } | 215 } |
| 221 | 216 |
| 222 Time SimpleEntryImpl::GetLastModified() const { | 217 Time SimpleEntryImpl::GetLastModified() const { |
| 223 DCHECK(thread_checker_.CalledOnValidThread()); | 218 DCHECK(thread_checker_.CalledOnValidThread()); |
| 224 if (!synchronous_entry_) { | 219 return last_modified_; |
| 225 NOTIMPLEMENTED() << ": Synchronous operations overlapping an asynchronous " | |
| 226 << "operation."; | |
| 227 NOTREACHED(); | |
| 228 } | |
| 229 return synchronous_entry_->last_modified(); | |
| 230 } | 220 } |
| 231 | 221 |
| 232 int32 SimpleEntryImpl::GetDataSize(int index) const { | 222 int32 SimpleEntryImpl::GetDataSize(int index) const { |
| 233 DCHECK(thread_checker_.CalledOnValidThread()); | 223 DCHECK(thread_checker_.CalledOnValidThread()); |
| 234 if (!synchronous_entry_) { | 224 return data_size_[index]; |
| 235 NOTIMPLEMENTED() << ": Synchronous operations overlapping an asynchronous " | |
| 236 << "operation."; | |
| 237 NOTREACHED(); | |
| 238 } | |
| 239 return synchronous_entry_->data_size(index); | |
| 240 } | 225 } |
| 241 | 226 |
| 242 int SimpleEntryImpl::ReadData(int index, | 227 int SimpleEntryImpl::ReadData(int index, |
| 243 int offset, | 228 int offset, |
| 244 net::IOBuffer* buf, | 229 net::IOBuffer* buf, |
| 245 int buf_len, | 230 int buf_len, |
| 246 const CompletionCallback& callback) { | 231 const CompletionCallback& callback) { |
| 247 DCHECK(thread_checker_.CalledOnValidThread()); | 232 DCHECK(thread_checker_.CalledOnValidThread()); |
| 248 // TODO(gavinp): Add support for overlapping reads. The net::HttpCache does | 233 // TODO(gavinp): Add support for overlapping reads. The net::HttpCache does |
| 249 // make overlapping read requests when multiple transactions access the same | 234 // make overlapping read requests when multiple transactions access the same |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 int SimpleEntryImpl::ReadyForSparseIO(const CompletionCallback& callback) { | 315 int SimpleEntryImpl::ReadyForSparseIO(const CompletionCallback& callback) { |
| 331 // TODO(gavinp): Determine if the simple backend should support sparse data. | 316 // TODO(gavinp): Determine if the simple backend should support sparse data. |
| 332 DCHECK(thread_checker_.CalledOnValidThread()); | 317 DCHECK(thread_checker_.CalledOnValidThread()); |
| 333 NOTIMPLEMENTED(); | 318 NOTIMPLEMENTED(); |
| 334 return net::ERR_FAILED; | 319 return net::ERR_FAILED; |
| 335 } | 320 } |
| 336 | 321 |
| 337 SimpleEntryImpl::SimpleEntryImpl( | 322 SimpleEntryImpl::SimpleEntryImpl( |
| 338 SimpleSynchronousEntry* synchronous_entry) | 323 SimpleSynchronousEntry* synchronous_entry) |
| 339 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 324 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 325 path_(synchronous_entry->path()), | |
| 340 key_(synchronous_entry->key()), | 326 key_(synchronous_entry->key()), |
| 341 synchronous_entry_(synchronous_entry), | 327 synchronous_entry_(NULL), |
| 342 has_been_doomed_(false) { | 328 has_been_doomed_(false) { |
| 343 DCHECK(synchronous_entry); | 329 SetSynchronousEntry(synchronous_entry); |
| 344 } | 330 } |
| 345 | 331 |
| 346 SimpleEntryImpl::~SimpleEntryImpl() { | 332 SimpleEntryImpl::~SimpleEntryImpl() { |
| 347 DCHECK(thread_checker_.CalledOnValidThread()); | 333 DCHECK(thread_checker_.CalledOnValidThread()); |
| 348 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; | 334 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; |
| 349 } | 335 } |
| 350 | 336 |
| 351 SimpleSynchronousEntry* SimpleEntryImpl::ReleaseSynchronousEntry() { | 337 SimpleSynchronousEntry* SimpleEntryImpl::ReleaseSynchronousEntry() { |
| 352 DCHECK(synchronous_entry_); | 338 DCHECK(synchronous_entry_); |
| 353 SimpleSynchronousEntry* retval = synchronous_entry_; | 339 SimpleSynchronousEntry* retval = synchronous_entry_; |
| 354 synchronous_entry_ = NULL; | 340 synchronous_entry_ = NULL; |
| 355 return retval; | 341 return retval; |
| 356 } | 342 } |
| 357 | 343 |
| 358 void SimpleEntryImpl::SetSynchronousEntry( | 344 void SimpleEntryImpl::SetSynchronousEntry( |
| 359 SimpleSynchronousEntry* synchronous_entry) { | 345 SimpleSynchronousEntry* synchronous_entry) { |
| 360 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; | 346 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; |
| 361 synchronous_entry_ = synchronous_entry; | 347 synchronous_entry_ = synchronous_entry; |
| 348 last_used_ = synchronous_entry_->last_used(); | |
| 349 last_modified_ = synchronous_entry_->last_modified(); | |
| 350 for (int i = 0; i < kSimpleEntryFileCount; ++i) | |
| 351 data_size_[i] = synchronous_entry_->data_size(i); | |
| 362 } | 352 } |
| 363 | 353 |
| 364 } // namespace disk_cache | 354 } // namespace disk_cache |
| OLD | NEW |