| 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" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/disk_cache/blockfile/backend_impl.h" | 12 #include "net/disk_cache/blockfile/backend_impl.h" |
| 13 #include "net/disk_cache/blockfile/entry_impl.h" | 13 #include "net/disk_cache/blockfile/entry_impl.h" |
| 14 #include "net/disk_cache/blockfile/histogram_macros.h" | 14 #include "net/disk_cache/blockfile/histogram_macros.h" |
| 15 | 15 |
| 16 // Provide a BackendImpl object to macros from histogram_macros.h. | 16 // Provide a BackendImpl object to macros from histogram_macros.h. |
| 17 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ | 17 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ |
| 18 | 18 |
| 19 namespace disk_cache { | 19 namespace disk_cache { |
| 20 | 20 |
| 21 BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, | 21 BackendIO::BackendIO(InFlightIO* controller, |
| 22 BackendImpl* backend, |
| 22 const net::CompletionCallback& callback) | 23 const net::CompletionCallback& callback) |
| 23 : BackgroundIO(controller), | 24 : BackgroundIO(controller), |
| 24 backend_(backend), | 25 backend_(backend), |
| 25 callback_(callback), | 26 callback_(callback), |
| 26 operation_(OP_NONE), | 27 operation_(OP_NONE), |
| 27 entry_ptr_(NULL), | 28 entry_ptr_(NULL), |
| 28 iter_ptr_(NULL), | 29 iter_ptr_(NULL), |
| 29 iter_(NULL), | 30 iter_(NULL), |
| 30 entry_(NULL), | 31 entry_(NULL), |
| 31 index_(0), | 32 index_(0), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 150 |
| 150 void BackendIO::FlushQueue() { | 151 void BackendIO::FlushQueue() { |
| 151 operation_ = OP_FLUSH_QUEUE; | 152 operation_ = OP_FLUSH_QUEUE; |
| 152 } | 153 } |
| 153 | 154 |
| 154 void BackendIO::RunTask(const base::Closure& task) { | 155 void BackendIO::RunTask(const base::Closure& task) { |
| 155 operation_ = OP_RUN_TASK; | 156 operation_ = OP_RUN_TASK; |
| 156 task_ = task; | 157 task_ = task; |
| 157 } | 158 } |
| 158 | 159 |
| 159 void BackendIO::ReadData(EntryImpl* entry, int index, int offset, | 160 void BackendIO::ReadData(EntryImpl* entry, |
| 160 net::IOBuffer* buf, int buf_len) { | 161 int index, |
| 162 int offset, |
| 163 net::IOBuffer* buf, |
| 164 int buf_len) { |
| 161 operation_ = OP_READ; | 165 operation_ = OP_READ; |
| 162 entry_ = entry; | 166 entry_ = entry; |
| 163 index_ = index; | 167 index_ = index; |
| 164 offset_ = offset; | 168 offset_ = offset; |
| 165 buf_ = buf; | 169 buf_ = buf; |
| 166 buf_len_ = buf_len; | 170 buf_len_ = buf_len; |
| 167 } | 171 } |
| 168 | 172 |
| 169 void BackendIO::WriteData(EntryImpl* entry, int index, int offset, | 173 void BackendIO::WriteData(EntryImpl* entry, |
| 170 net::IOBuffer* buf, int buf_len, bool truncate) { | 174 int index, |
| 175 int offset, |
| 176 net::IOBuffer* buf, |
| 177 int buf_len, |
| 178 bool truncate) { |
| 171 operation_ = OP_WRITE; | 179 operation_ = OP_WRITE; |
| 172 entry_ = entry; | 180 entry_ = entry; |
| 173 index_ = index; | 181 index_ = index; |
| 174 offset_ = offset; | 182 offset_ = offset; |
| 175 buf_ = buf; | 183 buf_ = buf; |
| 176 buf_len_ = buf_len; | 184 buf_len_ = buf_len; |
| 177 truncate_ = truncate; | 185 truncate_ = truncate; |
| 178 } | 186 } |
| 179 | 187 |
| 180 void BackendIO::ReadSparseData(EntryImpl* entry, int64 offset, | 188 void BackendIO::ReadSparseData(EntryImpl* entry, |
| 181 net::IOBuffer* buf, int buf_len) { | 189 int64 offset, |
| 190 net::IOBuffer* buf, |
| 191 int buf_len) { |
| 182 operation_ = OP_READ_SPARSE; | 192 operation_ = OP_READ_SPARSE; |
| 183 entry_ = entry; | 193 entry_ = entry; |
| 184 offset64_ = offset; | 194 offset64_ = offset; |
| 185 buf_ = buf; | 195 buf_ = buf; |
| 186 buf_len_ = buf_len; | 196 buf_len_ = buf_len; |
| 187 } | 197 } |
| 188 | 198 |
| 189 void BackendIO::WriteSparseData(EntryImpl* entry, int64 offset, | 199 void BackendIO::WriteSparseData(EntryImpl* entry, |
| 190 net::IOBuffer* buf, int buf_len) { | 200 int64 offset, |
| 201 net::IOBuffer* buf, |
| 202 int buf_len) { |
| 191 operation_ = OP_WRITE_SPARSE; | 203 operation_ = OP_WRITE_SPARSE; |
| 192 entry_ = entry; | 204 entry_ = entry; |
| 193 offset64_ = offset; | 205 offset64_ = offset; |
| 194 buf_ = buf; | 206 buf_ = buf; |
| 195 buf_len_ = buf_len; | 207 buf_len_ = buf_len; |
| 196 } | 208 } |
| 197 | 209 |
| 198 void BackendIO::GetAvailableRange(EntryImpl* entry, int64 offset, int len, | 210 void BackendIO::GetAvailableRange(EntryImpl* entry, |
| 211 int64 offset, |
| 212 int len, |
| 199 int64* start) { | 213 int64* start) { |
| 200 operation_ = OP_GET_RANGE; | 214 operation_ = OP_GET_RANGE; |
| 201 entry_ = entry; | 215 entry_ = entry; |
| 202 offset64_ = offset; | 216 offset64_ = offset; |
| 203 buf_len_ = len; | 217 buf_len_ = len; |
| 204 start_ = start; | 218 start_ = start; |
| 205 } | 219 } |
| 206 | 220 |
| 207 void BackendIO::CancelSparseIO(EntryImpl* entry) { | 221 void BackendIO::CancelSparseIO(EntryImpl* entry) { |
| 208 operation_ = OP_CANCEL_IO; | 222 operation_ = OP_CANCEL_IO; |
| 209 entry_ = entry; | 223 entry_ = entry; |
| 210 } | 224 } |
| 211 | 225 |
| 212 void BackendIO::ReadyForSparseIO(EntryImpl* entry) { | 226 void BackendIO::ReadyForSparseIO(EntryImpl* entry) { |
| 213 operation_ = OP_IS_READY; | 227 operation_ = OP_IS_READY; |
| 214 entry_ = entry; | 228 entry_ = entry; |
| 215 } | 229 } |
| 216 | 230 |
| 217 BackendIO::~BackendIO() {} | 231 BackendIO::~BackendIO() { |
| 232 } |
| 218 | 233 |
| 219 bool BackendIO::ReturnsEntry() { | 234 bool BackendIO::ReturnsEntry() { |
| 220 return (operation_ == OP_OPEN || operation_ == OP_CREATE || | 235 return (operation_ == OP_OPEN || operation_ == OP_CREATE || |
| 221 operation_ == OP_OPEN_NEXT || operation_ == OP_OPEN_PREV); | 236 operation_ == OP_OPEN_NEXT || operation_ == OP_OPEN_PREV); |
| 222 } | 237 } |
| 223 | 238 |
| 224 base::TimeDelta BackendIO::ElapsedTime() const { | 239 base::TimeDelta BackendIO::ElapsedTime() const { |
| 225 return base::TimeTicks::Now() - start_time_; | 240 return base::TimeTicks::Now() - start_time_; |
| 226 } | 241 } |
| 227 | 242 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 299 } |
| 285 DCHECK_NE(net::ERR_IO_PENDING, result_); | 300 DCHECK_NE(net::ERR_IO_PENDING, result_); |
| 286 NotifyController(); | 301 NotifyController(); |
| 287 } | 302 } |
| 288 | 303 |
| 289 // Runs on the background thread. | 304 // Runs on the background thread. |
| 290 void BackendIO::ExecuteEntryOperation() { | 305 void BackendIO::ExecuteEntryOperation() { |
| 291 switch (operation_) { | 306 switch (operation_) { |
| 292 case OP_READ: | 307 case OP_READ: |
| 293 result_ = | 308 result_ = |
| 294 entry_->ReadDataImpl(index_, offset_, buf_.get(), buf_len_, | 309 entry_->ReadDataImpl(index_, |
| 310 offset_, |
| 311 buf_.get(), |
| 312 buf_len_, |
| 295 base::Bind(&BackendIO::OnIOComplete, this)); | 313 base::Bind(&BackendIO::OnIOComplete, this)); |
| 296 break; | 314 break; |
| 297 case OP_WRITE: | 315 case OP_WRITE: |
| 298 result_ = | 316 result_ = |
| 299 entry_->WriteDataImpl(index_, offset_, buf_.get(), buf_len_, | 317 entry_->WriteDataImpl(index_, |
| 318 offset_, |
| 319 buf_.get(), |
| 320 buf_len_, |
| 300 base::Bind(&BackendIO::OnIOComplete, this), | 321 base::Bind(&BackendIO::OnIOComplete, this), |
| 301 truncate_); | 322 truncate_); |
| 302 break; | 323 break; |
| 303 case OP_READ_SPARSE: | 324 case OP_READ_SPARSE: |
| 304 result_ = entry_->ReadSparseDataImpl( | 325 result_ = entry_->ReadSparseDataImpl( |
| 305 offset64_, buf_.get(), buf_len_, | 326 offset64_, |
| 306 base::Bind(&BackendIO::OnIOComplete, this)); | 327 buf_.get(), |
| 328 buf_len_, |
| 329 base::Bind(&BackendIO::OnIOComplete, this)); |
| 307 break; | 330 break; |
| 308 case OP_WRITE_SPARSE: | 331 case OP_WRITE_SPARSE: |
| 309 result_ = entry_->WriteSparseDataImpl( | 332 result_ = entry_->WriteSparseDataImpl( |
| 310 offset64_, buf_.get(), buf_len_, | 333 offset64_, |
| 311 base::Bind(&BackendIO::OnIOComplete, this)); | 334 buf_.get(), |
| 335 buf_len_, |
| 336 base::Bind(&BackendIO::OnIOComplete, this)); |
| 312 break; | 337 break; |
| 313 case OP_GET_RANGE: | 338 case OP_GET_RANGE: |
| 314 result_ = entry_->GetAvailableRangeImpl(offset64_, buf_len_, start_); | 339 result_ = entry_->GetAvailableRangeImpl(offset64_, buf_len_, start_); |
| 315 break; | 340 break; |
| 316 case OP_CANCEL_IO: | 341 case OP_CANCEL_IO: |
| 317 entry_->CancelSparseIOImpl(); | 342 entry_->CancelSparseIOImpl(); |
| 318 result_ = net::OK; | 343 result_ = net::OK; |
| 319 break; | 344 break; |
| 320 case OP_IS_READY: | 345 case OP_IS_READY: |
| 321 result_ = entry_->ReadyForSparseIOImpl( | 346 result_ = entry_->ReadyForSparseIOImpl( |
| 322 base::Bind(&BackendIO::OnIOComplete, this)); | 347 base::Bind(&BackendIO::OnIOComplete, this)); |
| 323 break; | 348 break; |
| 324 default: | 349 default: |
| 325 NOTREACHED() << "Invalid Operation"; | 350 NOTREACHED() << "Invalid Operation"; |
| 326 result_ = net::ERR_UNEXPECTED; | 351 result_ = net::ERR_UNEXPECTED; |
| 327 } | 352 } |
| 328 buf_ = NULL; | 353 buf_ = NULL; |
| 329 if (result_ != net::ERR_IO_PENDING) | 354 if (result_ != net::ERR_IO_PENDING) |
| 330 NotifyController(); | 355 NotifyController(); |
| 331 } | 356 } |
| 332 | 357 |
| 333 InFlightBackendIO::InFlightBackendIO(BackendImpl* backend, | 358 InFlightBackendIO::InFlightBackendIO(BackendImpl* backend, |
| 334 base::MessageLoopProxy* background_thread) | 359 base::MessageLoopProxy* background_thread) |
| 335 : backend_(backend), | 360 : backend_(backend), |
| 336 background_thread_(background_thread), | 361 background_thread_(background_thread), |
| 337 ptr_factory_(this) { | 362 ptr_factory_(this) { |
| 338 } | 363 } |
| 339 | 364 |
| 340 InFlightBackendIO::~InFlightBackendIO() { | 365 InFlightBackendIO::~InFlightBackendIO() { |
| 341 } | 366 } |
| 342 | 367 |
| 343 void InFlightBackendIO::Init(const net::CompletionCallback& callback) { | 368 void InFlightBackendIO::Init(const net::CompletionCallback& callback) { |
| 344 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 369 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 345 operation->Init(); | 370 operation->Init(); |
| 346 PostOperation(operation.get()); | 371 PostOperation(operation.get()); |
| 347 } | 372 } |
| 348 | 373 |
| 349 void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, | 374 void InFlightBackendIO::OpenEntry(const std::string& key, |
| 375 Entry** entry, |
| 350 const net::CompletionCallback& callback) { | 376 const net::CompletionCallback& callback) { |
| 351 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 377 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 352 operation->OpenEntry(key, entry); | 378 operation->OpenEntry(key, entry); |
| 353 PostOperation(operation.get()); | 379 PostOperation(operation.get()); |
| 354 } | 380 } |
| 355 | 381 |
| 356 void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, | 382 void InFlightBackendIO::CreateEntry(const std::string& key, |
| 383 Entry** entry, |
| 357 const net::CompletionCallback& callback) { | 384 const net::CompletionCallback& callback) { |
| 358 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 385 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 359 operation->CreateEntry(key, entry); | 386 operation->CreateEntry(key, entry); |
| 360 PostOperation(operation.get()); | 387 PostOperation(operation.get()); |
| 361 } | 388 } |
| 362 | 389 |
| 363 void InFlightBackendIO::DoomEntry(const std::string& key, | 390 void InFlightBackendIO::DoomEntry(const std::string& key, |
| 364 const net::CompletionCallback& callback) { | 391 const net::CompletionCallback& callback) { |
| 365 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 392 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 366 operation->DoomEntry(key); | 393 operation->DoomEntry(key); |
| 367 PostOperation(operation.get()); | 394 PostOperation(operation.get()); |
| 368 } | 395 } |
| 369 | 396 |
| 370 void InFlightBackendIO::DoomAllEntries( | 397 void InFlightBackendIO::DoomAllEntries( |
| 371 const net::CompletionCallback& callback) { | 398 const net::CompletionCallback& callback) { |
| 372 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 399 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 373 operation->DoomAllEntries(); | 400 operation->DoomAllEntries(); |
| 374 PostOperation(operation.get()); | 401 PostOperation(operation.get()); |
| 375 } | 402 } |
| 376 | 403 |
| 377 void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, | 404 void InFlightBackendIO::DoomEntriesBetween( |
| 378 const base::Time end_time, | 405 const base::Time initial_time, |
| 379 const net::CompletionCallback& callback) { | 406 const base::Time end_time, |
| 407 const net::CompletionCallback& callback) { |
| 380 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 408 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 381 operation->DoomEntriesBetween(initial_time, end_time); | 409 operation->DoomEntriesBetween(initial_time, end_time); |
| 382 PostOperation(operation.get()); | 410 PostOperation(operation.get()); |
| 383 } | 411 } |
| 384 | 412 |
| 385 void InFlightBackendIO::DoomEntriesSince( | 413 void InFlightBackendIO::DoomEntriesSince( |
| 386 const base::Time initial_time, const net::CompletionCallback& callback) { | 414 const base::Time initial_time, |
| 415 const net::CompletionCallback& callback) { |
| 387 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 416 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 388 operation->DoomEntriesSince(initial_time); | 417 operation->DoomEntriesSince(initial_time); |
| 389 PostOperation(operation.get()); | 418 PostOperation(operation.get()); |
| 390 } | 419 } |
| 391 | 420 |
| 392 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, | 421 void InFlightBackendIO::OpenNextEntry(void** iter, |
| 422 Entry** next_entry, |
| 393 const net::CompletionCallback& callback) { | 423 const net::CompletionCallback& callback) { |
| 394 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 424 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 395 operation->OpenNextEntry(iter, next_entry); | 425 operation->OpenNextEntry(iter, next_entry); |
| 396 PostOperation(operation.get()); | 426 PostOperation(operation.get()); |
| 397 } | 427 } |
| 398 | 428 |
| 399 void InFlightBackendIO::OpenPrevEntry(void** iter, Entry** prev_entry, | 429 void InFlightBackendIO::OpenPrevEntry(void** iter, |
| 430 Entry** prev_entry, |
| 400 const net::CompletionCallback& callback) { | 431 const net::CompletionCallback& callback) { |
| 401 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 432 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 402 operation->OpenPrevEntry(iter, prev_entry); | 433 operation->OpenPrevEntry(iter, prev_entry); |
| 403 PostOperation(operation.get()); | 434 PostOperation(operation.get()); |
| 404 } | 435 } |
| 405 | 436 |
| 406 void InFlightBackendIO::EndEnumeration(void* iterator) { | 437 void InFlightBackendIO::EndEnumeration(void* iterator) { |
| 407 scoped_refptr<BackendIO> operation( | 438 scoped_refptr<BackendIO> operation( |
| 408 new BackendIO(this, backend_, net::CompletionCallback())); | 439 new BackendIO(this, backend_, net::CompletionCallback())); |
| 409 operation->EndEnumeration(iterator); | 440 operation->EndEnumeration(iterator); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 430 operation->DoomEntryImpl(entry); | 461 operation->DoomEntryImpl(entry); |
| 431 PostOperation(operation.get()); | 462 PostOperation(operation.get()); |
| 432 } | 463 } |
| 433 | 464 |
| 434 void InFlightBackendIO::FlushQueue(const net::CompletionCallback& callback) { | 465 void InFlightBackendIO::FlushQueue(const net::CompletionCallback& callback) { |
| 435 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 466 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 436 operation->FlushQueue(); | 467 operation->FlushQueue(); |
| 437 PostOperation(operation.get()); | 468 PostOperation(operation.get()); |
| 438 } | 469 } |
| 439 | 470 |
| 440 void InFlightBackendIO::RunTask( | 471 void InFlightBackendIO::RunTask(const base::Closure& task, |
| 441 const base::Closure& task, const net::CompletionCallback& callback) { | 472 const net::CompletionCallback& callback) { |
| 442 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 473 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 443 operation->RunTask(task); | 474 operation->RunTask(task); |
| 444 PostOperation(operation.get()); | 475 PostOperation(operation.get()); |
| 445 } | 476 } |
| 446 | 477 |
| 447 void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, | 478 void InFlightBackendIO::ReadData(EntryImpl* entry, |
| 448 net::IOBuffer* buf, int buf_len, | 479 int index, |
| 480 int offset, |
| 481 net::IOBuffer* buf, |
| 482 int buf_len, |
| 449 const net::CompletionCallback& callback) { | 483 const net::CompletionCallback& callback) { |
| 450 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 484 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 451 operation->ReadData(entry, index, offset, buf, buf_len); | 485 operation->ReadData(entry, index, offset, buf, buf_len); |
| 452 PostOperation(operation.get()); | 486 PostOperation(operation.get()); |
| 453 } | 487 } |
| 454 | 488 |
| 455 void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, | 489 void InFlightBackendIO::WriteData(EntryImpl* entry, |
| 456 net::IOBuffer* buf, int buf_len, | 490 int index, |
| 491 int offset, |
| 492 net::IOBuffer* buf, |
| 493 int buf_len, |
| 457 bool truncate, | 494 bool truncate, |
| 458 const net::CompletionCallback& callback) { | 495 const net::CompletionCallback& callback) { |
| 459 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 496 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 460 operation->WriteData(entry, index, offset, buf, buf_len, truncate); | 497 operation->WriteData(entry, index, offset, buf, buf_len, truncate); |
| 461 PostOperation(operation.get()); | 498 PostOperation(operation.get()); |
| 462 } | 499 } |
| 463 | 500 |
| 464 void InFlightBackendIO::ReadSparseData( | 501 void InFlightBackendIO::ReadSparseData( |
| 465 EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, | 502 EntryImpl* entry, |
| 503 int64 offset, |
| 504 net::IOBuffer* buf, |
| 505 int buf_len, |
| 466 const net::CompletionCallback& callback) { | 506 const net::CompletionCallback& callback) { |
| 467 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 507 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 468 operation->ReadSparseData(entry, offset, buf, buf_len); | 508 operation->ReadSparseData(entry, offset, buf, buf_len); |
| 469 PostOperation(operation.get()); | 509 PostOperation(operation.get()); |
| 470 } | 510 } |
| 471 | 511 |
| 472 void InFlightBackendIO::WriteSparseData( | 512 void InFlightBackendIO::WriteSparseData( |
| 473 EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, | 513 EntryImpl* entry, |
| 514 int64 offset, |
| 515 net::IOBuffer* buf, |
| 516 int buf_len, |
| 474 const net::CompletionCallback& callback) { | 517 const net::CompletionCallback& callback) { |
| 475 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 518 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 476 operation->WriteSparseData(entry, offset, buf, buf_len); | 519 operation->WriteSparseData(entry, offset, buf, buf_len); |
| 477 PostOperation(operation.get()); | 520 PostOperation(operation.get()); |
| 478 } | 521 } |
| 479 | 522 |
| 480 void InFlightBackendIO::GetAvailableRange( | 523 void InFlightBackendIO::GetAvailableRange( |
| 481 EntryImpl* entry, int64 offset, int len, int64* start, | 524 EntryImpl* entry, |
| 525 int64 offset, |
| 526 int len, |
| 527 int64* start, |
| 482 const net::CompletionCallback& callback) { | 528 const net::CompletionCallback& callback) { |
| 483 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 529 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 484 operation->GetAvailableRange(entry, offset, len, start); | 530 operation->GetAvailableRange(entry, offset, len, start); |
| 485 PostOperation(operation.get()); | 531 PostOperation(operation.get()); |
| 486 } | 532 } |
| 487 | 533 |
| 488 void InFlightBackendIO::CancelSparseIO(EntryImpl* entry) { | 534 void InFlightBackendIO::CancelSparseIO(EntryImpl* entry) { |
| 489 scoped_refptr<BackendIO> operation( | 535 scoped_refptr<BackendIO> operation( |
| 490 new BackendIO(this, backend_, net::CompletionCallback())); | 536 new BackendIO(this, backend_, net::CompletionCallback())); |
| 491 operation->CancelSparseIO(entry); | 537 operation->CancelSparseIO(entry); |
| 492 PostOperation(operation.get()); | 538 PostOperation(operation.get()); |
| 493 } | 539 } |
| 494 | 540 |
| 495 void InFlightBackendIO::ReadyForSparseIO( | 541 void InFlightBackendIO::ReadyForSparseIO( |
| 496 EntryImpl* entry, const net::CompletionCallback& callback) { | 542 EntryImpl* entry, |
| 543 const net::CompletionCallback& callback) { |
| 497 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 544 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 498 operation->ReadyForSparseIO(entry); | 545 operation->ReadyForSparseIO(entry); |
| 499 PostOperation(operation.get()); | 546 PostOperation(operation.get()); |
| 500 } | 547 } |
| 501 | 548 |
| 502 void InFlightBackendIO::WaitForPendingIO() { | 549 void InFlightBackendIO::WaitForPendingIO() { |
| 503 InFlightIO::WaitForPendingIO(); | 550 InFlightIO::WaitForPendingIO(); |
| 504 } | 551 } |
| 505 | 552 |
| 506 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, | 553 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, |
| 507 bool cancel) { | 554 bool cancel) { |
| 508 BackendIO* op = static_cast<BackendIO*>(operation); | 555 BackendIO* op = static_cast<BackendIO*>(operation); |
| 509 op->OnDone(cancel); | 556 op->OnDone(cancel); |
| 510 | 557 |
| 511 if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) | 558 if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) |
| 512 op->callback().Run(op->result()); | 559 op->callback().Run(op->result()); |
| 513 } | 560 } |
| 514 | 561 |
| 515 void InFlightBackendIO::PostOperation(BackendIO* operation) { | 562 void InFlightBackendIO::PostOperation(BackendIO* operation) { |
| 516 background_thread_->PostTask(FROM_HERE, | 563 background_thread_->PostTask( |
| 517 base::Bind(&BackendIO::ExecuteOperation, operation)); | 564 FROM_HERE, base::Bind(&BackendIO::ExecuteOperation, operation)); |
| 518 OnOperationPosted(operation); | 565 OnOperationPosted(operation); |
| 519 } | 566 } |
| 520 | 567 |
| 521 base::WeakPtr<InFlightBackendIO> InFlightBackendIO::GetWeakPtr() { | 568 base::WeakPtr<InFlightBackendIO> InFlightBackendIO::GetWeakPtr() { |
| 522 return ptr_factory_.GetWeakPtr(); | 569 return ptr_factory_.GetWeakPtr(); |
| 523 } | 570 } |
| 524 | 571 |
| 525 } // namespace | 572 } // namespace |
| OLD | NEW |