| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/blockfile/in_flight_backend_io.h" | 5 #include "net/disk_cache/blockfile/in_flight_backend_io.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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 operation_ = OP_DOOM_SINCE; | 115 operation_ = OP_DOOM_SINCE; |
| 116 initial_time_ = initial_time; | 116 initial_time_ = initial_time; |
| 117 } | 117 } |
| 118 | 118 |
| 119 void BackendIO::OpenNextEntry(void** iter, Entry** next_entry) { | 119 void BackendIO::OpenNextEntry(void** iter, Entry** next_entry) { |
| 120 operation_ = OP_OPEN_NEXT; | 120 operation_ = OP_OPEN_NEXT; |
| 121 iter_ptr_ = iter; | 121 iter_ptr_ = iter; |
| 122 entry_ptr_ = next_entry; | 122 entry_ptr_ = next_entry; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void BackendIO::OpenPrevEntry(void** iter, Entry** prev_entry) { | |
| 126 operation_ = OP_OPEN_PREV; | |
| 127 iter_ptr_ = iter; | |
| 128 entry_ptr_ = prev_entry; | |
| 129 } | |
| 130 | |
| 131 void BackendIO::EndEnumeration(void* iterator) { | 125 void BackendIO::EndEnumeration(void* iterator) { |
| 132 operation_ = OP_END_ENUMERATION; | 126 operation_ = OP_END_ENUMERATION; |
| 133 iter_ = iterator; | 127 iter_ = iterator; |
| 134 } | 128 } |
| 135 | 129 |
| 136 void BackendIO::OnExternalCacheHit(const std::string& key) { | 130 void BackendIO::OnExternalCacheHit(const std::string& key) { |
| 137 operation_ = OP_ON_EXTERNAL_CACHE_HIT; | 131 operation_ = OP_ON_EXTERNAL_CACHE_HIT; |
| 138 key_ = key; | 132 key_ = key; |
| 139 } | 133 } |
| 140 | 134 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 205 } |
| 212 | 206 |
| 213 void BackendIO::ReadyForSparseIO(EntryImpl* entry) { | 207 void BackendIO::ReadyForSparseIO(EntryImpl* entry) { |
| 214 operation_ = OP_IS_READY; | 208 operation_ = OP_IS_READY; |
| 215 entry_ = entry; | 209 entry_ = entry; |
| 216 } | 210 } |
| 217 | 211 |
| 218 BackendIO::~BackendIO() {} | 212 BackendIO::~BackendIO() {} |
| 219 | 213 |
| 220 bool BackendIO::ReturnsEntry() { | 214 bool BackendIO::ReturnsEntry() { |
| 221 return (operation_ == OP_OPEN || operation_ == OP_CREATE || | 215 return operation_ == OP_OPEN || operation_ == OP_CREATE || |
| 222 operation_ == OP_OPEN_NEXT || operation_ == OP_OPEN_PREV); | 216 operation_ == OP_OPEN_NEXT; |
| 223 } | 217 } |
| 224 | 218 |
| 225 base::TimeDelta BackendIO::ElapsedTime() const { | 219 base::TimeDelta BackendIO::ElapsedTime() const { |
| 226 return base::TimeTicks::Now() - start_time_; | 220 return base::TimeTicks::Now() - start_time_; |
| 227 } | 221 } |
| 228 | 222 |
| 229 // Runs on the background thread. | 223 // Runs on the background thread. |
| 230 void BackendIO::ExecuteBackendOperation() { | 224 void BackendIO::ExecuteBackendOperation() { |
| 231 switch (operation_) { | 225 switch (operation_) { |
| 232 case OP_INIT: | 226 case OP_INIT: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 246 break; | 240 break; |
| 247 case OP_DOOM_BETWEEN: | 241 case OP_DOOM_BETWEEN: |
| 248 result_ = backend_->SyncDoomEntriesBetween(initial_time_, end_time_); | 242 result_ = backend_->SyncDoomEntriesBetween(initial_time_, end_time_); |
| 249 break; | 243 break; |
| 250 case OP_DOOM_SINCE: | 244 case OP_DOOM_SINCE: |
| 251 result_ = backend_->SyncDoomEntriesSince(initial_time_); | 245 result_ = backend_->SyncDoomEntriesSince(initial_time_); |
| 252 break; | 246 break; |
| 253 case OP_OPEN_NEXT: | 247 case OP_OPEN_NEXT: |
| 254 result_ = backend_->SyncOpenNextEntry(iter_ptr_, entry_ptr_); | 248 result_ = backend_->SyncOpenNextEntry(iter_ptr_, entry_ptr_); |
| 255 break; | 249 break; |
| 256 case OP_OPEN_PREV: | |
| 257 result_ = backend_->SyncOpenPrevEntry(iter_ptr_, entry_ptr_); | |
| 258 break; | |
| 259 case OP_END_ENUMERATION: | 250 case OP_END_ENUMERATION: |
| 260 backend_->SyncEndEnumeration(iter_); | 251 backend_->SyncEndEnumeration(iter_); |
| 261 result_ = net::OK; | 252 result_ = net::OK; |
| 262 break; | 253 break; |
| 263 case OP_ON_EXTERNAL_CACHE_HIT: | 254 case OP_ON_EXTERNAL_CACHE_HIT: |
| 264 backend_->SyncOnExternalCacheHit(key_); | 255 backend_->SyncOnExternalCacheHit(key_); |
| 265 result_ = net::OK; | 256 result_ = net::OK; |
| 266 break; | 257 break; |
| 267 case OP_CLOSE_ENTRY: | 258 case OP_CLOSE_ENTRY: |
| 268 entry_->Release(); | 259 entry_->Release(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 PostOperation(operation.get()); | 382 PostOperation(operation.get()); |
| 392 } | 383 } |
| 393 | 384 |
| 394 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, | 385 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, |
| 395 const net::CompletionCallback& callback) { | 386 const net::CompletionCallback& callback) { |
| 396 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 387 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 397 operation->OpenNextEntry(iter, next_entry); | 388 operation->OpenNextEntry(iter, next_entry); |
| 398 PostOperation(operation.get()); | 389 PostOperation(operation.get()); |
| 399 } | 390 } |
| 400 | 391 |
| 401 void InFlightBackendIO::OpenPrevEntry(void** iter, Entry** prev_entry, | |
| 402 const net::CompletionCallback& callback) { | |
| 403 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | |
| 404 operation->OpenPrevEntry(iter, prev_entry); | |
| 405 PostOperation(operation.get()); | |
| 406 } | |
| 407 | |
| 408 void InFlightBackendIO::EndEnumeration(void* iterator) { | 392 void InFlightBackendIO::EndEnumeration(void* iterator) { |
| 409 scoped_refptr<BackendIO> operation( | 393 scoped_refptr<BackendIO> operation( |
| 410 new BackendIO(this, backend_, net::CompletionCallback())); | 394 new BackendIO(this, backend_, net::CompletionCallback())); |
| 411 operation->EndEnumeration(iterator); | 395 operation->EndEnumeration(iterator); |
| 412 PostOperation(operation.get()); | 396 PostOperation(operation.get()); |
| 413 } | 397 } |
| 414 | 398 |
| 415 void InFlightBackendIO::OnExternalCacheHit(const std::string& key) { | 399 void InFlightBackendIO::OnExternalCacheHit(const std::string& key) { |
| 416 scoped_refptr<BackendIO> operation( | 400 scoped_refptr<BackendIO> operation( |
| 417 new BackendIO(this, backend_, net::CompletionCallback())); | 401 new BackendIO(this, backend_, net::CompletionCallback())); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 background_thread_->PostTask( | 502 background_thread_->PostTask( |
| 519 FROM_HERE, base::Bind(&BackendIO::ExecuteOperation, operation)); | 503 FROM_HERE, base::Bind(&BackendIO::ExecuteOperation, operation)); |
| 520 OnOperationPosted(operation); | 504 OnOperationPosted(operation); |
| 521 } | 505 } |
| 522 | 506 |
| 523 base::WeakPtr<InFlightBackendIO> InFlightBackendIO::GetWeakPtr() { | 507 base::WeakPtr<InFlightBackendIO> InFlightBackendIO::GetWeakPtr() { |
| 524 return ptr_factory_.GetWeakPtr(); | 508 return ptr_factory_.GetWeakPtr(); |
| 525 } | 509 } |
| 526 | 510 |
| 527 } // namespace | 511 } // namespace |
| OLD | NEW |