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/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 INDEX_STATE_FRESH = 2, | 235 INDEX_STATE_FRESH = 2, |
236 INDEX_STATE_FRESH_CONCURRENT_UPDATES = 3, | 236 INDEX_STATE_FRESH_CONCURRENT_UPDATES = 3, |
237 INDEX_STATE_MAX = 4, | 237 INDEX_STATE_MAX = 4, |
238 } index_file_state; | 238 } index_file_state; |
239 | 239 |
240 // Only load if the index is not stale. | 240 // Only load if the index is not stale. |
241 if (IsIndexFileStale(cache_last_modified, index_file_path)) { | 241 if (IsIndexFileStale(cache_last_modified, index_file_path)) { |
242 index_file_state = INDEX_STATE_STALE; | 242 index_file_state = INDEX_STATE_STALE; |
243 } else { | 243 } else { |
244 index_file_state = INDEX_STATE_FRESH; | 244 index_file_state = INDEX_STATE_FRESH; |
245 base::Time latest_dir_mtime; | 245 base::PlatformFileInfo file_info; |
246 if (simple_util::GetMTime(cache_directory, &latest_dir_mtime) && | 246 bool file_info_result = file_util::GetFileInfo(index_file_path, &file_info); |
247 IsIndexFileStale(latest_dir_mtime, index_file_path)) { | 247 DCHECK(file_info_result); |
| 248 if (IsIndexFileStale(file_info.last_modified, index_file_path)) { |
248 // A file operation has updated the directory since we last looked at it | 249 // A file operation has updated the directory since we last looked at it |
249 // during backend initialization. | 250 // during backend initialization. |
250 index_file_state = INDEX_STATE_FRESH_CONCURRENT_UPDATES; | 251 index_file_state = INDEX_STATE_FRESH_CONCURRENT_UPDATES; |
251 } | 252 } |
252 | 253 |
253 const base::TimeTicks start = base::TimeTicks::Now(); | 254 const base::TimeTicks start = base::TimeTicks::Now(); |
254 SyncLoadFromDisk(index_file_path, out_result); | 255 SyncLoadFromDisk(index_file_path, out_result); |
255 UMA_HISTOGRAM_TIMES("SimpleCache.IndexLoadTime", | 256 UMA_HISTOGRAM_TIMES("SimpleCache.IndexLoadTime", |
256 base::TimeTicks::Now() - start); | 257 base::TimeTicks::Now() - start); |
257 UMA_HISTOGRAM_COUNTS("SimpleCache.IndexEntriesLoaded", | 258 UMA_HISTOGRAM_COUNTS("SimpleCache.IndexEntriesLoaded", |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 } | 412 } |
412 out_result->did_load = true; | 413 out_result->did_load = true; |
413 // When we restore from disk we write the merged index file to disk right | 414 // When we restore from disk we write the merged index file to disk right |
414 // away, this might save us from having to restore again next time. | 415 // away, this might save us from having to restore again next time. |
415 out_result->flush_required = true; | 416 out_result->flush_required = true; |
416 } | 417 } |
417 | 418 |
418 // static | 419 // static |
419 bool SimpleIndexFile::IsIndexFileStale(base::Time cache_last_modified, | 420 bool SimpleIndexFile::IsIndexFileStale(base::Time cache_last_modified, |
420 const base::FilePath& index_file_path) { | 421 const base::FilePath& index_file_path) { |
421 base::Time index_mtime; | 422 base::PlatformFileInfo file_info; |
422 if (!simple_util::GetMTime(index_file_path, &index_mtime)) | 423 if (!file_util::GetFileInfo(index_file_path, &file_info)) |
423 return true; | 424 return true; |
424 return index_mtime < cache_last_modified; | 425 return file_info.last_modified < cache_last_modified; |
425 } | 426 } |
426 | 427 |
427 } // namespace disk_cache | 428 } // namespace disk_cache |
OLD | NEW |