Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: net/disk_cache/backend_impl.cc

Issue 155231: Disk cache: Additional code cleanup after CL 20067. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 if (!*dirty) 1096 if (!*dirty)
1097 open_entries_[address.value()] = cache_entry; 1097 open_entries_[address.value()] = cache_entry;
1098 1098
1099 cache_entry.swap(entry); 1099 cache_entry.swap(entry);
1100 return 0; 1100 return 0;
1101 } 1101 }
1102 1102
1103 EntryImpl* BackendImpl::MatchEntry(const std::string& key, uint32 hash, 1103 EntryImpl* BackendImpl::MatchEntry(const std::string& key, uint32 hash,
1104 bool find_parent) { 1104 bool find_parent) {
1105 Addr address(data_->table[hash & mask_]); 1105 Addr address(data_->table[hash & mask_]);
1106 EntryImpl* cache_entry = NULL; 1106 scoped_refptr<EntryImpl> cache_entry, parent_entry;
1107 EntryImpl* parent_entry = NULL; 1107 EntryImpl* tmp = NULL;
1108 bool found = false; 1108 bool found = false;
1109 1109
1110 for (;;) { 1110 for (;;) {
1111 if (disabled_) 1111 if (disabled_)
1112 break; 1112 break;
1113 1113
1114 if (!address.is_initialized()) { 1114 if (!address.is_initialized()) {
1115 if (find_parent) 1115 if (find_parent)
1116 found = true; 1116 found = true;
1117 break; 1117 break;
1118 } 1118 }
1119 1119
1120 bool dirty; 1120 bool dirty;
1121 int error = NewEntry(address, &cache_entry, &dirty); 1121 int error = NewEntry(address, &tmp, &dirty);
1122 cache_entry.swap(&tmp);
1122 1123
1123 if (error || dirty) { 1124 if (error || dirty) {
1124 // This entry is dirty on disk (it was not properly closed): we cannot 1125 // This entry is dirty on disk (it was not properly closed): we cannot
1125 // trust it. 1126 // trust it.
1126 Addr child(0); 1127 Addr child(0);
1127 if (!error) 1128 if (!error)
1128 child.set_value(cache_entry->GetNextAddress()); 1129 child.set_value(cache_entry->GetNextAddress());
1129 1130
1130 if (parent_entry) { 1131 if (parent_entry) {
1131 parent_entry->SetNextAddress(child); 1132 parent_entry->SetNextAddress(child);
1132 parent_entry->Release();
1133 parent_entry = NULL; 1133 parent_entry = NULL;
Nicolas Sylvain 2009/07/08 20:25:09 maybe here and below you could use .reset()?
rvargas (doing something else) 2009/07/08 20:49:44 there is no reset() for scoped_refptr
1134 } else { 1134 } else {
1135 data_->table[hash & mask_] = child.value(); 1135 data_->table[hash & mask_] = child.value();
1136 } 1136 }
1137 1137
1138 if (!error) { 1138 if (!error) {
1139 // It is important to call DestroyInvalidEntry after removing this 1139 // It is important to call DestroyInvalidEntry after removing this
1140 // entry from the table. 1140 // entry from the table.
1141 DestroyInvalidEntry(address, cache_entry); 1141 DestroyInvalidEntry(address, cache_entry);
1142 cache_entry->Release();
1143 cache_entry = NULL; 1142 cache_entry = NULL;
1144 } else { 1143 } else {
1145 Trace("NewEntry failed on MatchEntry 0x%x", address.value()); 1144 Trace("NewEntry failed on MatchEntry 0x%x", address.value());
1146 } 1145 }
1147 1146
1148 // Restart the search. 1147 // Restart the search.
1149 address.set_value(data_->table[hash & mask_]); 1148 address.set_value(data_->table[hash & mask_]);
1150 continue; 1149 continue;
1151 } 1150 }
1152 1151
1153 if (cache_entry->IsSameEntry(key, hash)) { 1152 if (cache_entry->IsSameEntry(key, hash)) {
1154 if (!cache_entry->Update()) { 1153 if (!cache_entry->Update())
1155 cache_entry->Release();
1156 cache_entry = NULL; 1154 cache_entry = NULL;
1157 }
1158 found = true; 1155 found = true;
1159 break; 1156 break;
1160 } 1157 }
1161 if (!cache_entry->Update()) { 1158 if (!cache_entry->Update())
1162 cache_entry->Release();
1163 cache_entry = NULL; 1159 cache_entry = NULL;
1164 }
1165 if (parent_entry)
1166 parent_entry->Release();
1167 parent_entry = cache_entry; 1160 parent_entry = cache_entry;
1168 cache_entry = NULL; 1161 cache_entry = NULL;
1169 if (!parent_entry) 1162 if (!parent_entry)
1170 break; 1163 break;
1171 1164
1172 address.set_value(parent_entry->GetNextAddress()); 1165 address.set_value(parent_entry->GetNextAddress());
1173 } 1166 }
1174 1167
1175 if (parent_entry && (!find_parent || !found)) { 1168 if (parent_entry && (!find_parent || !found))
1176 parent_entry->Release();
1177 parent_entry = NULL; 1169 parent_entry = NULL;
1178 }
1179 1170
1180 if (cache_entry && (find_parent || !found)) { 1171 if (cache_entry && (find_parent || !found))
1181 cache_entry->Release();
1182 cache_entry = NULL; 1172 cache_entry = NULL;
1183 }
1184 1173
1185 return find_parent ? parent_entry : cache_entry; 1174 find_parent ? parent_entry.swap(&tmp) : cache_entry.swap(&tmp);
1175 return tmp;
1186 } 1176 }
1187 1177
1188 // This is the actual implementation for OpenNextEntry and OpenPrevEntry. 1178 // This is the actual implementation for OpenNextEntry and OpenPrevEntry.
1189 bool BackendImpl::OpenFollowingEntry(bool forward, void** iter, 1179 bool BackendImpl::OpenFollowingEntry(bool forward, void** iter,
1190 Entry** next_entry) { 1180 Entry** next_entry) {
1191 if (disabled_) 1181 if (disabled_)
1192 return false; 1182 return false;
1193 1183
1194 DCHECK(iter); 1184 DCHECK(iter);
1195 DCHECK(next_entry); 1185 DCHECK(next_entry);
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 1563
1574 return num_dirty; 1564 return num_dirty;
1575 } 1565 }
1576 1566
1577 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { 1567 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) {
1578 RankingsNode* rankings = cache_entry->rankings()->Data(); 1568 RankingsNode* rankings = cache_entry->rankings()->Data();
1579 return !rankings->pointer; 1569 return !rankings->pointer;
1580 } 1570 }
1581 1571
1582 } // namespace disk_cache 1572 } // namespace disk_cache
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698