Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: trunk/src/net/disk_cache/simple/simple_index.cc

Issue 14824006: Revert 198820 "Move FileEnumerator to its own file, do some refa..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 5 #include "net/disk_cache/simple/simple_index.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_enumerator.h"
13 #include "base/logging.h" 12 #include "base/logging.h"
14 #include "base/message_loop.h" 13 #include "base/message_loop.h"
15 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
16 #include "base/pickle.h" 15 #include "base/pickle.h"
17 #include "base/task_runner.h" 16 #include "base/task_runner.h"
18 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
19 #include "base/threading/worker_pool.h" 18 #include "base/threading/worker_pool.h"
20 #include "base/time.h" 19 #include "base/time.h"
21 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
22 #include "net/disk_cache/simple/simple_entry_format.h" 21 #include "net/disk_cache/simple/simple_entry_format.h"
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 440
442 io_thread->PostTask(FROM_HERE, 441 io_thread->PostTask(FROM_HERE,
443 base::Bind(completion_callback, 442 base::Bind(completion_callback,
444 base::Passed(&index_file_entries), 443 base::Passed(&index_file_entries),
445 force_index_flush)); 444 force_index_flush));
446 } 445 }
447 446
448 // static 447 // static
449 scoped_ptr<SimpleIndex::EntrySet> SimpleIndex::RestoreFromDisk( 448 scoped_ptr<SimpleIndex::EntrySet> SimpleIndex::RestoreFromDisk(
450 const base::FilePath& index_filename) { 449 const base::FilePath& index_filename) {
450 using file_util::FileEnumerator;
451 LOG(INFO) << "Simple Cache Index is being restored from disk."; 451 LOG(INFO) << "Simple Cache Index is being restored from disk.";
452 452
453 file_util::Delete(index_filename, /* recursive = */ false); 453 file_util::Delete(index_filename, /* recursive = */ false);
454 scoped_ptr<EntrySet> index_file_entries(new EntrySet()); 454 scoped_ptr<EntrySet> index_file_entries(new EntrySet());
455 455
456 // TODO(felipeg,gavinp): Fix this once we have a one-file per entry format. 456 // TODO(felipeg,gavinp): Fix this once we have a one-file per entry format.
457 COMPILE_ASSERT(kSimpleEntryFileCount == 3, 457 COMPILE_ASSERT(kSimpleEntryFileCount == 3,
458 file_pattern_must_match_file_count); 458 file_pattern_must_match_file_count);
459 459
460 const int kFileSuffixLenght = std::string("_0").size(); 460 const int kFileSuffixLenght = std::string("_0").size();
461 const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*_[0-2]"); 461 const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*_[0-2]");
462 base::FileEnumerator enumerator(index_filename.DirName(), 462 FileEnumerator enumerator(index_filename.DirName(),
463 false /* recursive */, 463 false /* recursive */,
464 base::FileEnumerator::FILES, 464 FileEnumerator::FILES,
465 file_pattern); 465 file_pattern);
466 for (base::FilePath file_path = enumerator.Next(); !file_path.empty(); 466 for (base::FilePath file_path = enumerator.Next(); !file_path.empty();
467 file_path = enumerator.Next()) { 467 file_path = enumerator.Next()) {
468 const base::FilePath::StringType base_name = file_path.BaseName().value(); 468 const base::FilePath::StringType base_name = file_path.BaseName().value();
469 // Converting to std::string is OK since we never use UTF8 wide chars in our 469 // Converting to std::string is OK since we never use UTF8 wide chars in our
470 // file names. 470 // file names.
471 const std::string hash_name(base_name.begin(), base_name.end()); 471 const std::string hash_name(base_name.begin(), base_name.end());
472 const std::string hash_key_string = 472 const std::string hash_key_string =
473 hash_name.substr(0, hash_name.size() - kFileSuffixLenght); 473 hash_name.substr(0, hash_name.size() - kFileSuffixLenght);
474 uint64 hash_key = 0; 474 uint64 hash_key = 0;
475 if (!simple_util::GetEntryHashKeyFromHexString( 475 if (!simple_util::GetEntryHashKeyFromHexString(
476 hash_key_string, &hash_key)) { 476 hash_key_string, &hash_key)) {
477 LOG(WARNING) << "Invalid Entry Hash Key filename while restoring " 477 LOG(WARNING) << "Invalid Entry Hash Key filename while restoring "
478 << "Simple Index from disk: " << hash_name; 478 << "Simple Index from disk: " << hash_name;
479 // TODO(felipeg): Should we delete the invalid file here ? 479 // TODO(felipeg): Should we delete the invalid file here ?
480 continue; 480 continue;
481 } 481 }
482 482
483 base::FileEnumerator::FileInfo find_info = enumerator.GetInfo(); 483 FileEnumerator::FindInfo find_info = {};
484 enumerator.GetFindInfo(&find_info);
484 base::Time last_used_time; 485 base::Time last_used_time;
485 #if defined(OS_POSIX) 486 #if defined(OS_POSIX)
486 // For POSIX systems, a last access time is available. However, it's not 487 // For POSIX systems, a last access time is available. However, it's not
487 // guaranteed to be more accurate than mtime. It is no worse though. 488 // guaranteed to be more accurate than mtime. It is no worse though.
488 last_used_time = base::Time::FromTimeT(find_info.stat().st_atime); 489 last_used_time = base::Time::FromTimeT(find_info.stat.st_atime);
489 #endif 490 #endif
490 if (last_used_time.is_null()) 491 if (last_used_time.is_null())
491 last_used_time = find_info.GetLastModifiedTime(); 492 last_used_time = FileEnumerator::GetLastModifiedTime(find_info);
492 493
493 int64 file_size = find_info.GetSize(); 494 int64 file_size = FileEnumerator::GetFilesize(find_info);
494 EntrySet::iterator it = index_file_entries->find(hash_key); 495 EntrySet::iterator it = index_file_entries->find(hash_key);
495 if (it == index_file_entries->end()) { 496 if (it == index_file_entries->end()) {
496 InsertInEntrySet(EntryMetadata(hash_key, last_used_time, file_size), 497 InsertInEntrySet(EntryMetadata(hash_key, last_used_time, file_size),
497 index_file_entries.get()); 498 index_file_entries.get());
498 } else { 499 } else {
499 // Summing up the total size of the entry through all the *_[0-2] files 500 // Summing up the total size of the entry through all the *_[0-2] files
500 it->second.SetEntrySize(it->second.GetEntrySize() + file_size); 501 it->second.SetEntrySize(it->second.GetEntrySize() + file_size);
501 } 502 }
502 } 503 }
503 return index_file_entries.Pass(); 504 return index_file_entries.Pass();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 scoped_ptr<Pickle> pickle = SimpleIndexFile::Serialize(index_metadata, 590 scoped_ptr<Pickle> pickle = SimpleIndexFile::Serialize(index_metadata,
590 entries_set_); 591 entries_set_);
591 cache_thread_->PostTask(FROM_HERE, base::Bind( 592 cache_thread_->PostTask(FROM_HERE, base::Bind(
592 &SimpleIndex::WriteToDiskInternal, 593 &SimpleIndex::WriteToDiskInternal,
593 index_filename_, 594 index_filename_,
594 base::Passed(&pickle), 595 base::Passed(&pickle),
595 start)); 596 start));
596 } 597 }
597 598
598 } // namespace disk_cache 599 } // namespace disk_cache
OLDNEW
« no previous file with comments | « trunk/src/net/disk_cache/cache_util_posix.cc ('k') | trunk/src/net/tools/dump_cache/dump_files.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698