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

Side by Side Diff: net/disk_cache/simple/simple_index_file.cc

Issue 16434016: Rewrite scoped_ptr<T>(NULL) to use the default ctor in net/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | « net/base/sdch_filter.cc ('k') | net/dns/dns_session.cc » ('j') | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/simple/simple_index_file.h" 5 #include "net/disk_cache/simple/simple_index_file.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // If not true, we need to restore the index. 166 // If not true, we need to restore the index.
167 return index_mtime < dir_mtime; 167 return index_mtime < dir_mtime;
168 } 168 }
169 169
170 // static 170 // static
171 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::LoadFromDisk( 171 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::LoadFromDisk(
172 const base::FilePath& index_filename) { 172 const base::FilePath& index_filename) {
173 std::string contents; 173 std::string contents;
174 if(!file_util::ReadFileToString(index_filename, &contents)) { 174 if(!file_util::ReadFileToString(index_filename, &contents)) {
175 LOG(WARNING) << "Could not read Simple Index file."; 175 LOG(WARNING) << "Could not read Simple Index file.";
176 return scoped_ptr<SimpleIndex::EntrySet>(NULL); 176 return scoped_ptr<SimpleIndex::EntrySet>();
177 } 177 }
178 178
179 return SimpleIndexFile::Deserialize(contents.data(), contents.size()); 179 return SimpleIndexFile::Deserialize(contents.data(), contents.size());
180 } 180 }
181 181
182 // static 182 // static
183 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::Deserialize(const char* data, 183 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::Deserialize(const char* data,
184 int data_len) { 184 int data_len) {
185 DCHECK(data); 185 DCHECK(data);
186 Pickle pickle(data, data_len); 186 Pickle pickle(data, data_len);
187 if (!pickle.data()) { 187 if (!pickle.data()) {
188 LOG(WARNING) << "Corrupt Simple Index File."; 188 LOG(WARNING) << "Corrupt Simple Index File.";
189 return scoped_ptr<SimpleIndex::EntrySet>(NULL); 189 return scoped_ptr<SimpleIndex::EntrySet>();
190 } 190 }
191 191
192 PickleIterator pickle_it(pickle); 192 PickleIterator pickle_it(pickle);
193 193
194 SimpleIndexFile::PickleHeader* header_p = 194 SimpleIndexFile::PickleHeader* header_p =
195 pickle.headerT<SimpleIndexFile::PickleHeader>(); 195 pickle.headerT<SimpleIndexFile::PickleHeader>();
196 const uint32 crc_read = header_p->crc; 196 const uint32 crc_read = header_p->crc;
197 const uint32 crc_calculated = CalculatePickleCRC(pickle); 197 const uint32 crc_calculated = CalculatePickleCRC(pickle);
198 198
199 if (crc_read != crc_calculated) { 199 if (crc_read != crc_calculated) {
200 LOG(WARNING) << "Invalid CRC in Simple Index file."; 200 LOG(WARNING) << "Invalid CRC in Simple Index file.";
201 return scoped_ptr<SimpleIndex::EntrySet>(NULL); 201 return scoped_ptr<SimpleIndex::EntrySet>();
202 } 202 }
203 203
204 SimpleIndexFile::IndexMetadata index_metadata; 204 SimpleIndexFile::IndexMetadata index_metadata;
205 if (!index_metadata.Deserialize(&pickle_it)) { 205 if (!index_metadata.Deserialize(&pickle_it)) {
206 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index."; 206 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index.";
207 return scoped_ptr<SimpleIndex::EntrySet>(NULL); 207 return scoped_ptr<SimpleIndex::EntrySet>();
208 } 208 }
209 209
210 if (!index_metadata.CheckIndexMetadata()) { 210 if (!index_metadata.CheckIndexMetadata()) {
211 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index."; 211 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index.";
212 return scoped_ptr<SimpleIndex::EntrySet>(NULL); 212 return scoped_ptr<SimpleIndex::EntrySet>();
213 } 213 }
214 214
215 scoped_ptr<SimpleIndex::EntrySet> index_file_entries( 215 scoped_ptr<SimpleIndex::EntrySet> index_file_entries(
216 new SimpleIndex::EntrySet()); 216 new SimpleIndex::EntrySet());
217 while (index_file_entries->size() < index_metadata.GetNumberOfEntries()) { 217 while (index_file_entries->size() < index_metadata.GetNumberOfEntries()) {
218 uint64 hash_key; 218 uint64 hash_key;
219 EntryMetadata entry_metadata; 219 EntryMetadata entry_metadata;
220 if (!pickle_it.ReadUInt64(&hash_key) || 220 if (!pickle_it.ReadUInt64(&hash_key) ||
221 !entry_metadata.Deserialize(&pickle_it)) { 221 !entry_metadata.Deserialize(&pickle_it)) {
222 LOG(WARNING) << "Invalid EntryMetadata in Simple Index file."; 222 LOG(WARNING) << "Invalid EntryMetadata in Simple Index file.";
223 return scoped_ptr<SimpleIndex::EntrySet>(NULL); 223 return scoped_ptr<SimpleIndex::EntrySet>();
224 } 224 }
225 SimpleIndex::InsertInEntrySet( 225 SimpleIndex::InsertInEntrySet(
226 hash_key, entry_metadata, index_file_entries.get()); 226 hash_key, entry_metadata, index_file_entries.get());
227 } 227 }
228 228
229 return index_file_entries.Pass(); 229 return index_file_entries.Pass();
230 } 230 }
231 231
232 // static 232 // static
233 scoped_ptr<Pickle> SimpleIndexFile::Serialize( 233 scoped_ptr<Pickle> SimpleIndexFile::Serialize(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 index_file_entries.get()); 367 index_file_entries.get());
368 } else { 368 } else {
369 // Summing up the total size of the entry through all the *_[0-2] files 369 // Summing up the total size of the entry through all the *_[0-2] files
370 it->second.SetEntrySize(it->second.GetEntrySize() + file_size); 370 it->second.SetEntrySize(it->second.GetEntrySize() + file_size);
371 } 371 }
372 } 372 }
373 return index_file_entries.Pass(); 373 return index_file_entries.Pass();
374 } 374 }
375 375
376 } // namespace disk_cache 376 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/base/sdch_filter.cc ('k') | net/dns/dns_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698