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" |
17 #include "base/format_macros.h" | 18 #include "base/format_macros.h" |
18 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
19 #include "net/base/file_stream.h" | 20 #include "net/base/file_stream.h" |
20 #include "net/disk_cache/block_files.h" | 21 #include "net/disk_cache/block_files.h" |
21 #include "net/disk_cache/disk_format.h" | 22 #include "net/disk_cache/disk_format.h" |
22 #include "net/disk_cache/mapped_file.h" | 23 #include "net/disk_cache/mapped_file.h" |
23 #include "net/disk_cache/stats.h" | 24 #include "net/disk_cache/stats.h" |
24 #include "net/disk_cache/storage_block.h" | 25 #include "net/disk_cache/storage_block.h" |
25 #include "net/disk_cache/storage_block-inl.h" | 26 #include "net/disk_cache/storage_block-inl.h" |
26 | 27 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 333 |
333 return version; | 334 return version; |
334 } | 335 } |
335 | 336 |
336 // Dumps the headers of all files. | 337 // Dumps the headers of all files. |
337 int DumpHeaders(const base::FilePath& input_path) { | 338 int DumpHeaders(const base::FilePath& input_path) { |
338 base::FilePath index_name(input_path.Append(kIndexName)); | 339 base::FilePath index_name(input_path.Append(kIndexName)); |
339 disk_cache::CacheAddr stats_addr = 0; | 340 disk_cache::CacheAddr stats_addr = 0; |
340 DumpIndexHeader(index_name, &stats_addr); | 341 DumpIndexHeader(index_name, &stats_addr); |
341 | 342 |
342 file_util::FileEnumerator iter(input_path, false, | 343 base::FileEnumerator iter(input_path, false, |
343 file_util::FileEnumerator::FILES, | 344 base::FileEnumerator::FILES, |
344 FILE_PATH_LITERAL("data_*")); | 345 FILE_PATH_LITERAL("data_*")); |
345 for (base::FilePath file = iter.Next(); !file.empty(); file = iter.Next()) | 346 for (base::FilePath file = iter.Next(); !file.empty(); file = iter.Next()) |
346 DumpBlockHeader(file); | 347 DumpBlockHeader(file); |
347 | 348 |
348 DumpStats(input_path, stats_addr); | 349 DumpStats(input_path, stats_addr); |
349 return 0; | 350 return 0; |
350 } | 351 } |
351 | 352 |
352 // Dumps all entries from the cache. | 353 // Dumps all entries from the cache. |
353 int DumpContents(const base::FilePath& input_path) { | 354 int DumpContents(const base::FilePath& input_path) { |
354 DumpHeaders(input_path); | 355 DumpHeaders(input_path); |
355 | 356 |
356 // We need a message loop, although we really don't run any task. | 357 // We need a message loop, although we really don't run any task. |
357 MessageLoop loop(MessageLoop::TYPE_IO); | 358 MessageLoop loop(MessageLoop::TYPE_IO); |
358 CacheDumper dumper(input_path); | 359 CacheDumper dumper(input_path); |
359 if (!dumper.Init()) | 360 if (!dumper.Init()) |
360 return -1; | 361 return -1; |
361 | 362 |
362 disk_cache::EntryStore entry; | 363 disk_cache::EntryStore entry; |
363 while (dumper.GetEntry(&entry)) { | 364 while (dumper.GetEntry(&entry)) { |
364 DumpEntry(entry); | 365 DumpEntry(entry); |
365 disk_cache::RankingsNode rankings; | 366 disk_cache::RankingsNode rankings; |
366 if (dumper.LoadRankings(entry.rankings_node, &rankings)) | 367 if (dumper.LoadRankings(entry.rankings_node, &rankings)) |
367 DumpRankings(rankings); | 368 DumpRankings(rankings); |
368 } | 369 } |
369 | 370 |
370 printf("Done.\n"); | 371 printf("Done.\n"); |
371 | 372 |
372 return 0; | 373 return 0; |
373 } | 374 } |
OLD | NEW |