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/bind_helpers.h> | |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
11 #include "base/hash.h" | 12 #include "base/hash.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
14 #include "base/pickle.h" | 15 #include "base/pickle.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
17 #include "net/disk_cache/simple/simple_entry_format.h" | 18 #include "net/disk_cache/simple/simple_entry_format.h" |
18 #include "net/disk_cache/simple/simple_index.h" | 19 #include "net/disk_cache/simple/simple_index.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 // Index file last_modified must be equal to the directory last_modified since | 169 // Index file last_modified must be equal to the directory last_modified since |
169 // the last operation we do is ReplaceFile in the | 170 // the last operation we do is ReplaceFile in the |
170 // SimpleIndexFile::WriteToDisk(). | 171 // SimpleIndexFile::WriteToDisk(). |
171 // If not true, we need to restore the index. | 172 // If not true, we need to restore the index. |
172 return index_mtime < dir_mtime; | 173 return index_mtime < dir_mtime; |
173 } | 174 } |
174 | 175 |
175 // static | 176 // static |
176 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::LoadFromDisk( | 177 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::LoadFromDisk( |
177 const base::FilePath& index_filename) { | 178 const base::FilePath& index_filename) { |
179 base::ScopedClosureRunner | |
180 scoped_index_deleter(base::Bind(base::IgnoreResult(&file_util::Delete), | |
181 index_filename, false)); | |
182 | |
178 std::string contents; | 183 std::string contents; |
179 if (!file_util::ReadFileToString(index_filename, &contents)) { | 184 if (!file_util::ReadFileToString(index_filename, &contents)) { |
180 LOG(WARNING) << "Could not read Simple Index file."; | 185 LOG(WARNING) << "Could not read Simple Index file."; |
181 return scoped_ptr<SimpleIndex::EntrySet>(); | 186 return scoped_ptr<SimpleIndex::EntrySet>(); |
182 } | 187 } |
183 | 188 |
184 return SimpleIndexFile::Deserialize(contents.data(), contents.size()); | 189 scoped_ptr<SimpleIndex::EntrySet> entries = |
190 SimpleIndexFile::Deserialize(contents.data(), contents.size()); | |
191 if (!entries) | |
192 return scoped_ptr<SimpleIndex::EntrySet>(); | |
193 | |
194 scoped_index_deleter.Release(); | |
pasko
2013/06/20 13:52:22
I don't like using automatic closure runner in thi
gavinp
2013/06/20 20:18:18
Done. I was only trying to show off that I knew ab
| |
195 return entries.Pass(); | |
185 } | 196 } |
186 | 197 |
187 // static | 198 // static |
188 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::Deserialize(const char* data, | 199 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::Deserialize(const char* data, |
189 int data_len) { | 200 int data_len) { |
190 DCHECK(data); | 201 DCHECK(data); |
191 Pickle pickle(data, data_len); | 202 Pickle pickle(data, data_len); |
192 if (!pickle.data()) { | 203 if (!pickle.data()) { |
193 LOG(WARNING) << "Corrupt Simple Index File."; | 204 LOG(WARNING) << "Corrupt Simple Index File."; |
194 return scoped_ptr<SimpleIndex::EntrySet>(); | 205 return scoped_ptr<SimpleIndex::EntrySet>(); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 index_file_entries.get()); | 383 index_file_entries.get()); |
373 } else { | 384 } else { |
374 // Summing up the total size of the entry through all the *_[0-2] files | 385 // Summing up the total size of the entry through all the *_[0-2] files |
375 it->second.SetEntrySize(it->second.GetEntrySize() + file_size); | 386 it->second.SetEntrySize(it->second.GetEntrySize() + file_size); |
376 } | 387 } |
377 } | 388 } |
378 return index_file_entries.Pass(); | 389 return index_file_entries.Pass(); |
379 } | 390 } |
380 | 391 |
381 } // namespace disk_cache | 392 } // namespace disk_cache |
OLD | NEW |