OLD | NEW |
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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // If not true, we need to restore the index. | 171 // If not true, we need to restore the index. |
172 return index_mtime < dir_mtime; | 172 return index_mtime < dir_mtime; |
173 } | 173 } |
174 | 174 |
175 // static | 175 // static |
176 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::LoadFromDisk( | 176 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::LoadFromDisk( |
177 const base::FilePath& index_filename) { | 177 const base::FilePath& index_filename) { |
178 std::string contents; | 178 std::string contents; |
179 if (!file_util::ReadFileToString(index_filename, &contents)) { | 179 if (!file_util::ReadFileToString(index_filename, &contents)) { |
180 LOG(WARNING) << "Could not read Simple Index file."; | 180 LOG(WARNING) << "Could not read Simple Index file."; |
| 181 file_util::Delete(index_filename, false); |
181 return scoped_ptr<SimpleIndex::EntrySet>(); | 182 return scoped_ptr<SimpleIndex::EntrySet>(); |
182 } | 183 } |
183 | 184 |
184 return SimpleIndexFile::Deserialize(contents.data(), contents.size()); | 185 scoped_ptr<SimpleIndex::EntrySet> entries = |
| 186 SimpleIndexFile::Deserialize(contents.data(), contents.size()); |
| 187 if (!entries) { |
| 188 file_util::Delete(index_filename, false); |
| 189 return scoped_ptr<SimpleIndex::EntrySet>(); |
| 190 } |
| 191 |
| 192 return entries.Pass(); |
185 } | 193 } |
186 | 194 |
187 // static | 195 // static |
188 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::Deserialize(const char* data, | 196 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::Deserialize(const char* data, |
189 int data_len) { | 197 int data_len) { |
190 DCHECK(data); | 198 DCHECK(data); |
191 Pickle pickle(data, data_len); | 199 Pickle pickle(data, data_len); |
192 if (!pickle.data()) { | 200 if (!pickle.data()) { |
193 LOG(WARNING) << "Corrupt Simple Index File."; | 201 LOG(WARNING) << "Corrupt Simple Index File."; |
194 return scoped_ptr<SimpleIndex::EntrySet>(); | 202 return scoped_ptr<SimpleIndex::EntrySet>(); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 index_file_entries.get()); | 380 index_file_entries.get()); |
373 } else { | 381 } else { |
374 // Summing up the total size of the entry through all the *_[0-2] files | 382 // Summing up the total size of the entry through all the *_[0-2] files |
375 it->second.SetEntrySize(it->second.GetEntrySize() + file_size); | 383 it->second.SetEntrySize(it->second.GetEntrySize() + file_size); |
376 } | 384 } |
377 } | 385 } |
378 return index_file_entries.Pass(); | 386 return index_file_entries.Pass(); |
379 } | 387 } |
380 | 388 |
381 } // namespace disk_cache | 389 } // namespace disk_cache |
OLD | NEW |