Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 // For POSIX systems, a last access time is available. However, it's not | 153 // For POSIX systems, a last access time is available. However, it's not |
| 154 // guaranteed to be more accurate than mtime. It is no worse though. | 154 // guaranteed to be more accurate than mtime. It is no worse though. |
| 155 last_used_time = last_accessed; | 155 last_used_time = last_accessed; |
| 156 #endif | 156 #endif |
| 157 if (last_used_time.is_null()) | 157 if (last_used_time.is_null()) |
| 158 last_used_time = last_modified; | 158 last_used_time = last_modified; |
| 159 | 159 |
| 160 SimpleIndex::EntrySet::iterator it = entries->find(hash_key); | 160 SimpleIndex::EntrySet::iterator it = entries->find(hash_key); |
| 161 base::CheckedNumeric<uint32_t> total_entry_size = size; | 161 base::CheckedNumeric<uint32_t> total_entry_size = size; |
| 162 | 162 |
| 163 // When the entry size is nonsense we can't use it, since don't want to | |
| 164 // crash, but we actually do want to proceed with the entry in the index: if | |
| 165 // it's not in index, and is never accessed again, then the file will never | |
| 166 // get removed. So we just make something up; if it's unused it will get | |
|
pasko
2017/05/11 12:15:07
not really "never get removed", it will be removed
morlovich
2017/05/19 11:35:05
It would be never removed if we decided to skip ov
| |
| 167 // kicked out eventually; if it's used we will either delete the file due to | |
| 168 // file format error, or set this correctly. | |
| 169 const int kPlaceHolderSizeWhenInvalid = 32768; | |
|
pasko
2017/05/11 12:15:07
I think it's worth mentioning that the entry size
morlovich
2017/05/19 11:35:05
OK, will tweak the comment to make it more explici
Maks Orlovich
2017/05/19 13:18:06
Hmm, thinking some more, maybe we should range-che
pasko
2017/05/19 14:38:07
ah, you are right. That basically brings us back t
Maks Orlovich
2017/05/19 15:09:58
True, that would save work, but the check is proba
| |
| 170 if (!total_entry_size.IsValid()) { | |
| 171 LOG(WARNING) << "Invalid file size while restoring index from disk: " | |
| 172 << size << " on file:" << file_name; | |
| 173 } | |
| 174 | |
| 163 if (it == entries->end()) { | 175 if (it == entries->end()) { |
| 164 SimpleIndex::InsertInEntrySet( | 176 SimpleIndex::InsertInEntrySet( |
| 165 hash_key, EntryMetadata(last_used_time, total_entry_size.ValueOrDie()), | 177 hash_key, |
| 178 EntryMetadata(last_used_time, total_entry_size.ValueOrDefault( | |
| 179 kPlaceHolderSizeWhenInvalid)), | |
| 166 entries); | 180 entries); |
| 167 } else { | 181 } else { |
| 168 // Summing up the total size of the entry through all the *_[0-1] files | 182 // Summing up the total size of the entry through all the *_[0-1] files |
| 169 total_entry_size += it->second.GetEntrySize(); | 183 total_entry_size += it->second.GetEntrySize(); |
| 170 it->second.SetEntrySize(total_entry_size.ValueOrDie()); | 184 it->second.SetEntrySize( |
| 185 total_entry_size.ValueOrDefault(kPlaceHolderSizeWhenInvalid)); | |
| 171 } | 186 } |
| 172 } | 187 } |
| 173 | 188 |
| 174 } // namespace | 189 } // namespace |
| 175 | 190 |
| 176 SimpleIndexLoadResult::SimpleIndexLoadResult() | 191 SimpleIndexLoadResult::SimpleIndexLoadResult() |
| 177 : did_load(false), | 192 : did_load(false), |
| 178 index_write_reason(SimpleIndex::INDEX_WRITE_REASON_MAX), | 193 index_write_reason(SimpleIndex::INDEX_WRITE_REASON_MAX), |
| 179 flush_required(false) {} | 194 flush_required(false) {} |
| 180 | 195 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 bool SimpleIndexFile::LegacyIsIndexFileStale( | 584 bool SimpleIndexFile::LegacyIsIndexFileStale( |
| 570 base::Time cache_last_modified, | 585 base::Time cache_last_modified, |
| 571 const base::FilePath& index_file_path) { | 586 const base::FilePath& index_file_path) { |
| 572 base::Time index_mtime; | 587 base::Time index_mtime; |
| 573 if (!simple_util::GetMTime(index_file_path, &index_mtime)) | 588 if (!simple_util::GetMTime(index_file_path, &index_mtime)) |
| 574 return true; | 589 return true; |
| 575 return index_mtime < cache_last_modified; | 590 return index_mtime < cache_last_modified; |
| 576 } | 591 } |
| 577 | 592 |
| 578 } // namespace disk_cache | 593 } // namespace disk_cache |
| OLD | NEW |