| OLD | NEW |
| 1 // Copyright (c) 2009-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009-2010 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/sparse_control.h" | 5 #include "net/disk_cache/sparse_control.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // And wait until OnFileIOComplete gets called. | 119 // And wait until OnFileIOComplete gets called. |
| 120 } | 120 } |
| 121 | 121 |
| 122 void ChildrenDeleter::DeleteChildren() { | 122 void ChildrenDeleter::DeleteChildren() { |
| 123 int child_id = 0; | 123 int child_id = 0; |
| 124 if (!children_map_.FindNextSetBit(&child_id)) { | 124 if (!children_map_.FindNextSetBit(&child_id)) { |
| 125 // We are done. Just delete this object. | 125 // We are done. Just delete this object. |
| 126 return Release(); | 126 return Release(); |
| 127 } | 127 } |
| 128 std::string child_name = GenerateChildName(name_, signature_, child_id); | 128 std::string child_name = GenerateChildName(name_, signature_, child_id); |
| 129 backend_->SyncDoomEntry(child_name); | 129 backend_->DoomEntry(child_name); |
| 130 children_map_.Set(child_id, false); | 130 children_map_.Set(child_id, false); |
| 131 | 131 |
| 132 // Post a task to delete the next child. | 132 // Post a task to delete the next child. |
| 133 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 133 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 134 this, &ChildrenDeleter::DeleteChildren)); | 134 this, &ChildrenDeleter::DeleteChildren)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 } // namespace. | 137 } // namespace. |
| 138 | 138 |
| 139 namespace disk_cache { | 139 namespace disk_cache { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 DCHECK_GE(result_, 0); | 366 DCHECK_GE(result_, 0); |
| 367 | 367 |
| 368 std::string key = GenerateChildKey(); | 368 std::string key = GenerateChildKey(); |
| 369 if (child_) { | 369 if (child_) { |
| 370 // Keep using the same child or open another one?. | 370 // Keep using the same child or open another one?. |
| 371 if (key == child_->GetKey()) | 371 if (key == child_->GetKey()) |
| 372 return true; | 372 return true; |
| 373 CloseChild(); | 373 CloseChild(); |
| 374 } | 374 } |
| 375 | 375 |
| 376 // See if we are tracking this child. | 376 // Se if we are tracking this child. |
| 377 if (!ChildPresent()) | 377 if (!ChildPresent()) |
| 378 return ContinueWithoutChild(key); | 378 return ContinueWithoutChild(key); |
| 379 | 379 |
| 380 child_ = entry_->backend_->OpenEntryImpl(key); | 380 child_ = entry_->backend_->OpenEntryImpl(key); |
| 381 if (!child_) | 381 if (!child_) |
| 382 return ContinueWithoutChild(key); | 382 return ContinueWithoutChild(key); |
| 383 | 383 |
| 384 EntryImpl* child = static_cast<EntryImpl*>(child_); | 384 EntryImpl* child = static_cast<EntryImpl*>(child_); |
| 385 if (!(CHILD_ENTRY & child->GetEntryFlags()) || | 385 if (!(CHILD_ENTRY & child->GetEntryFlags()) || |
| 386 child->GetDataSize(kSparseIndex) < | 386 child->GetDataSize(kSparseIndex) < |
| (...skipping 24 matching lines...) Expand all Loading... |
| 411 | 411 |
| 412 void SparseControl::CloseChild() { | 412 void SparseControl::CloseChild() { |
| 413 scoped_refptr<net::WrappedIOBuffer> buf = | 413 scoped_refptr<net::WrappedIOBuffer> buf = |
| 414 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_)); | 414 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_)); |
| 415 | 415 |
| 416 // Save the allocation bitmap before closing the child entry. | 416 // Save the allocation bitmap before closing the child entry. |
| 417 int rv = child_->WriteData(kSparseIndex, 0, buf, sizeof(child_data_), | 417 int rv = child_->WriteData(kSparseIndex, 0, buf, sizeof(child_data_), |
| 418 NULL, false); | 418 NULL, false); |
| 419 if (rv != sizeof(child_data_)) | 419 if (rv != sizeof(child_data_)) |
| 420 DLOG(ERROR) << "Failed to save child data"; | 420 DLOG(ERROR) << "Failed to save child data"; |
| 421 child_->Release(); | 421 child_->Close(); |
| 422 child_ = NULL; | 422 child_ = NULL; |
| 423 } | 423 } |
| 424 | 424 |
| 425 std::string SparseControl::GenerateChildKey() { | 425 std::string SparseControl::GenerateChildKey() { |
| 426 return GenerateChildName(entry_->GetKey(), sparse_header_.signature, | 426 return GenerateChildName(entry_->GetKey(), sparse_header_.signature, |
| 427 offset_ >> 20); | 427 offset_ >> 20); |
| 428 } | 428 } |
| 429 | 429 |
| 430 // We are deleting the child because something went wrong. | 430 // We are deleting the child because something went wrong. |
| 431 bool SparseControl::KillChildAndContinue(const std::string& key, bool fatal) { | 431 bool SparseControl::KillChildAndContinue(const std::string& key, bool fatal) { |
| 432 SetChildBit(false); | 432 SetChildBit(false); |
| 433 child_->DoomImpl(); | 433 child_->Doom(); |
| 434 child_->Release(); | 434 child_->Close(); |
| 435 child_ = NULL; | 435 child_ = NULL; |
| 436 if (fatal) { | 436 if (fatal) { |
| 437 result_ = net::ERR_CACHE_READ_FAILURE; | 437 result_ = net::ERR_CACHE_READ_FAILURE; |
| 438 return false; | 438 return false; |
| 439 } | 439 } |
| 440 return ContinueWithoutChild(key); | 440 return ContinueWithoutChild(key); |
| 441 } | 441 } |
| 442 | 442 |
| 443 // We were not able to open this child; see what we can do. | 443 // We were not able to open this child; see what we can do. |
| 444 bool SparseControl::ContinueWithoutChild(const std::string& key) { | 444 bool SparseControl::ContinueWithoutChild(const std::string& key) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 if (!VerifyRange()) | 610 if (!VerifyRange()) |
| 611 return false; | 611 return false; |
| 612 | 612 |
| 613 // We have more work to do. Let's not trigger a callback to the caller. | 613 // We have more work to do. Let's not trigger a callback to the caller. |
| 614 finished_ = false; | 614 finished_ = false; |
| 615 net::CompletionCallback* callback = user_callback_ ? &child_callback_ : NULL; | 615 net::CompletionCallback* callback = user_callback_ ? &child_callback_ : NULL; |
| 616 | 616 |
| 617 int rv = 0; | 617 int rv = 0; |
| 618 switch (operation_) { | 618 switch (operation_) { |
| 619 case kReadOperation: | 619 case kReadOperation: |
| 620 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_, | 620 rv = child_->ReadData(kSparseData, child_offset_, user_buf_, child_len_, |
| 621 child_len_, callback); | 621 callback); |
| 622 break; | 622 break; |
| 623 case kWriteOperation: | 623 case kWriteOperation: |
| 624 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_, | 624 rv = child_->WriteData(kSparseData, child_offset_, user_buf_, child_len_, |
| 625 child_len_, callback, false); | 625 callback, false); |
| 626 break; | 626 break; |
| 627 case kGetRangeOperation: | 627 case kGetRangeOperation: |
| 628 rv = DoGetAvailableRange(); | 628 rv = DoGetAvailableRange(); |
| 629 break; | 629 break; |
| 630 default: | 630 default: |
| 631 NOTREACHED(); | 631 NOTREACHED(); |
| 632 } | 632 } |
| 633 | 633 |
| 634 if (rv == net::ERR_IO_PENDING) { | 634 if (rv == net::ERR_IO_PENDING) { |
| 635 if (!pending_) { | 635 if (!pending_) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 net::CompletionCallback* c = abort_callbacks_[i]; | 749 net::CompletionCallback* c = abort_callbacks_[i]; |
| 750 if (i == abort_callbacks_.size() - 1) | 750 if (i == abort_callbacks_.size() - 1) |
| 751 abort_callbacks_.clear(); | 751 abort_callbacks_.clear(); |
| 752 | 752 |
| 753 entry_->Release(); // Don't touch object after this line. | 753 entry_->Release(); // Don't touch object after this line. |
| 754 c->Run(net::OK); | 754 c->Run(net::OK); |
| 755 } | 755 } |
| 756 } | 756 } |
| 757 | 757 |
| 758 } // namespace disk_cache | 758 } // namespace disk_cache |
| OLD | NEW |