[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / net / tools / dump_cache / dump_cache.cc
blob74cbd4064a703cffaebc182ae2491952d89d2c9b
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
3 // found in the LICENSE file.
5 // This command-line program dumps the contents of a set of cache files, either
6 // to stdout or to another set of cache files.
8 #include <stdio.h>
9 #include <string>
11 #include "base/at_exit.h"
12 #include "base/command_line.h"
13 #include "base/strings/string16.h"
14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h"
16 #include "net/disk_cache/blockfile/disk_format.h"
17 #include "net/tools/dump_cache/dump_files.h"
19 enum Errors {
20 GENERIC = -1,
21 ALL_GOOD = 0,
22 INVALID_ARGUMENT = 1,
23 FILE_ACCESS_ERROR,
24 UNKNOWN_VERSION,
25 TOOL_NOT_FOUND,
28 // Dumps the file headers to stdout.
29 const char kDumpHeaders[] = "dump-headers";
31 // Dumps all entries to stdout.
32 const char kDumpContents[] = "dump-contents";
34 // Dumps the LRU lists(s).
35 const char kDumpLists[] = "dump-lists";
37 // Dumps the entry at the given address (see kDumpAt).
38 const char kDumpEntry[] = "dump-entry";
40 // The cache address to dump.
41 const char kDumpAt[] = "at";
43 // Dumps the allocation bitmap of a file (see kDumpFile).
44 const char kDumpAllocation[] = "dump-allocation";
46 // The file to look at.
47 const char kDumpFile[] = "file";
49 int Help() {
50 printf("dump_cache path_to_files [options]\n");
51 printf("Dumps internal cache structures.\n");
52 printf("warning: input files may be modified by this tool\n\n");
53 printf("--dump-headers: show file headers\n");
54 printf("--dump-contents [-v] [--full-key] [--csv]: list all entries\n");
55 printf("--dump-lists: follow the LRU list(s)\n");
56 printf(
57 "--dump-entry [-v] [--full-key] --at=0xf00: show the data stored at"
58 " 0xf00\n");
59 printf(
60 "--dump-allocation --file=data_0: show the allocation bitmap of"
61 " data_0\n");
62 printf("--csv: dump in a comma-separated-values format\n");
63 printf(
64 "--full-key: show up to 160 chars for the key. Use either -v or the"
65 " key address for longer keys\n");
66 printf("-v: detailed output (verbose)\n");
67 return INVALID_ARGUMENT;
70 // -----------------------------------------------------------------------
72 int main(int argc, const char* argv[]) {
73 // Setup an AtExitManager so Singleton objects will be destroyed.
74 base::AtExitManager at_exit_manager;
76 base::CommandLine::Init(argc, argv);
78 const base::CommandLine& command_line =
79 *base::CommandLine::ForCurrentProcess();
80 base::CommandLine::StringVector args = command_line.GetArgs();
81 if (args.size() != 1)
82 return Help();
84 base::FilePath input_path(args[0]);
85 if (input_path.empty())
86 return Help();
88 int version = GetMajorVersion(input_path);
89 if (version != 2)
90 return FILE_ACCESS_ERROR;
92 if (command_line.HasSwitch(kDumpContents))
93 return DumpContents(input_path);
95 if (command_line.HasSwitch(kDumpLists))
96 return DumpLists(input_path);
98 if (command_line.HasSwitch(kDumpEntry) && command_line.HasSwitch(kDumpAt))
99 return DumpEntryAt(input_path, command_line.GetSwitchValueASCII(kDumpAt));
101 if (command_line.HasSwitch(kDumpAllocation) &&
102 command_line.HasSwitch(kDumpFile)) {
103 base::FilePath name =
104 input_path.AppendASCII(command_line.GetSwitchValueASCII(kDumpFile));
105 return DumpAllocation(name);
108 if (command_line.HasSwitch(kDumpHeaders))
109 return DumpHeaders(input_path);
111 return Help();