Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: net/disk_cache/in_flight_backend_io.cc

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/flash/log_store_entry_unittest.cc ('k') | net/disk_cache/in_flight_io.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/in_flight_backend_io.h" 5 #include "net/disk_cache/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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 result_ = net::ERR_UNEXPECTED; 280 result_ = net::ERR_UNEXPECTED;
281 } 281 }
282 DCHECK_NE(net::ERR_IO_PENDING, result_); 282 DCHECK_NE(net::ERR_IO_PENDING, result_);
283 NotifyController(); 283 NotifyController();
284 } 284 }
285 285
286 // Runs on the background thread. 286 // Runs on the background thread.
287 void BackendIO::ExecuteEntryOperation() { 287 void BackendIO::ExecuteEntryOperation() {
288 switch (operation_) { 288 switch (operation_) {
289 case OP_READ: 289 case OP_READ:
290 result_ = entry_->ReadDataImpl( 290 result_ =
291 index_, offset_, buf_, buf_len_, 291 entry_->ReadDataImpl(index_,
292 base::Bind(&BackendIO::OnIOComplete, this)); 292 offset_,
293 buf_.get(),
294 buf_len_,
295 base::Bind(&BackendIO::OnIOComplete, this));
293 break; 296 break;
294 case OP_WRITE: 297 case OP_WRITE:
295 result_ = entry_->WriteDataImpl( 298 result_ =
296 index_, offset_, buf_, buf_len_, 299 entry_->WriteDataImpl(index_,
297 base::Bind(&BackendIO::OnIOComplete, this), 300 offset_,
298 truncate_); 301 buf_.get(),
302 buf_len_,
303 base::Bind(&BackendIO::OnIOComplete, this),
304 truncate_);
299 break; 305 break;
300 case OP_READ_SPARSE: 306 case OP_READ_SPARSE:
301 result_ = entry_->ReadSparseDataImpl( 307 result_ = entry_->ReadSparseDataImpl(
302 offset64_, buf_, buf_len_, 308 offset64_,
309 buf_.get(),
310 buf_len_,
303 base::Bind(&BackendIO::OnIOComplete, this)); 311 base::Bind(&BackendIO::OnIOComplete, this));
304 break; 312 break;
305 case OP_WRITE_SPARSE: 313 case OP_WRITE_SPARSE:
306 result_ = entry_->WriteSparseDataImpl( 314 result_ = entry_->WriteSparseDataImpl(
307 offset64_, buf_, buf_len_, 315 offset64_,
316 buf_.get(),
317 buf_len_,
308 base::Bind(&BackendIO::OnIOComplete, this)); 318 base::Bind(&BackendIO::OnIOComplete, this));
309 break; 319 break;
310 case OP_GET_RANGE: 320 case OP_GET_RANGE:
311 result_ = entry_->GetAvailableRangeImpl(offset64_, buf_len_, start_); 321 result_ = entry_->GetAvailableRangeImpl(offset64_, buf_len_, start_);
312 break; 322 break;
313 case OP_CANCEL_IO: 323 case OP_CANCEL_IO:
314 entry_->CancelSparseIOImpl(); 324 entry_->CancelSparseIOImpl();
315 result_ = net::OK; 325 result_ = net::OK;
316 break; 326 break;
317 case OP_IS_READY: 327 case OP_IS_READY:
(...skipping 15 matching lines...) Expand all
333 background_thread_(background_thread), 343 background_thread_(background_thread),
334 ptr_factory_(this) { 344 ptr_factory_(this) {
335 } 345 }
336 346
337 InFlightBackendIO::~InFlightBackendIO() { 347 InFlightBackendIO::~InFlightBackendIO() {
338 } 348 }
339 349
340 void InFlightBackendIO::Init(const net::CompletionCallback& callback) { 350 void InFlightBackendIO::Init(const net::CompletionCallback& callback) {
341 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 351 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
342 operation->Init(); 352 operation->Init();
343 PostOperation(operation); 353 PostOperation(operation.get());
344 } 354 }
345 355
346 void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, 356 void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry,
347 const net::CompletionCallback& callback) { 357 const net::CompletionCallback& callback) {
348 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 358 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
349 operation->OpenEntry(key, entry); 359 operation->OpenEntry(key, entry);
350 PostOperation(operation); 360 PostOperation(operation.get());
351 } 361 }
352 362
353 void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, 363 void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry,
354 const net::CompletionCallback& callback) { 364 const net::CompletionCallback& callback) {
355 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 365 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
356 operation->CreateEntry(key, entry); 366 operation->CreateEntry(key, entry);
357 PostOperation(operation); 367 PostOperation(operation.get());
358 } 368 }
359 369
360 void InFlightBackendIO::DoomEntry(const std::string& key, 370 void InFlightBackendIO::DoomEntry(const std::string& key,
361 const net::CompletionCallback& callback) { 371 const net::CompletionCallback& callback) {
362 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 372 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
363 operation->DoomEntry(key); 373 operation->DoomEntry(key);
364 PostOperation(operation); 374 PostOperation(operation.get());
365 } 375 }
366 376
367 void InFlightBackendIO::DoomAllEntries( 377 void InFlightBackendIO::DoomAllEntries(
368 const net::CompletionCallback& callback) { 378 const net::CompletionCallback& callback) {
369 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 379 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
370 operation->DoomAllEntries(); 380 operation->DoomAllEntries();
371 PostOperation(operation); 381 PostOperation(operation.get());
372 } 382 }
373 383
374 void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, 384 void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time,
375 const base::Time end_time, 385 const base::Time end_time,
376 const net::CompletionCallback& callback) { 386 const net::CompletionCallback& callback) {
377 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 387 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
378 operation->DoomEntriesBetween(initial_time, end_time); 388 operation->DoomEntriesBetween(initial_time, end_time);
379 PostOperation(operation); 389 PostOperation(operation.get());
380 } 390 }
381 391
382 void InFlightBackendIO::DoomEntriesSince( 392 void InFlightBackendIO::DoomEntriesSince(
383 const base::Time initial_time, const net::CompletionCallback& callback) { 393 const base::Time initial_time, const net::CompletionCallback& callback) {
384 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 394 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
385 operation->DoomEntriesSince(initial_time); 395 operation->DoomEntriesSince(initial_time);
386 PostOperation(operation); 396 PostOperation(operation.get());
387 } 397 }
388 398
389 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, 399 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry,
390 const net::CompletionCallback& callback) { 400 const net::CompletionCallback& callback) {
391 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 401 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
392 operation->OpenNextEntry(iter, next_entry); 402 operation->OpenNextEntry(iter, next_entry);
393 PostOperation(operation); 403 PostOperation(operation.get());
394 } 404 }
395 405
396 void InFlightBackendIO::OpenPrevEntry(void** iter, Entry** prev_entry, 406 void InFlightBackendIO::OpenPrevEntry(void** iter, Entry** prev_entry,
397 const net::CompletionCallback& callback) { 407 const net::CompletionCallback& callback) {
398 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 408 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
399 operation->OpenPrevEntry(iter, prev_entry); 409 operation->OpenPrevEntry(iter, prev_entry);
400 PostOperation(operation); 410 PostOperation(operation.get());
401 } 411 }
402 412
403 void InFlightBackendIO::EndEnumeration(void* iterator) { 413 void InFlightBackendIO::EndEnumeration(void* iterator) {
404 scoped_refptr<BackendIO> operation( 414 scoped_refptr<BackendIO> operation(
405 new BackendIO(this, backend_, net::CompletionCallback())); 415 new BackendIO(this, backend_, net::CompletionCallback()));
406 operation->EndEnumeration(iterator); 416 operation->EndEnumeration(iterator);
407 PostOperation(operation); 417 PostOperation(operation.get());
408 } 418 }
409 419
410 void InFlightBackendIO::OnExternalCacheHit(const std::string& key) { 420 void InFlightBackendIO::OnExternalCacheHit(const std::string& key) {
411 scoped_refptr<BackendIO> operation( 421 scoped_refptr<BackendIO> operation(
412 new BackendIO(this, backend_, net::CompletionCallback())); 422 new BackendIO(this, backend_, net::CompletionCallback()));
413 operation->OnExternalCacheHit(key); 423 operation->OnExternalCacheHit(key);
414 PostOperation(operation); 424 PostOperation(operation.get());
415 } 425 }
416 426
417 void InFlightBackendIO::CloseEntryImpl(EntryImpl* entry) { 427 void InFlightBackendIO::CloseEntryImpl(EntryImpl* entry) {
418 scoped_refptr<BackendIO> operation( 428 scoped_refptr<BackendIO> operation(
419 new BackendIO(this, backend_, net::CompletionCallback())); 429 new BackendIO(this, backend_, net::CompletionCallback()));
420 operation->CloseEntryImpl(entry); 430 operation->CloseEntryImpl(entry);
421 PostOperation(operation); 431 PostOperation(operation.get());
422 } 432 }
423 433
424 void InFlightBackendIO::DoomEntryImpl(EntryImpl* entry) { 434 void InFlightBackendIO::DoomEntryImpl(EntryImpl* entry) {
425 scoped_refptr<BackendIO> operation( 435 scoped_refptr<BackendIO> operation(
426 new BackendIO(this, backend_, net::CompletionCallback())); 436 new BackendIO(this, backend_, net::CompletionCallback()));
427 operation->DoomEntryImpl(entry); 437 operation->DoomEntryImpl(entry);
428 PostOperation(operation); 438 PostOperation(operation.get());
429 } 439 }
430 440
431 void InFlightBackendIO::FlushQueue(const net::CompletionCallback& callback) { 441 void InFlightBackendIO::FlushQueue(const net::CompletionCallback& callback) {
432 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 442 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
433 operation->FlushQueue(); 443 operation->FlushQueue();
434 PostOperation(operation); 444 PostOperation(operation.get());
435 } 445 }
436 446
437 void InFlightBackendIO::RunTask( 447 void InFlightBackendIO::RunTask(
438 const base::Closure& task, const net::CompletionCallback& callback) { 448 const base::Closure& task, const net::CompletionCallback& callback) {
439 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 449 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
440 operation->RunTask(task); 450 operation->RunTask(task);
441 PostOperation(operation); 451 PostOperation(operation.get());
442 } 452 }
443 453
444 void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, 454 void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset,
445 net::IOBuffer* buf, int buf_len, 455 net::IOBuffer* buf, int buf_len,
446 const net::CompletionCallback& callback) { 456 const net::CompletionCallback& callback) {
447 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 457 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
448 operation->ReadData(entry, index, offset, buf, buf_len); 458 operation->ReadData(entry, index, offset, buf, buf_len);
449 PostOperation(operation); 459 PostOperation(operation.get());
450 } 460 }
451 461
452 void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, 462 void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset,
453 net::IOBuffer* buf, int buf_len, 463 net::IOBuffer* buf, int buf_len,
454 bool truncate, 464 bool truncate,
455 const net::CompletionCallback& callback) { 465 const net::CompletionCallback& callback) {
456 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 466 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
457 operation->WriteData(entry, index, offset, buf, buf_len, truncate); 467 operation->WriteData(entry, index, offset, buf, buf_len, truncate);
458 PostOperation(operation); 468 PostOperation(operation.get());
459 } 469 }
460 470
461 void InFlightBackendIO::ReadSparseData( 471 void InFlightBackendIO::ReadSparseData(
462 EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, 472 EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len,
463 const net::CompletionCallback& callback) { 473 const net::CompletionCallback& callback) {
464 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 474 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
465 operation->ReadSparseData(entry, offset, buf, buf_len); 475 operation->ReadSparseData(entry, offset, buf, buf_len);
466 PostOperation(operation); 476 PostOperation(operation.get());
467 } 477 }
468 478
469 void InFlightBackendIO::WriteSparseData( 479 void InFlightBackendIO::WriteSparseData(
470 EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, 480 EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len,
471 const net::CompletionCallback& callback) { 481 const net::CompletionCallback& callback) {
472 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 482 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
473 operation->WriteSparseData(entry, offset, buf, buf_len); 483 operation->WriteSparseData(entry, offset, buf, buf_len);
474 PostOperation(operation); 484 PostOperation(operation.get());
475 } 485 }
476 486
477 void InFlightBackendIO::GetAvailableRange( 487 void InFlightBackendIO::GetAvailableRange(
478 EntryImpl* entry, int64 offset, int len, int64* start, 488 EntryImpl* entry, int64 offset, int len, int64* start,
479 const net::CompletionCallback& callback) { 489 const net::CompletionCallback& callback) {
480 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 490 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
481 operation->GetAvailableRange(entry, offset, len, start); 491 operation->GetAvailableRange(entry, offset, len, start);
482 PostOperation(operation); 492 PostOperation(operation.get());
483 } 493 }
484 494
485 void InFlightBackendIO::CancelSparseIO(EntryImpl* entry) { 495 void InFlightBackendIO::CancelSparseIO(EntryImpl* entry) {
486 scoped_refptr<BackendIO> operation( 496 scoped_refptr<BackendIO> operation(
487 new BackendIO(this, backend_, net::CompletionCallback())); 497 new BackendIO(this, backend_, net::CompletionCallback()));
488 operation->CancelSparseIO(entry); 498 operation->CancelSparseIO(entry);
489 PostOperation(operation); 499 PostOperation(operation.get());
490 } 500 }
491 501
492 void InFlightBackendIO::ReadyForSparseIO( 502 void InFlightBackendIO::ReadyForSparseIO(
493 EntryImpl* entry, const net::CompletionCallback& callback) { 503 EntryImpl* entry, const net::CompletionCallback& callback) {
494 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); 504 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
495 operation->ReadyForSparseIO(entry); 505 operation->ReadyForSparseIO(entry);
496 PostOperation(operation); 506 PostOperation(operation.get());
497 } 507 }
498 508
499 void InFlightBackendIO::WaitForPendingIO() { 509 void InFlightBackendIO::WaitForPendingIO() {
500 InFlightIO::WaitForPendingIO(); 510 InFlightIO::WaitForPendingIO();
501 } 511 }
502 512
503 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, 513 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation,
504 bool cancel) { 514 bool cancel) {
505 BackendIO* op = static_cast<BackendIO*>(operation); 515 BackendIO* op = static_cast<BackendIO*>(operation);
506 op->OnDone(cancel); 516 op->OnDone(cancel);
507 517
508 if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) 518 if (!op->callback().is_null() && (!cancel || op->IsEntryOperation()))
509 op->callback().Run(op->result()); 519 op->callback().Run(op->result());
510 } 520 }
511 521
512 void InFlightBackendIO::PostOperation(BackendIO* operation) { 522 void InFlightBackendIO::PostOperation(BackendIO* operation) {
513 background_thread_->PostTask(FROM_HERE, 523 background_thread_->PostTask(FROM_HERE,
514 base::Bind(&BackendIO::ExecuteOperation, operation)); 524 base::Bind(&BackendIO::ExecuteOperation, operation));
515 OnOperationPosted(operation); 525 OnOperationPosted(operation);
516 } 526 }
517 527
518 base::WeakPtr<InFlightBackendIO> InFlightBackendIO::GetWeakPtr() { 528 base::WeakPtr<InFlightBackendIO> InFlightBackendIO::GetWeakPtr() {
519 return ptr_factory_.GetWeakPtr(); 529 return ptr_factory_.GetWeakPtr();
520 } 530 }
521 531
522 } // namespace 532 } // namespace
OLDNEW
« no previous file with comments | « net/disk_cache/flash/log_store_entry_unittest.cc ('k') | net/disk_cache/in_flight_io.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698