OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Performs basic inspection of the disk cache files with minimal disruption | 5 // Performs basic inspection of the disk cache files with minimal disruption |
6 // to the actual files (they still may change if an error is detected on the | 6 // to the actual files (they still may change if an error is detected on the |
7 // files). | 7 // files). |
8 | 8 |
9 #include "net/tools/dump_cache/dump_files.h" | 9 #include "net/tools/dump_cache/dump_files.h" |
10 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 | 12 |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/files/file_enumerator.h" | |
18 #include "base/format_macros.h" | 17 #include "base/format_macros.h" |
19 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
20 #include "net/base/file_stream.h" | 19 #include "net/base/file_stream.h" |
21 #include "net/disk_cache/block_files.h" | 20 #include "net/disk_cache/block_files.h" |
22 #include "net/disk_cache/disk_format.h" | 21 #include "net/disk_cache/disk_format.h" |
23 #include "net/disk_cache/mapped_file.h" | 22 #include "net/disk_cache/mapped_file.h" |
24 #include "net/disk_cache/stats.h" | 23 #include "net/disk_cache/stats.h" |
25 #include "net/disk_cache/storage_block.h" | 24 #include "net/disk_cache/storage_block.h" |
26 #include "net/disk_cache/storage_block-inl.h" | 25 #include "net/disk_cache/storage_block-inl.h" |
27 | 26 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 332 |
334 return version; | 333 return version; |
335 } | 334 } |
336 | 335 |
337 // Dumps the headers of all files. | 336 // Dumps the headers of all files. |
338 int DumpHeaders(const base::FilePath& input_path) { | 337 int DumpHeaders(const base::FilePath& input_path) { |
339 base::FilePath index_name(input_path.Append(kIndexName)); | 338 base::FilePath index_name(input_path.Append(kIndexName)); |
340 disk_cache::CacheAddr stats_addr = 0; | 339 disk_cache::CacheAddr stats_addr = 0; |
341 DumpIndexHeader(index_name, &stats_addr); | 340 DumpIndexHeader(index_name, &stats_addr); |
342 | 341 |
343 base::FileEnumerator iter(input_path, false, | 342 file_util::FileEnumerator iter(input_path, false, |
344 base::FileEnumerator::FILES, | 343 file_util::FileEnumerator::FILES, |
345 FILE_PATH_LITERAL("data_*")); | 344 FILE_PATH_LITERAL("data_*")); |
346 for (base::FilePath file = iter.Next(); !file.empty(); file = iter.Next()) | 345 for (base::FilePath file = iter.Next(); !file.empty(); file = iter.Next()) |
347 DumpBlockHeader(file); | 346 DumpBlockHeader(file); |
348 | 347 |
349 DumpStats(input_path, stats_addr); | 348 DumpStats(input_path, stats_addr); |
350 return 0; | 349 return 0; |
351 } | 350 } |
352 | 351 |
353 // Dumps all entries from the cache. | 352 // Dumps all entries from the cache. |
354 int DumpContents(const base::FilePath& input_path) { | 353 int DumpContents(const base::FilePath& input_path) { |
355 DumpHeaders(input_path); | 354 DumpHeaders(input_path); |
356 | 355 |
357 // We need a message loop, although we really don't run any task. | 356 // We need a message loop, although we really don't run any task. |
358 MessageLoop loop(MessageLoop::TYPE_IO); | 357 MessageLoop loop(MessageLoop::TYPE_IO); |
359 CacheDumper dumper(input_path); | 358 CacheDumper dumper(input_path); |
360 if (!dumper.Init()) | 359 if (!dumper.Init()) |
361 return -1; | 360 return -1; |
362 | 361 |
363 disk_cache::EntryStore entry; | 362 disk_cache::EntryStore entry; |
364 while (dumper.GetEntry(&entry)) { | 363 while (dumper.GetEntry(&entry)) { |
365 DumpEntry(entry); | 364 DumpEntry(entry); |
366 disk_cache::RankingsNode rankings; | 365 disk_cache::RankingsNode rankings; |
367 if (dumper.LoadRankings(entry.rankings_node, &rankings)) | 366 if (dumper.LoadRankings(entry.rankings_node, &rankings)) |
368 DumpRankings(rankings); | 367 DumpRankings(rankings); |
369 } | 368 } |
370 | 369 |
371 printf("Done.\n"); | 370 printf("Done.\n"); |
372 | 371 |
373 return 0; | 372 return 0; |
374 } | 373 } |
OLD | NEW |