| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/histogram.h" | 8 #include "base/histogram.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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 } | 839 } |
| 840 | 840 |
| 841 void BackendImpl::PrepareForRestart() { | 841 void BackendImpl::PrepareForRestart() { |
| 842 data_->header.crash = 0; | 842 data_->header.crash = 0; |
| 843 index_ = NULL; | 843 index_ = NULL; |
| 844 data_ = NULL; | 844 data_ = NULL; |
| 845 block_files_.CloseFiles(); | 845 block_files_.CloseFiles(); |
| 846 rankings_.Reset(); | 846 rankings_.Reset(); |
| 847 init_ = false; | 847 init_ = false; |
| 848 restarted_ = true; | 848 restarted_ = true; |
| 849 |
| 850 // TODO(rvargas): remove this line at the end of this experiment. |
| 851 max_size_ = 0; |
| 849 } | 852 } |
| 850 | 853 |
| 851 int BackendImpl::NewEntry(Addr address, EntryImpl** entry, bool* dirty) { | 854 int BackendImpl::NewEntry(Addr address, EntryImpl** entry, bool* dirty) { |
| 852 scoped_refptr<EntryImpl> cache_entry(new EntryImpl(this, address)); | 855 scoped_refptr<EntryImpl> cache_entry(new EntryImpl(this, address)); |
| 853 IncreaseNumRefs(); | 856 IncreaseNumRefs(); |
| 854 *entry = NULL; | 857 *entry = NULL; |
| 855 | 858 |
| 856 if (!address.is_initialized() || address.is_separate_file() || | 859 if (!address.is_initialized() || address.is_separate_file() || |
| 857 address.file_type() != BLOCK_256) { | 860 address.file_type() != BLOCK_256) { |
| 858 LOG(WARNING) << "Wrong entry address."; | 861 LOG(WARNING) << "Wrong entry address."; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 return false; | 1089 return false; |
| 1087 } | 1090 } |
| 1088 | 1091 |
| 1089 if (current_size < GetIndexSize(data_->header.table_len) || | 1092 if (current_size < GetIndexSize(data_->header.table_len) || |
| 1090 data_->header.table_len & (kBaseTableLen - 1)) { | 1093 data_->header.table_len & (kBaseTableLen - 1)) { |
| 1091 LOG(ERROR) << "Corrupt Index file"; | 1094 LOG(ERROR) << "Corrupt Index file"; |
| 1092 return false; | 1095 return false; |
| 1093 } | 1096 } |
| 1094 | 1097 |
| 1095 AdjustMaxCacheSize(data_->header.table_len); | 1098 AdjustMaxCacheSize(data_->header.table_len); |
| 1096 | 1099 |
| 1097 // We need to avoid integer overflows. | 1100 // We need to avoid integer overflows. |
| 1098 DCHECK(max_size_ < kint32max - kint32max / 10); | 1101 DCHECK(max_size_ < kint32max - kint32max / 10); |
| 1099 if (data_->header.num_bytes < 0 || | 1102 if (data_->header.num_bytes < 0 || |
| 1100 data_->header.num_bytes > max_size_ + max_size_ / 10) { | 1103 data_->header.num_bytes > max_size_ + max_size_ / 10) { |
| 1101 LOG(ERROR) << "Invalid cache (current) size"; | 1104 LOG(ERROR) << "Invalid cache (current) size"; |
| 1102 return false; | 1105 return false; |
| 1103 } | 1106 } |
| 1104 | 1107 |
| 1105 if (data_->header.num_entries < 0) { | 1108 if (data_->header.num_entries < 0) { |
| 1106 LOG(ERROR) << "Invalid number of entries"; | 1109 LOG(ERROR) << "Invalid number of entries"; |
| 1107 return false; | 1110 return false; |
| 1108 } | 1111 } |
| 1109 | 1112 |
| 1110 if (!mask_) | 1113 if (!mask_) |
| 1111 mask_ = data_->header.table_len - 1; | 1114 mask_ = data_->header.table_len - 1; |
| 1112 | 1115 |
| 1116 // TODO(rvargas): remove this. For some reason, we are receiving crashes with |
| 1117 // mask_ being bigger than the actual table length. (bug 7217). |
| 1118 if (mask_ > 0xffff) { |
| 1119 LOG(ERROR) << "Invalid cache mask"; |
| 1120 ReportError(ERR_INVALID_MASK); |
| 1121 return false; |
| 1122 } |
| 1123 |
| 1113 return true; | 1124 return true; |
| 1114 } | 1125 } |
| 1115 | 1126 |
| 1116 int BackendImpl::CheckAllEntries() { | 1127 int BackendImpl::CheckAllEntries() { |
| 1117 int num_dirty = 0; | 1128 int num_dirty = 0; |
| 1118 int num_entries = 0; | 1129 int num_entries = 0; |
| 1119 DCHECK(mask_ < kuint32max); | 1130 DCHECK(mask_ < kuint32max); |
| 1120 for (int i = 0; i <= static_cast<int>(mask_); i++) { | 1131 for (int i = 0; i <= static_cast<int>(mask_); i++) { |
| 1121 Addr address(data_->table[i]); | 1132 Addr address(data_->table[i]); |
| 1122 if (!address.is_initialized()) | 1133 if (!address.is_initialized()) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1150 | 1161 |
| 1151 return num_dirty; | 1162 return num_dirty; |
| 1152 } | 1163 } |
| 1153 | 1164 |
| 1154 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { | 1165 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { |
| 1155 RankingsNode* rankings = cache_entry->rankings()->Data(); | 1166 RankingsNode* rankings = cache_entry->rankings()->Data(); |
| 1156 return !rankings->pointer; | 1167 return !rankings->pointer; |
| 1157 } | 1168 } |
| 1158 | 1169 |
| 1159 } // namespace disk_cache | 1170 } // namespace disk_cache |
| OLD | NEW |