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

Side by Side Diff: net/disk_cache/simple/simple_index_file.cc

Issue 16392011: Move FileEnumerator to its own file, do some refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix incorrect includes Created 7 years, 6 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
« no previous file with comments | « net/disk_cache/simple/simple_index.cc ('k') | net/tools/dump_cache/dump_files.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_file.h" 5 #include "net/disk_cache/simple/simple_index_file.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_enumerator.h"
8 #include "base/hash.h" 9 #include "base/hash.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
11 #include "base/pickle.h" 12 #include "base/pickle.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_restrictions.h" 14 #include "base/threading/thread_restrictions.h"
14 #include "base/threading/worker_pool.h" 15 #include "base/threading/worker_pool.h"
15 #include "net/disk_cache/simple/simple_entry_format.h" 16 #include "net/disk_cache/simple/simple_entry_format.h"
16 #include "net/disk_cache/simple/simple_index.h" 17 #include "net/disk_cache/simple/simple_index.h"
17 #include "net/disk_cache/simple/simple_synchronous_entry.h" 18 #include "net/disk_cache/simple/simple_synchronous_entry.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 initialize_method, INITIALIZE_METHOD_MAX); 309 initialize_method, INITIALIZE_METHOD_MAX);
309 response_thread->PostTask(FROM_HERE, 310 response_thread->PostTask(FROM_HERE,
310 base::Bind(completion_callback, 311 base::Bind(completion_callback,
311 base::Passed(&index_file_entries), 312 base::Passed(&index_file_entries),
312 force_index_flush)); 313 force_index_flush));
313 } 314 }
314 315
315 // static 316 // static
316 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::RestoreFromDisk( 317 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::RestoreFromDisk(
317 const base::FilePath& index_file_path) { 318 const base::FilePath& index_file_path) {
318 using file_util::FileEnumerator;
319 LOG(INFO) << "Simple Cache Index is being restored from disk."; 319 LOG(INFO) << "Simple Cache Index is being restored from disk.";
320 320
321 file_util::Delete(index_file_path, /* recursive = */ false); 321 file_util::Delete(index_file_path, /* recursive = */ false);
322 scoped_ptr<SimpleIndex::EntrySet> index_file_entries( 322 scoped_ptr<SimpleIndex::EntrySet> index_file_entries(
323 new SimpleIndex::EntrySet()); 323 new SimpleIndex::EntrySet());
324 324
325 // TODO(felipeg,gavinp): Fix this once we have a one-file per entry format. 325 // TODO(felipeg,gavinp): Fix this once we have a one-file per entry format.
326 COMPILE_ASSERT(kSimpleEntryFileCount == 3, 326 COMPILE_ASSERT(kSimpleEntryFileCount == 3,
327 file_pattern_must_match_file_count); 327 file_pattern_must_match_file_count);
328 328
329 const int kFileSuffixLength = sizeof("_0") - 1; 329 const int kFileSuffixLength = sizeof("_0") - 1;
330 const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*_[0-2]"); 330 const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*_[0-2]");
331 FileEnumerator enumerator(index_file_path.DirName(), 331 base::FileEnumerator enumerator(index_file_path.DirName(),
332 false /* recursive */, 332 false /* recursive */,
333 FileEnumerator::FILES, 333 base::FileEnumerator::FILES,
334 file_pattern); 334 file_pattern);
335 for (base::FilePath file_path = enumerator.Next(); !file_path.empty(); 335 for (base::FilePath file_path = enumerator.Next(); !file_path.empty();
336 file_path = enumerator.Next()) { 336 file_path = enumerator.Next()) {
337 const base::FilePath::StringType base_name = file_path.BaseName().value(); 337 const base::FilePath::StringType base_name = file_path.BaseName().value();
338 // Converting to std::string is OK since we never use UTF8 wide chars in our 338 // Converting to std::string is OK since we never use UTF8 wide chars in our
339 // file names. 339 // file names.
340 const std::string hash_key_string(base_name.begin(), 340 const std::string hash_key_string(base_name.begin(),
341 base_name.end() - kFileSuffixLength); 341 base_name.end() - kFileSuffixLength);
342 uint64 hash_key = 0; 342 uint64 hash_key = 0;
343 if (!simple_util::GetEntryHashKeyFromHexString( 343 if (!simple_util::GetEntryHashKeyFromHexString(
344 hash_key_string, &hash_key)) { 344 hash_key_string, &hash_key)) {
345 LOG(WARNING) << "Invalid Entry Hash Key filename while restoring " 345 LOG(WARNING) << "Invalid Entry Hash Key filename while restoring "
346 << "Simple Index from disk: " << base_name; 346 << "Simple Index from disk: " << base_name;
347 // TODO(felipeg): Should we delete the invalid file here ? 347 // TODO(felipeg): Should we delete the invalid file here ?
348 continue; 348 continue;
349 } 349 }
350 350
351 FileEnumerator::FindInfo find_info = {}; 351 base::FileEnumerator::FileInfo info = enumerator.GetInfo();
352 enumerator.GetFindInfo(&find_info);
353 base::Time last_used_time; 352 base::Time last_used_time;
354 #if defined(OS_POSIX) 353 #if defined(OS_POSIX)
355 // For POSIX systems, a last access time is available. However, it's not 354 // For POSIX systems, a last access time is available. However, it's not
356 // guaranteed to be more accurate than mtime. It is no worse though. 355 // guaranteed to be more accurate than mtime. It is no worse though.
357 last_used_time = base::Time::FromTimeT(find_info.stat.st_atime); 356 last_used_time = base::Time::FromTimeT(info.stat().st_atime);
358 #endif 357 #endif
359 if (last_used_time.is_null()) 358 if (last_used_time.is_null())
360 last_used_time = FileEnumerator::GetLastModifiedTime(find_info); 359 last_used_time = info.GetLastModifiedTime();
361 360
362 int64 file_size = FileEnumerator::GetFilesize(find_info); 361 int64 file_size = info.GetSize();
363 SimpleIndex::EntrySet::iterator it = index_file_entries->find(hash_key); 362 SimpleIndex::EntrySet::iterator it = index_file_entries->find(hash_key);
364 if (it == index_file_entries->end()) { 363 if (it == index_file_entries->end()) {
365 SimpleIndex::InsertInEntrySet( 364 SimpleIndex::InsertInEntrySet(
366 hash_key, 365 hash_key,
367 EntryMetadata(last_used_time, file_size), 366 EntryMetadata(last_used_time, file_size),
368 index_file_entries.get()); 367 index_file_entries.get());
369 } else { 368 } else {
370 // Summing up the total size of the entry through all the *_[0-2] files 369 // Summing up the total size of the entry through all the *_[0-2] files
371 it->second.SetEntrySize(it->second.GetEntrySize() + file_size); 370 it->second.SetEntrySize(it->second.GetEntrySize() + file_size);
372 } 371 }
373 } 372 }
374 return index_file_entries.Pass(); 373 return index_file_entries.Pass();
375 } 374 }
376 375
377 } // namespace disk_cache 376 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_index.cc ('k') | net/tools/dump_cache/dump_files.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698