| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/field_trial.h" | 7 #include "base/field_trial.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 | 874 |
| 875 LogStats(); | 875 LogStats(); |
| 876 ReportError(error); | 876 ReportError(error); |
| 877 | 877 |
| 878 // Setting the index table length to an invalid value will force re-creation | 878 // Setting the index table length to an invalid value will force re-creation |
| 879 // of the cache files. | 879 // of the cache files. |
| 880 data_->header.table_len = 1; | 880 data_->header.table_len = 1; |
| 881 disabled_ = true; | 881 disabled_ = true; |
| 882 | 882 |
| 883 if (!num_refs_) | 883 if (!num_refs_) |
| 884 RestartCache(); | 884 MessageLoop::current()->PostTask(FROM_HERE, |
| 885 factory_.NewRunnableMethod(&BackendImpl::RestartCache)); |
| 885 } | 886 } |
| 886 | 887 |
| 887 void BackendImpl::ReportError(int error) { | 888 void BackendImpl::ReportError(int error) { |
| 888 // We transmit positive numbers, instead of direct error codes. | 889 // We transmit positive numbers, instead of direct error codes. |
| 889 DCHECK(error <= 0); | 890 DCHECK(error <= 0); |
| 890 CACHE_UMA(CACHE_ERROR, "Error", 0, error * -1); | 891 CACHE_UMA(CACHE_ERROR, "Error", 0, error * -1); |
| 891 } | 892 } |
| 892 | 893 |
| 893 void BackendImpl::OnEvent(Stats::Counters an_event) { | 894 void BackendImpl::OnEvent(Stats::Counters an_event) { |
| 894 stats_.OnEvent(an_event); | 895 stats_.OnEvent(an_event); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 | 1060 |
| 1060 if (!table_len) | 1061 if (!table_len) |
| 1061 return; | 1062 return; |
| 1062 | 1063 |
| 1063 // If we already have a table, adjust the size to it. | 1064 // If we already have a table, adjust the size to it. |
| 1064 int current_max_size = MaxStorageSizeForTable(table_len); | 1065 int current_max_size = MaxStorageSizeForTable(table_len); |
| 1065 if (max_size_ > current_max_size) | 1066 if (max_size_ > current_max_size) |
| 1066 max_size_= current_max_size; | 1067 max_size_= current_max_size; |
| 1067 } | 1068 } |
| 1068 | 1069 |
| 1070 // We always execute this method from the message loop so that we can freely |
| 1071 // release files, memory pointers etc. |
| 1069 void BackendImpl::RestartCache() { | 1072 void BackendImpl::RestartCache() { |
| 1073 DCHECK(!num_refs_); |
| 1074 DCHECK(!open_entries_.size()); |
| 1070 PrepareForRestart(); | 1075 PrepareForRestart(); |
| 1071 DelayedCacheCleanup(path_); | 1076 DelayedCacheCleanup(path_); |
| 1072 | 1077 |
| 1073 int64 errors = stats_.GetCounter(Stats::FATAL_ERROR); | 1078 int64 errors = stats_.GetCounter(Stats::FATAL_ERROR); |
| 1074 | 1079 |
| 1075 // Don't call Init() if directed by the unit test: we are simulating a failure | 1080 // Don't call Init() if directed by the unit test: we are simulating a failure |
| 1076 // trying to re-enable the cache. | 1081 // trying to re-enable the cache. |
| 1077 if (unit_test_) | 1082 if (unit_test_) |
| 1078 init_ = true; // Let the destructor do proper cleanup. | 1083 init_ = true; // Let the destructor do proper cleanup. |
| 1079 else if (Init()) | 1084 else if (Init()) |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 *next_entry = GetEnumeratedEntry(next.get(), false); | 1322 *next_entry = GetEnumeratedEntry(next.get(), false); |
| 1318 if (!*next_entry) | 1323 if (!*next_entry) |
| 1319 return false; | 1324 return false; |
| 1320 | 1325 |
| 1321 *from_entry = next.release(); | 1326 *from_entry = next.release(); |
| 1322 return true; | 1327 return true; |
| 1323 } | 1328 } |
| 1324 | 1329 |
| 1325 EntryImpl* BackendImpl::GetEnumeratedEntry(CacheRankingsBlock* next, | 1330 EntryImpl* BackendImpl::GetEnumeratedEntry(CacheRankingsBlock* next, |
| 1326 bool to_evict) { | 1331 bool to_evict) { |
| 1327 if (!next) | 1332 if (!next || disabled_) |
| 1328 return NULL; | 1333 return NULL; |
| 1329 | 1334 |
| 1330 EntryImpl* entry; | 1335 EntryImpl* entry; |
| 1331 bool dirty; | 1336 bool dirty; |
| 1332 if (NewEntry(Addr(next->Data()->contents), &entry, &dirty)) | 1337 if (NewEntry(Addr(next->Data()->contents), &entry, &dirty)) |
| 1333 return NULL; | 1338 return NULL; |
| 1334 | 1339 |
| 1335 if (dirty) { | 1340 if (dirty) { |
| 1336 // We cannot trust this entry. This code also releases the reference. | 1341 // We cannot trust this entry. This code also releases the reference. |
| 1337 DestroyInvalidEntryFromEnumeration(entry); | 1342 DestroyInvalidEntryFromEnumeration(entry); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 num_refs_++; | 1438 num_refs_++; |
| 1434 if (max_refs_ < num_refs_) | 1439 if (max_refs_ < num_refs_) |
| 1435 max_refs_ = num_refs_; | 1440 max_refs_ = num_refs_; |
| 1436 } | 1441 } |
| 1437 | 1442 |
| 1438 void BackendImpl::DecreaseNumRefs() { | 1443 void BackendImpl::DecreaseNumRefs() { |
| 1439 DCHECK(num_refs_); | 1444 DCHECK(num_refs_); |
| 1440 num_refs_--; | 1445 num_refs_--; |
| 1441 | 1446 |
| 1442 if (!num_refs_ && disabled_) | 1447 if (!num_refs_ && disabled_) |
| 1443 RestartCache(); | 1448 MessageLoop::current()->PostTask(FROM_HERE, |
| 1449 factory_.NewRunnableMethod(&BackendImpl::RestartCache)); |
| 1444 } | 1450 } |
| 1445 | 1451 |
| 1446 void BackendImpl::IncreaseNumEntries() { | 1452 void BackendImpl::IncreaseNumEntries() { |
| 1447 data_->header.num_entries++; | 1453 data_->header.num_entries++; |
| 1448 DCHECK(data_->header.num_entries > 0); | 1454 DCHECK(data_->header.num_entries > 0); |
| 1449 } | 1455 } |
| 1450 | 1456 |
| 1451 void BackendImpl::DecreaseNumEntries() { | 1457 void BackendImpl::DecreaseNumEntries() { |
| 1452 data_->header.num_entries--; | 1458 data_->header.num_entries--; |
| 1453 if (data_->header.num_entries < 0) { | 1459 if (data_->header.num_entries < 0) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 | 1638 |
| 1633 return num_dirty; | 1639 return num_dirty; |
| 1634 } | 1640 } |
| 1635 | 1641 |
| 1636 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { | 1642 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { |
| 1637 RankingsNode* rankings = cache_entry->rankings()->Data(); | 1643 RankingsNode* rankings = cache_entry->rankings()->Data(); |
| 1638 return !rankings->pointer; | 1644 return !rankings->pointer; |
| 1639 } | 1645 } |
| 1640 | 1646 |
| 1641 } // namespace disk_cache | 1647 } // namespace disk_cache |
| OLD | NEW |