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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Se if we are tracking this child. | 376 // Se if we are tracking this child. |
377 bool child_present = ChildPresent(); | 377 if (!ChildPresent()) |
378 if (!child_present || !entry_->backend_->OpenEntry(key, &child_)) | 378 return ContinueWithoutChild(key); |
| 379 |
| 380 child_ = entry_->backend_->OpenEntryImpl(key); |
| 381 if (!child_) |
379 return ContinueWithoutChild(key); | 382 return ContinueWithoutChild(key); |
380 | 383 |
381 EntryImpl* child = static_cast<EntryImpl*>(child_); | 384 EntryImpl* child = static_cast<EntryImpl*>(child_); |
382 if (!(CHILD_ENTRY & child->GetEntryFlags()) || | 385 if (!(CHILD_ENTRY & child->GetEntryFlags()) || |
383 child->GetDataSize(kSparseIndex) < | 386 child->GetDataSize(kSparseIndex) < |
384 static_cast<int>(sizeof(child_data_))) | 387 static_cast<int>(sizeof(child_data_))) |
385 return KillChildAndContinue(key, false); | 388 return KillChildAndContinue(key, false); |
386 | 389 |
387 scoped_refptr<net::WrappedIOBuffer> buf = | 390 scoped_refptr<net::WrappedIOBuffer> buf = |
388 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_)); | 391 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_)); |
389 | 392 |
390 // Read signature. | 393 // Read signature. |
391 int rv = child_->ReadData(kSparseIndex, 0, buf, sizeof(child_data_), NULL); | 394 int rv = child_->ReadData(kSparseIndex, 0, buf, sizeof(child_data_), NULL); |
392 if (rv != sizeof(child_data_)) | 395 if (rv != sizeof(child_data_)) |
393 return KillChildAndContinue(key, true); // This is a fatal failure. | 396 return KillChildAndContinue(key, true); // This is a fatal failure. |
394 | 397 |
395 if (child_data_.header.signature != sparse_header_.signature || | 398 if (child_data_.header.signature != sparse_header_.signature || |
396 child_data_.header.magic != kIndexMagic) | 399 child_data_.header.magic != kIndexMagic) |
397 return KillChildAndContinue(key, false); | 400 return KillChildAndContinue(key, false); |
398 | 401 |
399 if (child_data_.header.last_block_len < 0 || | 402 if (child_data_.header.last_block_len < 0 || |
400 child_data_.header.last_block_len > kBlockSize) { | 403 child_data_.header.last_block_len > kBlockSize) { |
401 // Make sure this values are always within range. | 404 // Make sure these values are always within range. |
402 child_data_.header.last_block_len = 0; | 405 child_data_.header.last_block_len = 0; |
403 child_data_.header.last_block = -1; | 406 child_data_.header.last_block = -1; |
404 } | 407 } |
405 | 408 |
406 return true; | 409 return true; |
407 } | 410 } |
408 | 411 |
409 void SparseControl::CloseChild() { | 412 void SparseControl::CloseChild() { |
410 scoped_refptr<net::WrappedIOBuffer> buf = | 413 scoped_refptr<net::WrappedIOBuffer> buf = |
411 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_)); | 414 new net::WrappedIOBuffer(reinterpret_cast<char*>(&child_data_)); |
(...skipping 25 matching lines...) Expand all Loading... |
437 return ContinueWithoutChild(key); | 440 return ContinueWithoutChild(key); |
438 } | 441 } |
439 | 442 |
440 // 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. |
441 bool SparseControl::ContinueWithoutChild(const std::string& key) { | 444 bool SparseControl::ContinueWithoutChild(const std::string& key) { |
442 if (kReadOperation == operation_) | 445 if (kReadOperation == operation_) |
443 return false; | 446 return false; |
444 if (kGetRangeOperation == operation_) | 447 if (kGetRangeOperation == operation_) |
445 return true; | 448 return true; |
446 | 449 |
447 if (!entry_->backend_->CreateEntry(key, &child_)) { | 450 child_ = entry_->backend_->CreateEntryImpl(key); |
| 451 if (!child_) { |
448 child_ = NULL; | 452 child_ = NULL; |
449 result_ = net::ERR_CACHE_READ_FAILURE; | 453 result_ = net::ERR_CACHE_READ_FAILURE; |
450 return false; | 454 return false; |
451 } | 455 } |
452 // Write signature. | 456 // Write signature. |
453 InitChildData(); | 457 InitChildData(); |
454 return true; | 458 return true; |
455 } | 459 } |
456 | 460 |
457 bool SparseControl::ChildPresent() { | 461 bool SparseControl::ChildPresent() { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 net::CompletionCallback* c = abort_callbacks_[i]; | 749 net::CompletionCallback* c = abort_callbacks_[i]; |
746 if (i == abort_callbacks_.size() - 1) | 750 if (i == abort_callbacks_.size() - 1) |
747 abort_callbacks_.clear(); | 751 abort_callbacks_.clear(); |
748 | 752 |
749 entry_->Release(); // Don't touch object after this line. | 753 entry_->Release(); // Don't touch object after this line. |
750 c->Run(net::OK); | 754 c->Run(net::OK); |
751 } | 755 } |
752 } | 756 } |
753 | 757 |
754 } // namespace disk_cache | 758 } // namespace disk_cache |
OLD | NEW |