OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/disk_cache/backend_impl.h" | 11 #include "net/disk_cache/backend_impl.h" |
12 #include "net/disk_cache/entry_impl.h" | 12 #include "net/disk_cache/entry_impl.h" |
13 #include "net/disk_cache/histogram_macros.h" | 13 #include "net/disk_cache/histogram_macros.h" |
14 | 14 |
15 namespace disk_cache { | 15 namespace disk_cache { |
16 | 16 |
17 BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, | 17 BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, |
18 net::OldCompletionCallback* callback) | 18 net::OldCompletionCallback* callback) |
19 : BackgroundIO(controller), | 19 : BackgroundIO(controller), backend_(backend), callback_(callback), |
20 backend_(backend), | |
21 old_callback_(callback), | |
22 operation_(OP_NONE), | 20 operation_(OP_NONE), |
23 ALLOW_THIS_IN_INITIALIZER_LIST( | 21 ALLOW_THIS_IN_INITIALIZER_LIST( |
24 my_callback_(this, &BackendIO::OnIOComplete)) { | 22 my_callback_(this, &BackendIO::OnIOComplete)) { |
25 start_time_ = base::TimeTicks::Now(); | |
26 } | |
27 | |
28 BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, | |
29 const net::CompletionCallback& callback) | |
30 : BackgroundIO(controller), | |
31 backend_(backend), | |
32 old_callback_(NULL), | |
33 callback_(callback), | |
34 operation_(OP_NONE), | |
35 ALLOW_THIS_IN_INITIALIZER_LIST( | |
36 my_callback_(this, &BackendIO::OnIOComplete)) { | |
37 start_time_ = base::TimeTicks::Now(); | 23 start_time_ = base::TimeTicks::Now(); |
38 } | 24 } |
39 | 25 |
40 // Runs on the background thread. | 26 // Runs on the background thread. |
41 void BackendIO::ExecuteOperation() { | 27 void BackendIO::ExecuteOperation() { |
42 if (IsEntryOperation()) | 28 if (IsEntryOperation()) |
43 return ExecuteEntryOperation(); | 29 return ExecuteEntryOperation(); |
44 | 30 |
45 ExecuteBackendOperation(); | 31 ExecuteBackendOperation(); |
46 } | 32 } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 PostOperation(operation); | 306 PostOperation(operation); |
321 } | 307 } |
322 | 308 |
323 void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, | 309 void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, |
324 OldCompletionCallback* callback) { | 310 OldCompletionCallback* callback) { |
325 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 311 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
326 operation->OpenEntry(key, entry); | 312 operation->OpenEntry(key, entry); |
327 PostOperation(operation); | 313 PostOperation(operation); |
328 } | 314 } |
329 | 315 |
330 void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, | |
331 const net::CompletionCallback& callback) { | |
332 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | |
333 operation->OpenEntry(key, entry); | |
334 PostOperation(operation); | |
335 } | |
336 | |
337 void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, | 316 void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, |
338 OldCompletionCallback* callback) { | 317 OldCompletionCallback* callback) { |
339 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 318 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
340 operation->CreateEntry(key, entry); | 319 operation->CreateEntry(key, entry); |
341 PostOperation(operation); | 320 PostOperation(operation); |
342 } | 321 } |
343 | 322 |
344 void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, | |
345 const net::CompletionCallback& callback) { | |
346 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | |
347 operation->CreateEntry(key, entry); | |
348 PostOperation(operation); | |
349 } | |
350 | |
351 void InFlightBackendIO::DoomEntry(const std::string& key, | 323 void InFlightBackendIO::DoomEntry(const std::string& key, |
352 OldCompletionCallback* callback) { | 324 OldCompletionCallback* callback) { |
353 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 325 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
354 operation->DoomEntry(key); | 326 operation->DoomEntry(key); |
355 PostOperation(operation); | 327 PostOperation(operation); |
356 } | 328 } |
357 | 329 |
358 void InFlightBackendIO::DoomAllEntries(OldCompletionCallback* callback) { | 330 void InFlightBackendIO::DoomAllEntries(OldCompletionCallback* callback) { |
359 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 331 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
360 operation->DoomAllEntries(); | 332 operation->DoomAllEntries(); |
361 PostOperation(operation); | 333 PostOperation(operation); |
362 } | 334 } |
363 | 335 |
364 void InFlightBackendIO::DoomAllEntries( | |
365 const net::CompletionCallback& callback) { | |
366 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | |
367 operation->DoomAllEntries(); | |
368 PostOperation(operation); | |
369 } | |
370 | |
371 void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, | 336 void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, |
372 const base::Time end_time, | 337 const base::Time end_time, |
373 OldCompletionCallback* callback) { | 338 OldCompletionCallback* callback) { |
374 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 339 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
375 operation->DoomEntriesBetween(initial_time, end_time); | 340 operation->DoomEntriesBetween(initial_time, end_time); |
376 PostOperation(operation); | 341 PostOperation(operation); |
377 } | 342 } |
378 | 343 |
379 void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, | |
380 const base::Time end_time, | |
381 const net::CompletionCallback& callback) { | |
382 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | |
383 operation->DoomEntriesBetween(initial_time, end_time); | |
384 PostOperation(operation); | |
385 } | |
386 | |
387 void InFlightBackendIO::DoomEntriesSince(const base::Time initial_time, | 344 void InFlightBackendIO::DoomEntriesSince(const base::Time initial_time, |
388 OldCompletionCallback* callback) { | 345 OldCompletionCallback* callback) { |
389 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 346 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
390 operation->DoomEntriesSince(initial_time); | 347 operation->DoomEntriesSince(initial_time); |
391 PostOperation(operation); | 348 PostOperation(operation); |
392 } | 349 } |
393 | 350 |
394 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, | 351 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, |
395 OldCompletionCallback* callback) { | 352 OldCompletionCallback* callback) { |
396 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 353 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
397 operation->OpenNextEntry(iter, next_entry); | 354 operation->OpenNextEntry(iter, next_entry); |
398 PostOperation(operation); | 355 PostOperation(operation); |
399 } | 356 } |
400 | 357 |
401 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, | |
402 const net::CompletionCallback& callback) { | |
403 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | |
404 operation->OpenNextEntry(iter, next_entry); | |
405 PostOperation(operation); | |
406 } | |
407 | |
408 void InFlightBackendIO::OpenPrevEntry(void** iter, Entry** prev_entry, | 358 void InFlightBackendIO::OpenPrevEntry(void** iter, Entry** prev_entry, |
409 OldCompletionCallback* callback) { | 359 OldCompletionCallback* callback) { |
410 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 360 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
411 operation->OpenPrevEntry(iter, prev_entry); | 361 operation->OpenPrevEntry(iter, prev_entry); |
412 PostOperation(operation); | 362 PostOperation(operation); |
413 } | 363 } |
414 | 364 |
415 void InFlightBackendIO::EndEnumeration(void* iterator) { | 365 void InFlightBackendIO::EndEnumeration(void* iterator) { |
416 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, NULL)); | 366 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, NULL)); |
417 operation->EndEnumeration(iterator); | 367 operation->EndEnumeration(iterator); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 399 } |
450 | 400 |
451 void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, | 401 void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, |
452 net::IOBuffer* buf, int buf_len, | 402 net::IOBuffer* buf, int buf_len, |
453 OldCompletionCallback* callback) { | 403 OldCompletionCallback* callback) { |
454 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 404 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
455 operation->ReadData(entry, index, offset, buf, buf_len); | 405 operation->ReadData(entry, index, offset, buf, buf_len); |
456 PostOperation(operation); | 406 PostOperation(operation); |
457 } | 407 } |
458 | 408 |
459 void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, | |
460 net::IOBuffer* buf, int buf_len, | |
461 const net::CompletionCallback& callback) { | |
462 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | |
463 operation->ReadData(entry, index, offset, buf, buf_len); | |
464 PostOperation(operation); | |
465 } | |
466 | |
467 void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, | 409 void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, |
468 net::IOBuffer* buf, int buf_len, | 410 net::IOBuffer* buf, int buf_len, |
469 bool truncate, | 411 bool truncate, |
470 OldCompletionCallback* callback) { | 412 OldCompletionCallback* callback) { |
471 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 413 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
472 operation->WriteData(entry, index, offset, buf, buf_len, truncate); | 414 operation->WriteData(entry, index, offset, buf, buf_len, truncate); |
473 PostOperation(operation); | 415 PostOperation(operation); |
474 } | 416 } |
475 | 417 |
476 void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, | |
477 net::IOBuffer* buf, int buf_len, | |
478 bool truncate, | |
479 const net::CompletionCallback& callback) { | |
480 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | |
481 operation->WriteData(entry, index, offset, buf, buf_len, truncate); | |
482 PostOperation(operation); | |
483 } | |
484 | |
485 void InFlightBackendIO::ReadSparseData(EntryImpl* entry, int64 offset, | 418 void InFlightBackendIO::ReadSparseData(EntryImpl* entry, int64 offset, |
486 net::IOBuffer* buf, int buf_len, | 419 net::IOBuffer* buf, int buf_len, |
487 OldCompletionCallback* callback) { | 420 OldCompletionCallback* callback) { |
488 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 421 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
489 operation->ReadSparseData(entry, offset, buf, buf_len); | 422 operation->ReadSparseData(entry, offset, buf, buf_len); |
490 PostOperation(operation); | 423 PostOperation(operation); |
491 } | 424 } |
492 | 425 |
493 void InFlightBackendIO::WriteSparseData(EntryImpl* entry, int64 offset, | 426 void InFlightBackendIO::WriteSparseData(EntryImpl* entry, int64 offset, |
494 net::IOBuffer* buf, int buf_len, | 427 net::IOBuffer* buf, int buf_len, |
(...skipping 29 matching lines...) Expand all Loading... |
524 } | 457 } |
525 | 458 |
526 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, | 459 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, |
527 bool cancel) { | 460 bool cancel) { |
528 BackendIO* op = static_cast<BackendIO*>(operation); | 461 BackendIO* op = static_cast<BackendIO*>(operation); |
529 | 462 |
530 if (op->IsEntryOperation()) { | 463 if (op->IsEntryOperation()) { |
531 CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); | 464 CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); |
532 } | 465 } |
533 | 466 |
534 if (op->old_callback() && (!cancel || op->IsEntryOperation())) | 467 if (op->callback() && (!cancel || op->IsEntryOperation())) |
535 op->old_callback()->Run(op->result()); | 468 op->callback()->Run(op->result()); |
536 else if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) | |
537 op->callback().Run(op->result()); | |
538 } | 469 } |
539 | 470 |
540 void InFlightBackendIO::PostOperation(BackendIO* operation) { | 471 void InFlightBackendIO::PostOperation(BackendIO* operation) { |
541 background_thread_->PostTask(FROM_HERE, | 472 background_thread_->PostTask(FROM_HERE, |
542 base::Bind(&BackendIO::ExecuteOperation, operation)); | 473 base::Bind(&BackendIO::ExecuteOperation, operation)); |
543 OnOperationPosted(operation); | 474 OnOperationPosted(operation); |
544 } | 475 } |
545 | 476 |
546 } // namespace | 477 } // namespace |
OLD | NEW |