| 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 <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 10 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 11 #include "base/files/memory_mapped_file.h" | 12 #include "base/files/memory_mapped_file.h" |
| 12 #include "base/hash.h" | 13 #include "base/hash.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
| 15 #include "base/pickle.h" | 16 #include "base/pickle.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 base::Time* out_last_cache_seen_by_index, | 348 base::Time* out_last_cache_seen_by_index, |
| 348 SimpleIndexLoadResult* out_result) { | 349 SimpleIndexLoadResult* out_result) { |
| 349 out_result->Reset(); | 350 out_result->Reset(); |
| 350 | 351 |
| 351 File file(index_filename, | 352 File file(index_filename, |
| 352 File::FLAG_OPEN | File::FLAG_READ | File::FLAG_SHARE_DELETE); | 353 File::FLAG_OPEN | File::FLAG_READ | File::FLAG_SHARE_DELETE); |
| 353 if (!file.IsValid()) | 354 if (!file.IsValid()) |
| 354 return; | 355 return; |
| 355 | 356 |
| 356 base::MemoryMappedFile index_file_map; | 357 base::MemoryMappedFile index_file_map; |
| 357 if (!index_file_map.Initialize(file.Pass())) { | 358 if (!index_file_map.Initialize(std::move(file))) { |
| 358 simple_util::SimpleCacheDeleteFile(index_filename); | 359 simple_util::SimpleCacheDeleteFile(index_filename); |
| 359 return; | 360 return; |
| 360 } | 361 } |
| 361 | 362 |
| 362 SimpleIndexFile::Deserialize( | 363 SimpleIndexFile::Deserialize( |
| 363 reinterpret_cast<const char*>(index_file_map.data()), | 364 reinterpret_cast<const char*>(index_file_map.data()), |
| 364 index_file_map.length(), | 365 index_file_map.length(), |
| 365 out_last_cache_seen_by_index, | 366 out_last_cache_seen_by_index, |
| 366 out_result); | 367 out_result); |
| 367 | 368 |
| 368 if (!out_result->did_load) | 369 if (!out_result->did_load) |
| 369 simple_util::SimpleCacheDeleteFile(index_filename); | 370 simple_util::SimpleCacheDeleteFile(index_filename); |
| 370 } | 371 } |
| 371 | 372 |
| 372 // static | 373 // static |
| 373 scoped_ptr<base::Pickle> SimpleIndexFile::Serialize( | 374 scoped_ptr<base::Pickle> SimpleIndexFile::Serialize( |
| 374 const SimpleIndexFile::IndexMetadata& index_metadata, | 375 const SimpleIndexFile::IndexMetadata& index_metadata, |
| 375 const SimpleIndex::EntrySet& entries) { | 376 const SimpleIndex::EntrySet& entries) { |
| 376 scoped_ptr<base::Pickle> pickle( | 377 scoped_ptr<base::Pickle> pickle( |
| 377 new base::Pickle(sizeof(SimpleIndexFile::PickleHeader))); | 378 new base::Pickle(sizeof(SimpleIndexFile::PickleHeader))); |
| 378 | 379 |
| 379 index_metadata.Serialize(pickle.get()); | 380 index_metadata.Serialize(pickle.get()); |
| 380 for (SimpleIndex::EntrySet::const_iterator it = entries.begin(); | 381 for (SimpleIndex::EntrySet::const_iterator it = entries.begin(); |
| 381 it != entries.end(); ++it) { | 382 it != entries.end(); ++it) { |
| 382 pickle->WriteUInt64(it->first); | 383 pickle->WriteUInt64(it->first); |
| 383 it->second.Serialize(pickle.get()); | 384 it->second.Serialize(pickle.get()); |
| 384 } | 385 } |
| 385 return pickle.Pass(); | 386 return pickle; |
| 386 } | 387 } |
| 387 | 388 |
| 388 // static | 389 // static |
| 389 void SimpleIndexFile::Deserialize(const char* data, int data_len, | 390 void SimpleIndexFile::Deserialize(const char* data, int data_len, |
| 390 base::Time* out_cache_last_modified, | 391 base::Time* out_cache_last_modified, |
| 391 SimpleIndexLoadResult* out_result) { | 392 SimpleIndexLoadResult* out_result) { |
| 392 DCHECK(data); | 393 DCHECK(data); |
| 393 | 394 |
| 394 out_result->Reset(); | 395 out_result->Reset(); |
| 395 SimpleIndex::EntrySet* entries = &out_result->entries; | 396 SimpleIndex::EntrySet* entries = &out_result->entries; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 bool SimpleIndexFile::LegacyIsIndexFileStale( | 476 bool SimpleIndexFile::LegacyIsIndexFileStale( |
| 476 base::Time cache_last_modified, | 477 base::Time cache_last_modified, |
| 477 const base::FilePath& index_file_path) { | 478 const base::FilePath& index_file_path) { |
| 478 base::Time index_mtime; | 479 base::Time index_mtime; |
| 479 if (!simple_util::GetMTime(index_file_path, &index_mtime)) | 480 if (!simple_util::GetMTime(index_file_path, &index_mtime)) |
| 480 return true; | 481 return true; |
| 481 return index_mtime < cache_last_modified; | 482 return index_mtime < cache_last_modified; |
| 482 } | 483 } |
| 483 | 484 |
| 484 } // namespace disk_cache | 485 } // namespace disk_cache |
| OLD | NEW |