| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This command-line program dumps the contents of a set of cache files, either | 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. | 6 // to stdout or to another set of cache files. |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/scoped_handle.h" | |
| 15 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 17 | 16 #include "base/win/scoped_handle.h" |
| 18 #include "net/disk_cache/disk_format.h" | 17 #include "net/disk_cache/disk_format.h" |
| 19 | 18 |
| 20 enum Errors { | 19 enum Errors { |
| 21 GENERIC = -1, | 20 GENERIC = -1, |
| 22 ALL_GOOD = 0, | 21 ALL_GOOD = 0, |
| 23 INVALID_ARGUMENT = 1, | 22 INVALID_ARGUMENT = 1, |
| 24 FILE_ACCESS_ERROR, | 23 FILE_ACCESS_ERROR, |
| 25 UNKNOWN_VERSION, | 24 UNKNOWN_VERSION, |
| 26 TOOL_NOT_FOUND, | 25 TOOL_NOT_FOUND, |
| 27 }; | 26 }; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 printf("Unknown version\n"); | 148 printf("Unknown version\n"); |
| 150 return UNKNOWN_VERSION; | 149 return UNKNOWN_VERSION; |
| 151 } | 150 } |
| 152 slave_required = true; | 151 slave_required = true; |
| 153 } | 152 } |
| 154 | 153 |
| 155 std::wstring pipe_number = command_line.GetSwitchValueNative(kPipe); | 154 std::wstring pipe_number = command_line.GetSwitchValueNative(kPipe); |
| 156 if (command_line.HasSwitch(kSlave) && slave_required) | 155 if (command_line.HasSwitch(kSlave) && slave_required) |
| 157 return RunSlave(input_path, pipe_number); | 156 return RunSlave(input_path, pipe_number); |
| 158 | 157 |
| 159 ScopedHandle server; | 158 base::win::ScopedHandle server; |
| 160 if (slave_required) { | 159 if (slave_required) { |
| 161 server.Set(CreateServer(&pipe_number)); | 160 server.Set(CreateServer(&pipe_number)); |
| 162 if (!server.IsValid()) { | 161 if (!server.IsValid()) { |
| 163 printf("Unable to create the server pipe\n"); | 162 printf("Unable to create the server pipe\n"); |
| 164 return -1; | 163 return -1; |
| 165 } | 164 } |
| 166 | 165 |
| 167 int ret = LaunchSlave(command_line, pipe_number, version); | 166 int ret = LaunchSlave(command_line, pipe_number, version); |
| 168 if (ret) | 167 if (ret) |
| 169 return ret; | 168 return ret; |
| 170 } | 169 } |
| 171 | 170 |
| 172 if (upgrade || copy_to_text) | 171 if (upgrade || copy_to_text) |
| 173 return CopyCache(output_path, server, copy_to_text); | 172 return CopyCache(output_path, server, copy_to_text); |
| 174 | 173 |
| 175 if (slave_required) { | 174 if (slave_required) { |
| 176 // Wait until the slave starts dumping data before we quit. Lazy "fix" for a | 175 // Wait until the slave starts dumping data before we quit. Lazy "fix" for a |
| 177 // console quirk. | 176 // console quirk. |
| 178 Sleep(500); | 177 Sleep(500); |
| 179 return ALL_GOOD; | 178 return ALL_GOOD; |
| 180 } | 179 } |
| 181 | 180 |
| 182 if (command_line.HasSwitch(kDumpContents)) | 181 if (command_line.HasSwitch(kDumpContents)) |
| 183 return DumpContents(input_path); | 182 return DumpContents(input_path); |
| 184 if (command_line.HasSwitch(kDumpHeaders)) | 183 if (command_line.HasSwitch(kDumpHeaders)) |
| 185 return DumpHeaders(input_path); | 184 return DumpHeaders(input_path); |
| 186 return Help(); | 185 return Help(); |
| 187 } | 186 } |
| OLD | NEW |