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/backend_impl.h" | 5 #include "net/disk_cache/backend_impl.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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 if (!(user_flags_ & kNoRandom)) { | 440 if (!(user_flags_ & kNoRandom)) { |
441 // The unit test controls directly what to test. | 441 // The unit test controls directly what to test. |
442 new_eviction_ = (cache_type_ == net::DISK_CACHE); | 442 new_eviction_ = (cache_type_ == net::DISK_CACHE); |
443 } | 443 } |
444 | 444 |
445 if (!CheckIndex()) { | 445 if (!CheckIndex()) { |
446 ReportError(ERR_INIT_FAILED); | 446 ReportError(ERR_INIT_FAILED); |
447 return net::ERR_FAILED; | 447 return net::ERR_FAILED; |
448 } | 448 } |
449 | 449 |
| 450 if (create_files || !data_->header.num_entries) |
| 451 ReportError(ERR_CACHE_CREATED); |
| 452 |
450 if (!(user_flags_ & kNoRandom) && | 453 if (!(user_flags_ & kNoRandom) && |
451 cache_type_ == net::DISK_CACHE && !InitExperiment(&data_->header)) | 454 cache_type_ == net::DISK_CACHE && !InitExperiment(&data_->header)) |
452 return net::ERR_FAILED; | 455 return net::ERR_FAILED; |
453 | 456 |
454 // We don't care if the value overflows. The only thing we care about is that | 457 // We don't care if the value overflows. The only thing we care about is that |
455 // the id cannot be zero, because that value is used as "not dirty". | 458 // the id cannot be zero, because that value is used as "not dirty". |
456 // Increasing the value once per second gives us many years before we start | 459 // Increasing the value once per second gives us many years before we start |
457 // having collisions. | 460 // having collisions. |
458 data_->header.this_id++; | 461 data_->header.this_id++; |
459 if (!data_->header.this_id) | 462 if (!data_->header.this_id) |
(...skipping 17 matching lines...) Expand all Loading... |
477 | 480 |
478 eviction_.Init(this); | 481 eviction_.Init(this); |
479 | 482 |
480 // stats_ and rankings_ may end up calling back to us so we better be enabled. | 483 // stats_ and rankings_ may end up calling back to us so we better be enabled. |
481 disabled_ = false; | 484 disabled_ = false; |
482 if (!stats_.Init(this, &data_->header.stats)) | 485 if (!stats_.Init(this, &data_->header.stats)) |
483 return net::ERR_FAILED; | 486 return net::ERR_FAILED; |
484 | 487 |
485 disabled_ = !rankings_.Init(this, new_eviction_); | 488 disabled_ = !rankings_.Init(this, new_eviction_); |
486 | 489 |
| 490 if (!disabled_ && !(user_flags_ & kNoRandom) && base::RandInt(0, 99) < 2) |
| 491 rankings_.SelfCheck(); // Ignore return value for now. |
| 492 |
487 #if defined(STRESS_CACHE_EXTENDED_VALIDATION) | 493 #if defined(STRESS_CACHE_EXTENDED_VALIDATION) |
488 trace_object_->EnableTracing(false); | 494 trace_object_->EnableTracing(false); |
489 int sc = SelfCheck(); | 495 int sc = SelfCheck(); |
490 if (sc < 0 && sc != ERR_NUM_ENTRIES_MISMATCH) | 496 if (sc < 0 && sc != ERR_NUM_ENTRIES_MISMATCH) |
491 NOTREACHED(); | 497 NOTREACHED(); |
492 trace_object_->EnableTracing(true); | 498 trace_object_->EnableTracing(true); |
493 #endif | 499 #endif |
494 | 500 |
495 return disabled_ ? net::ERR_FAILED : net::OK; | 501 return disabled_ ? net::ERR_FAILED : net::OK; |
496 } | 502 } |
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 if (it != open_entries_.end()) { | 1547 if (it != open_entries_.end()) { |
1542 // Easy job. This entry is already in memory. | 1548 // Easy job. This entry is already in memory. |
1543 EntryImpl* this_entry = it->second; | 1549 EntryImpl* this_entry = it->second; |
1544 this_entry->AddRef(); | 1550 this_entry->AddRef(); |
1545 *entry = this_entry; | 1551 *entry = this_entry; |
1546 return 0; | 1552 return 0; |
1547 } | 1553 } |
1548 | 1554 |
1549 STRESS_DCHECK(block_files_.IsValid(address)); | 1555 STRESS_DCHECK(block_files_.IsValid(address)); |
1550 | 1556 |
1551 if (!address.is_initialized() || address.is_separate_file() || | 1557 if (!address.SanityCheckForEntry()) { |
1552 address.file_type() != BLOCK_256) { | |
1553 LOG(WARNING) << "Wrong entry address."; | 1558 LOG(WARNING) << "Wrong entry address."; |
1554 STRESS_NOTREACHED(); | 1559 STRESS_NOTREACHED(); |
1555 return ERR_INVALID_ADDRESS; | 1560 return ERR_INVALID_ADDRESS; |
1556 } | 1561 } |
1557 | 1562 |
1558 scoped_refptr<EntryImpl> cache_entry( | 1563 scoped_refptr<EntryImpl> cache_entry( |
1559 new EntryImpl(this, address, read_only_)); | 1564 new EntryImpl(this, address, read_only_)); |
1560 IncreaseNumRefs(); | 1565 IncreaseNumRefs(); |
1561 *entry = NULL; | 1566 *entry = NULL; |
1562 | 1567 |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2169 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 2174 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
2170 total_memory = kMaxBuffersSize; | 2175 total_memory = kMaxBuffersSize; |
2171 | 2176 |
2172 done = true; | 2177 done = true; |
2173 } | 2178 } |
2174 | 2179 |
2175 return static_cast<int>(total_memory); | 2180 return static_cast<int>(total_memory); |
2176 } | 2181 } |
2177 | 2182 |
2178 } // namespace disk_cache | 2183 } // namespace disk_cache |
OLD | NEW |