| 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/sparse_control.h" | 5 #include "net/disk_cache/blockfile/sparse_control.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const int kMaxEntrySize = 0x100000; | 35 const int kMaxEntrySize = 0x100000; |
| 36 | 36 |
| 37 // The size of each data block (tracked by the child allocation bitmap). | 37 // The size of each data block (tracked by the child allocation bitmap). |
| 38 const int kBlockSize = 1024; | 38 const int kBlockSize = 1024; |
| 39 | 39 |
| 40 // Returns the name of a child entry given the base_name and signature of the | 40 // Returns the name of a child entry given the base_name and signature of the |
| 41 // parent and the child_id. | 41 // parent and the child_id. |
| 42 // If the entry is called entry_name, child entries will be named something | 42 // If the entry is called entry_name, child entries will be named something |
| 43 // like Range_entry_name:XXX:YYY where XXX is the entry signature and YYY is the | 43 // like Range_entry_name:XXX:YYY where XXX is the entry signature and YYY is the |
| 44 // number of the particular child. | 44 // number of the particular child. |
| 45 std::string GenerateChildName(const std::string& base_name, int64 signature, | 45 std::string GenerateChildName(const std::string& base_name, |
| 46 int64 signature, |
| 46 int64 child_id) { | 47 int64 child_id) { |
| 47 return base::StringPrintf("Range_%s:%" PRIx64 ":%" PRIx64, base_name.c_str(), | 48 return base::StringPrintf( |
| 48 signature, child_id); | 49 "Range_%s:%" PRIx64 ":%" PRIx64, base_name.c_str(), signature, child_id); |
| 49 } | 50 } |
| 50 | 51 |
| 51 // This class deletes the children of a sparse entry. | 52 // This class deletes the children of a sparse entry. |
| 52 class ChildrenDeleter | 53 class ChildrenDeleter : public base::RefCounted<ChildrenDeleter>, |
| 53 : public base::RefCounted<ChildrenDeleter>, | 54 public disk_cache::FileIOCallback { |
| 54 public disk_cache::FileIOCallback { | |
| 55 public: | 55 public: |
| 56 ChildrenDeleter(disk_cache::BackendImpl* backend, const std::string& name) | 56 ChildrenDeleter(disk_cache::BackendImpl* backend, const std::string& name) |
| 57 : backend_(backend->GetWeakPtr()), name_(name), signature_(0) {} | 57 : backend_(backend->GetWeakPtr()), name_(name), signature_(0) {} |
| 58 | 58 |
| 59 virtual void OnFileIOComplete(int bytes_copied) OVERRIDE; | 59 virtual void OnFileIOComplete(int bytes_copied) OVERRIDE; |
| 60 | 60 |
| 61 // Two ways of deleting the children: if we have the children map, use Start() | 61 // Two ways of deleting the children: if we have the children map, use Start() |
| 62 // directly, otherwise pass the data address to ReadData(). | 62 // directly, otherwise pass the data address to ReadData(). |
| 63 void Start(char* buffer, int len); | 63 void Start(char* buffer, int len); |
| 64 void ReadData(disk_cache::Addr address, int len); | 64 void ReadData(disk_cache::Addr address, int len); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 bool SparseControl::CouldBeSparse() const { | 215 bool SparseControl::CouldBeSparse() const { |
| 216 DCHECK(!init_); | 216 DCHECK(!init_); |
| 217 | 217 |
| 218 if (entry_->GetDataSize(kSparseData)) | 218 if (entry_->GetDataSize(kSparseData)) |
| 219 return false; | 219 return false; |
| 220 | 220 |
| 221 // We don't verify the data, just see if it could be there. | 221 // We don't verify the data, just see if it could be there. |
| 222 return (entry_->GetDataSize(kSparseIndex) != 0); | 222 return (entry_->GetDataSize(kSparseIndex) != 0); |
| 223 } | 223 } |
| 224 | 224 |
| 225 int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, | 225 int SparseControl::StartIO(SparseOperation op, |
| 226 int buf_len, const CompletionCallback& callback) { | 226 int64 offset, |
| 227 net::IOBuffer* buf, |
| 228 int buf_len, |
| 229 const CompletionCallback& callback) { |
| 227 DCHECK(init_); | 230 DCHECK(init_); |
| 228 // We don't support simultaneous IO for sparse data. | 231 // We don't support simultaneous IO for sparse data. |
| 229 if (operation_ != kNoOperation) | 232 if (operation_ != kNoOperation) |
| 230 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 233 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 231 | 234 |
| 232 if (offset < 0 || buf_len < 0) | 235 if (offset < 0 || buf_len < 0) |
| 233 return net::ERR_INVALID_ARGUMENT; | 236 return net::ERR_INVALID_ARGUMENT; |
| 234 | 237 |
| 235 // We only support up to 64 GB. | 238 // We only support up to 64 GB. |
| 236 if (offset + buf_len >= 0x1000000000LL || offset + buf_len < 0) | 239 if (offset + buf_len >= 0x1000000000LL || offset + buf_len < 0) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 277 |
| 275 int SparseControl::GetAvailableRange(int64 offset, int len, int64* start) { | 278 int SparseControl::GetAvailableRange(int64 offset, int len, int64* start) { |
| 276 DCHECK(init_); | 279 DCHECK(init_); |
| 277 // We don't support simultaneous IO for sparse data. | 280 // We don't support simultaneous IO for sparse data. |
| 278 if (operation_ != kNoOperation) | 281 if (operation_ != kNoOperation) |
| 279 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 282 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 280 | 283 |
| 281 DCHECK(start); | 284 DCHECK(start); |
| 282 | 285 |
| 283 range_found_ = false; | 286 range_found_ = false; |
| 284 int result = StartIO( | 287 int result = |
| 285 kGetRangeOperation, offset, NULL, len, CompletionCallback()); | 288 StartIO(kGetRangeOperation, offset, NULL, len, CompletionCallback()); |
| 286 if (range_found_) { | 289 if (range_found_) { |
| 287 *start = offset_; | 290 *start = offset_; |
| 288 return result; | 291 return result; |
| 289 } | 292 } |
| 290 | 293 |
| 291 // This is a failure. We want to return a valid start value in any case. | 294 // This is a failure. We want to return a valid start value in any case. |
| 292 *start = offset; | 295 *start = offset; |
| 293 return result < 0 ? result : 0; // Don't mask error codes to the caller. | 296 return result < 0 ? result : 0; // Don't mask error codes to the caller. |
| 294 } | 297 } |
| 295 | 298 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 325 | 328 |
| 326 char* buffer; | 329 char* buffer; |
| 327 Addr address; | 330 Addr address; |
| 328 entry->GetData(kSparseIndex, &buffer, &address); | 331 entry->GetData(kSparseIndex, &buffer, &address); |
| 329 if (!buffer && !address.is_initialized()) | 332 if (!buffer && !address.is_initialized()) |
| 330 return; | 333 return; |
| 331 | 334 |
| 332 entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN); | 335 entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN); |
| 333 | 336 |
| 334 DCHECK(entry->backend_); | 337 DCHECK(entry->backend_); |
| 335 ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_.get(), | 338 ChildrenDeleter* deleter = |
| 336 entry->GetKey()); | 339 new ChildrenDeleter(entry->backend_.get(), entry->GetKey()); |
| 337 // The object will self destruct when finished. | 340 // The object will self destruct when finished. |
| 338 deleter->AddRef(); | 341 deleter->AddRef(); |
| 339 | 342 |
| 340 if (buffer) { | 343 if (buffer) { |
| 341 base::MessageLoop::current()->PostTask( | 344 base::MessageLoop::current()->PostTask( |
| 342 FROM_HERE, | 345 FROM_HERE, |
| 343 base::Bind(&ChildrenDeleter::Start, deleter, buffer, data_len)); | 346 base::Bind(&ChildrenDeleter::Start, deleter, buffer, data_len)); |
| 344 } else { | 347 } else { |
| 345 base::MessageLoop::current()->PostTask( | 348 base::MessageLoop::current()->PostTask( |
| 346 FROM_HERE, | 349 FROM_HERE, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 memset(&sparse_header_, 0, sizeof(sparse_header_)); | 383 memset(&sparse_header_, 0, sizeof(sparse_header_)); |
| 381 sparse_header_.signature = Time::Now().ToInternalValue(); | 384 sparse_header_.signature = Time::Now().ToInternalValue(); |
| 382 sparse_header_.magic = kIndexMagic; | 385 sparse_header_.magic = kIndexMagic; |
| 383 sparse_header_.parent_key_len = entry_->GetKey().size(); | 386 sparse_header_.parent_key_len = entry_->GetKey().size(); |
| 384 children_map_.Resize(kNumSparseBits, true); | 387 children_map_.Resize(kNumSparseBits, true); |
| 385 | 388 |
| 386 // Save the header. The bitmap is saved in the destructor. | 389 // Save the header. The bitmap is saved in the destructor. |
| 387 scoped_refptr<net::IOBuffer> buf( | 390 scoped_refptr<net::IOBuffer> buf( |
| 388 new net::WrappedIOBuffer(reinterpret_cast<char*>(&sparse_header_))); | 391 new net::WrappedIOBuffer(reinterpret_cast<char*>(&sparse_header_))); |
| 389 | 392 |
| 390 int rv = entry_->WriteData(kSparseIndex, 0, buf.get(), sizeof(sparse_header_), | 393 int rv = entry_->WriteData(kSparseIndex, |
| 391 CompletionCallback(), false); | 394 0, |
| 395 buf.get(), |
| 396 sizeof(sparse_header_), |
| 397 CompletionCallback(), |
| 398 false); |
| 392 if (rv != sizeof(sparse_header_)) { | 399 if (rv != sizeof(sparse_header_)) { |
| 393 DLOG(ERROR) << "Unable to save sparse_header_"; | 400 DLOG(ERROR) << "Unable to save sparse_header_"; |
| 394 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 401 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 395 } | 402 } |
| 396 | 403 |
| 397 entry_->SetEntryFlags(PARENT_ENTRY); | 404 entry_->SetEntryFlags(PARENT_ENTRY); |
| 398 return net::OK; | 405 return net::OK; |
| 399 } | 406 } |
| 400 | 407 |
| 401 // We are opening an entry from disk. Make sure that our control data is there. | 408 // We are opening an entry from disk. Make sure that our control data is there. |
| 402 int SparseControl::OpenSparseEntry(int data_len) { | 409 int SparseControl::OpenSparseEntry(int data_len) { |
| 403 if (data_len < static_cast<int>(sizeof(SparseData))) | 410 if (data_len < static_cast<int>(sizeof(SparseData))) |
| 404 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 411 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 405 | 412 |
| 406 if (entry_->GetDataSize(kSparseData)) | 413 if (entry_->GetDataSize(kSparseData)) |
| 407 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 414 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 408 | 415 |
| 409 if (!(PARENT_ENTRY & entry_->GetEntryFlags())) | 416 if (!(PARENT_ENTRY & entry_->GetEntryFlags())) |
| 410 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 417 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 411 | 418 |
| 412 // Dont't go over board with the bitmap. 8 KB gives us offsets up to 64 GB. | 419 // Dont't go over board with the bitmap. 8 KB gives us offsets up to 64 GB. |
| 413 int map_len = data_len - sizeof(sparse_header_); | 420 int map_len = data_len - sizeof(sparse_header_); |
| 414 if (map_len > kMaxMapSize || map_len % 4) | 421 if (map_len > kMaxMapSize || map_len % 4) |
| 415 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 422 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 416 | 423 |
| 417 scoped_refptr<net::IOBuffer> buf( | 424 scoped_refptr<net::IOBuffer> buf( |
| 418 new net::WrappedIOBuffer(reinterpret_cast<char*>(&sparse_header_))); | 425 new net::WrappedIOBuffer(reinterpret_cast<char*>(&sparse_header_))); |
| 419 | 426 |
| 420 // Read header. | 427 // Read header. |
| 421 int rv = entry_->ReadData(kSparseIndex, 0, buf.get(), sizeof(sparse_header_), | 428 int rv = entry_->ReadData( |
| 422 CompletionCallback()); | 429 kSparseIndex, 0, buf.get(), sizeof(sparse_header_), CompletionCallback()); |
| 423 if (rv != static_cast<int>(sizeof(sparse_header_))) | 430 if (rv != static_cast<int>(sizeof(sparse_header_))) |
| 424 return net::ERR_CACHE_READ_FAILURE; | 431 return net::ERR_CACHE_READ_FAILURE; |
| 425 | 432 |
| 426 // The real validation should be performed by the caller. This is just to | 433 // The real validation should be performed by the caller. This is just to |
| 427 // double check. | 434 // double check. |
| 428 if (sparse_header_.magic != kIndexMagic || | 435 if (sparse_header_.magic != kIndexMagic || |
| 429 sparse_header_.parent_key_len != | 436 sparse_header_.parent_key_len != |
| 430 static_cast<int>(entry_->GetKey().size())) | 437 static_cast<int>(entry_->GetKey().size())) |
| 431 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 438 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 432 | 439 |
| 433 // Read the actual bitmap. | 440 // Read the actual bitmap. |
| 434 buf = new net::IOBuffer(map_len); | 441 buf = new net::IOBuffer(map_len); |
| 435 rv = entry_->ReadData(kSparseIndex, sizeof(sparse_header_), buf.get(), | 442 rv = entry_->ReadData(kSparseIndex, |
| 436 map_len, CompletionCallback()); | 443 sizeof(sparse_header_), |
| 444 buf.get(), |
| 445 map_len, |
| 446 CompletionCallback()); |
| 437 if (rv != map_len) | 447 if (rv != map_len) |
| 438 return net::ERR_CACHE_READ_FAILURE; | 448 return net::ERR_CACHE_READ_FAILURE; |
| 439 | 449 |
| 440 // Grow the bitmap to the current size and copy the bits. | 450 // Grow the bitmap to the current size and copy the bits. |
| 441 children_map_.Resize(map_len * 8, false); | 451 children_map_.Resize(map_len * 8, false); |
| 442 children_map_.SetMap(reinterpret_cast<uint32*>(buf->data()), map_len); | 452 children_map_.SetMap(reinterpret_cast<uint32*>(buf->data()), map_len); |
| 443 return net::OK; | 453 return net::OK; |
| 444 } | 454 } |
| 445 | 455 |
| 446 bool SparseControl::OpenChild() { | 456 bool SparseControl::OpenChild() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 460 | 470 |
| 461 if (!entry_->backend_) | 471 if (!entry_->backend_) |
| 462 return false; | 472 return false; |
| 463 | 473 |
| 464 child_ = entry_->backend_->OpenEntryImpl(key); | 474 child_ = entry_->backend_->OpenEntryImpl(key); |
| 465 if (!child_) | 475 if (!child_) |
| 466 return ContinueWithoutChild(key); | 476 return ContinueWithoutChild(key); |
| 467 | 477 |
| 468 EntryImpl* child = static_cast<EntryImpl*>(child_); | 478 EntryImpl* child = static_cast<EntryImpl*>(child_); |
| 469 if (!(CHILD_ENTRY & child->GetEntryFlags()) || | 479 if (!(CHILD_ENTRY & child->GetEntryFlags()) || |
| 470 child->GetDataSize(kSparseIndex) < | 480 child->GetDataSize(kSparseIndex) < static_cast<int>(sizeof(child_data_))) |
| 471 static_cast<int>(sizeof(child_data_))) | |
| 472 return KillChildAndContinue(key, false); | 481 return KillChildAndContinue(key, false); |
| 473 | 482 |
| 474 scoped_refptr<net::WrappedIOBuffer> buf( | 483 scoped_refptr<net::WrappedIOBuffer> buf( |
| 475 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_))); | 484 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_))); |
| 476 | 485 |
| 477 // Read signature. | 486 // Read signature. |
| 478 int rv = child_->ReadData(kSparseIndex, 0, buf.get(), sizeof(child_data_), | 487 int rv = child_->ReadData( |
| 479 CompletionCallback()); | 488 kSparseIndex, 0, buf.get(), sizeof(child_data_), CompletionCallback()); |
| 480 if (rv != sizeof(child_data_)) | 489 if (rv != sizeof(child_data_)) |
| 481 return KillChildAndContinue(key, true); // This is a fatal failure. | 490 return KillChildAndContinue(key, true); // This is a fatal failure. |
| 482 | 491 |
| 483 if (child_data_.header.signature != sparse_header_.signature || | 492 if (child_data_.header.signature != sparse_header_.signature || |
| 484 child_data_.header.magic != kIndexMagic) | 493 child_data_.header.magic != kIndexMagic) |
| 485 return KillChildAndContinue(key, false); | 494 return KillChildAndContinue(key, false); |
| 486 | 495 |
| 487 if (child_data_.header.last_block_len < 0 || | 496 if (child_data_.header.last_block_len < 0 || |
| 488 child_data_.header.last_block_len > kBlockSize) { | 497 child_data_.header.last_block_len > kBlockSize) { |
| 489 // Make sure these values are always within range. | 498 // Make sure these values are always within range. |
| 490 child_data_.header.last_block_len = 0; | 499 child_data_.header.last_block_len = 0; |
| 491 child_data_.header.last_block = -1; | 500 child_data_.header.last_block = -1; |
| 492 } | 501 } |
| 493 | 502 |
| 494 return true; | 503 return true; |
| 495 } | 504 } |
| 496 | 505 |
| 497 void SparseControl::CloseChild() { | 506 void SparseControl::CloseChild() { |
| 498 scoped_refptr<net::WrappedIOBuffer> buf( | 507 scoped_refptr<net::WrappedIOBuffer> buf( |
| 499 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_))); | 508 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_))); |
| 500 | 509 |
| 501 // Save the allocation bitmap before closing the child entry. | 510 // Save the allocation bitmap before closing the child entry. |
| 502 int rv = child_->WriteData(kSparseIndex, 0, buf.get(), sizeof(child_data_), | 511 int rv = child_->WriteData(kSparseIndex, |
| 512 0, |
| 513 buf.get(), |
| 514 sizeof(child_data_), |
| 503 CompletionCallback(), | 515 CompletionCallback(), |
| 504 false); | 516 false); |
| 505 if (rv != sizeof(child_data_)) | 517 if (rv != sizeof(child_data_)) |
| 506 DLOG(ERROR) << "Failed to save child data"; | 518 DLOG(ERROR) << "Failed to save child data"; |
| 507 child_->Release(); | 519 child_->Release(); |
| 508 child_ = NULL; | 520 child_ = NULL; |
| 509 } | 521 } |
| 510 | 522 |
| 511 // We were not able to open this child; see what we can do. | 523 // We were not able to open this child; see what we can do. |
| 512 bool SparseControl::ContinueWithoutChild(const std::string& key) { | 524 bool SparseControl::ContinueWithoutChild(const std::string& key) { |
| 513 if (kReadOperation == operation_) | 525 if (kReadOperation == operation_) |
| 514 return false; | 526 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 527 // Write signature. | 539 // Write signature. |
| 528 InitChildData(); | 540 InitChildData(); |
| 529 return true; | 541 return true; |
| 530 } | 542 } |
| 531 | 543 |
| 532 void SparseControl::WriteSparseData() { | 544 void SparseControl::WriteSparseData() { |
| 533 scoped_refptr<net::IOBuffer> buf(new net::WrappedIOBuffer( | 545 scoped_refptr<net::IOBuffer> buf(new net::WrappedIOBuffer( |
| 534 reinterpret_cast<const char*>(children_map_.GetMap()))); | 546 reinterpret_cast<const char*>(children_map_.GetMap()))); |
| 535 | 547 |
| 536 int len = children_map_.ArraySize() * 4; | 548 int len = children_map_.ArraySize() * 4; |
| 537 int rv = entry_->WriteData(kSparseIndex, sizeof(sparse_header_), buf.get(), | 549 int rv = entry_->WriteData(kSparseIndex, |
| 538 len, CompletionCallback(), false); | 550 sizeof(sparse_header_), |
| 551 buf.get(), |
| 552 len, |
| 553 CompletionCallback(), |
| 554 false); |
| 539 if (rv != len) { | 555 if (rv != len) { |
| 540 DLOG(ERROR) << "Unable to save sparse map"; | 556 DLOG(ERROR) << "Unable to save sparse map"; |
| 541 } | 557 } |
| 542 } | 558 } |
| 543 | 559 |
| 544 bool SparseControl::DoChildIO() { | 560 bool SparseControl::DoChildIO() { |
| 545 finished_ = true; | 561 finished_ = true; |
| 546 if (!buf_len_ || result_ < 0) | 562 if (!buf_len_ || result_ < 0) |
| 547 return false; | 563 return false; |
| 548 | 564 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 562 | 578 |
| 563 int rv = 0; | 579 int rv = 0; |
| 564 switch (operation_) { | 580 switch (operation_) { |
| 565 case kReadOperation: | 581 case kReadOperation: |
| 566 if (entry_->net_log().IsLogging()) { | 582 if (entry_->net_log().IsLogging()) { |
| 567 entry_->net_log().BeginEvent( | 583 entry_->net_log().BeginEvent( |
| 568 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, | 584 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, |
| 569 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), | 585 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), |
| 570 child_len_)); | 586 child_len_)); |
| 571 } | 587 } |
| 572 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_.get(), | 588 rv = child_->ReadDataImpl( |
| 573 child_len_, callback); | 589 kSparseData, child_offset_, user_buf_.get(), child_len_, callback); |
| 574 break; | 590 break; |
| 575 case kWriteOperation: | 591 case kWriteOperation: |
| 576 if (entry_->net_log().IsLogging()) { | 592 if (entry_->net_log().IsLogging()) { |
| 577 entry_->net_log().BeginEvent( | 593 entry_->net_log().BeginEvent( |
| 578 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, | 594 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, |
| 579 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), | 595 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), |
| 580 child_len_)); | 596 child_len_)); |
| 581 } | 597 } |
| 582 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_.get(), | 598 rv = child_->WriteDataImpl(kSparseData, |
| 583 child_len_, callback, false); | 599 child_offset_, |
| 600 user_buf_.get(), |
| 601 child_len_, |
| 602 callback, |
| 603 false); |
| 584 break; | 604 break; |
| 585 case kGetRangeOperation: | 605 case kGetRangeOperation: |
| 586 rv = DoGetAvailableRange(); | 606 rv = DoGetAvailableRange(); |
| 587 break; | 607 break; |
| 588 default: | 608 default: |
| 589 NOTREACHED(); | 609 NOTREACHED(); |
| 590 } | 610 } |
| 591 | 611 |
| 592 if (rv == net::ERR_IO_PENDING) { | 612 if (rv == net::ERR_IO_PENDING) { |
| 593 if (!pending_) { | 613 if (!pending_) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 620 result_ += result; | 640 result_ += result; |
| 621 offset_ += result; | 641 offset_ += result; |
| 622 buf_len_ -= result; | 642 buf_len_ -= result; |
| 623 | 643 |
| 624 // We'll be reusing the user provided buffer for the next chunk. | 644 // We'll be reusing the user provided buffer for the next chunk. |
| 625 if (buf_len_ && user_buf_) | 645 if (buf_len_ && user_buf_) |
| 626 user_buf_->DidConsume(result); | 646 user_buf_->DidConsume(result); |
| 627 } | 647 } |
| 628 | 648 |
| 629 std::string SparseControl::GenerateChildKey() { | 649 std::string SparseControl::GenerateChildKey() { |
| 630 return GenerateChildName(entry_->GetKey(), sparse_header_.signature, | 650 return GenerateChildName( |
| 631 offset_ >> 20); | 651 entry_->GetKey(), sparse_header_.signature, offset_ >> 20); |
| 632 } | 652 } |
| 633 | 653 |
| 634 // We are deleting the child because something went wrong. | 654 // We are deleting the child because something went wrong. |
| 635 bool SparseControl::KillChildAndContinue(const std::string& key, bool fatal) { | 655 bool SparseControl::KillChildAndContinue(const std::string& key, bool fatal) { |
| 636 SetChildBit(false); | 656 SetChildBit(false); |
| 637 child_->DoomImpl(); | 657 child_->DoomImpl(); |
| 638 child_->Release(); | 658 child_->Release(); |
| 639 child_ = NULL; | 659 child_ = NULL; |
| 640 if (fatal) { | 660 if (fatal) { |
| 641 result_ = net::ERR_CACHE_READ_FAILURE; | 661 result_ = net::ERR_CACHE_READ_FAILURE; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 // We know the real type of child_. | 772 // We know the real type of child_. |
| 753 EntryImpl* child = static_cast<EntryImpl*>(child_); | 773 EntryImpl* child = static_cast<EntryImpl*>(child_); |
| 754 child->SetEntryFlags(CHILD_ENTRY); | 774 child->SetEntryFlags(CHILD_ENTRY); |
| 755 | 775 |
| 756 memset(&child_data_, 0, sizeof(child_data_)); | 776 memset(&child_data_, 0, sizeof(child_data_)); |
| 757 child_data_.header = sparse_header_; | 777 child_data_.header = sparse_header_; |
| 758 | 778 |
| 759 scoped_refptr<net::WrappedIOBuffer> buf( | 779 scoped_refptr<net::WrappedIOBuffer> buf( |
| 760 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_))); | 780 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_))); |
| 761 | 781 |
| 762 int rv = child_->WriteData(kSparseIndex, 0, buf.get(), sizeof(child_data_), | 782 int rv = child_->WriteData(kSparseIndex, |
| 763 CompletionCallback(), false); | 783 0, |
| 784 buf.get(), |
| 785 sizeof(child_data_), |
| 786 CompletionCallback(), |
| 787 false); |
| 764 if (rv != sizeof(child_data_)) | 788 if (rv != sizeof(child_data_)) |
| 765 DLOG(ERROR) << "Failed to save child data"; | 789 DLOG(ERROR) << "Failed to save child data"; |
| 766 SetChildBit(true); | 790 SetChildBit(true); |
| 767 } | 791 } |
| 768 | 792 |
| 769 int SparseControl::DoGetAvailableRange() { | 793 int SparseControl::DoGetAvailableRange() { |
| 770 if (!child_) | 794 if (!child_) |
| 771 return child_len_; // Move on to the next child. | 795 return child_len_; // Move on to the next child. |
| 772 | 796 |
| 773 // Check that there are no holes in this range. | 797 // Check that there are no holes in this range. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 DoAbortCallbacks(); | 883 DoAbortCallbacks(); |
| 860 return; | 884 return; |
| 861 } | 885 } |
| 862 | 886 |
| 863 // We are running a callback from the message loop. It's time to restart what | 887 // We are running a callback from the message loop. It's time to restart what |
| 864 // we were doing before. | 888 // we were doing before. |
| 865 DoChildrenIO(); | 889 DoChildrenIO(); |
| 866 } | 890 } |
| 867 | 891 |
| 868 } // namespace disk_cache | 892 } // namespace disk_cache |
| OLD | NEW |