Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/component_updater/component_patcher_win.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/base_paths.h" | |
| 10 #include "base/command_line.h" | |
| 11 #include "base/file_util.h" | |
| 12 #include "base/path_service.h" | |
| 13 #include "base/process_util.h" | |
| 14 #include "base/string_util.h" | |
| 15 #include "chrome/installer/util/util_constants.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 std::string PatchTypeToCommandLineSwitch(PatchType patch_type) { | |
| 20 if (patch_type == kPatchTypeCourgette) | |
| 21 return std::string(installer::switches::kCourgette); | |
| 22 else if (patch_type == kPatchTypeBsdiff) | |
| 23 return std::string(installer::switches::kBsdiff); | |
| 24 else | |
| 25 return std::string(); | |
| 26 } | |
| 27 | |
| 28 // Finds the path to the setup.exe. First, it looks for the program in the | |
| 29 // "installer" directory. If the program is not found there, it tries to find it | |
| 30 // in the directory where chrome.dll. Returns the path to the setup.exe, if the | |
|
cpu_(ooo_6.6-7.5)
2013/06/14 23:25:28
where chrome.dll lives?
waffles
2013/06/15 00:01:37
Done; will be in the next patchset.
| |
| 31 // path exists, otherwise it returns an an empty path. | |
| 32 base::FilePath FindSetupProgram() { | |
| 33 base::FilePath exe_dir; | |
| 34 if (!PathService::Get(base::DIR_MODULE, &exe_dir)) | |
| 35 return base::FilePath(); | |
| 36 | |
| 37 const std::string installer_dir(WideToASCII(installer::kInstallerDir)); | |
| 38 const std::string setup_exe(WideToASCII(installer::kSetupExe)); | |
| 39 | |
| 40 base::FilePath setup_path = exe_dir; | |
| 41 setup_path = setup_path.AppendASCII(installer_dir); | |
| 42 setup_path = setup_path.AppendASCII(setup_exe); | |
| 43 if (file_util::PathExists(setup_path)) | |
| 44 return setup_path; | |
| 45 | |
| 46 setup_path = exe_dir; | |
| 47 setup_path = setup_path.AppendASCII(setup_exe); | |
| 48 if (file_util::PathExists(setup_path)) | |
| 49 return setup_path; | |
| 50 | |
| 51 return base::FilePath(); | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 // Applies the patch to the input file. Returns kNone if the pacth was | |
|
robertshield
2013/06/17 17:47:00
patch
Sorin Jianu
2013/06/17 22:21:09
Done.
| |
| 57 // successfully applied, kDeltaOperationFailure if the patch operation | |
| 58 // encountered errors, and kDeltaPatchProcessFailure if there was an error | |
| 59 // when running the patch code out of process. In the error case, detailed error | |
| 60 // information could be returned in the error parameter. | |
| 61 ComponentUnpacker::Error ComponentPatcherWin::Patch( | |
| 62 PatchType patch_type, | |
| 63 const base::FilePath& input_file, | |
| 64 const base::FilePath& patch_file, | |
| 65 const base::FilePath& output_file, | |
| 66 int* error) { | |
| 67 *error = 0; | |
| 68 | |
| 69 const base::FilePath exe_path = FindSetupProgram(); | |
| 70 if (exe_path.empty()) | |
| 71 return ComponentUnpacker::kDeltaPatchProcessFailure; | |
| 72 | |
| 73 const std::string patch_type_str(PatchTypeToCommandLineSwitch(patch_type)); | |
| 74 | |
| 75 CommandLine cl(CommandLine::NO_PROGRAM); | |
| 76 cl.AppendSwitchASCII(installer::switches::kPatch, patch_type_str.c_str()); | |
| 77 cl.AppendSwitchPath(installer::switches::kInputFile, input_file); | |
| 78 cl.AppendSwitchPath(installer::switches::kPatchFile, patch_file); | |
| 79 cl.AppendSwitchPath(installer::switches::kOutputFile, output_file); | |
| 80 | |
| 81 base::LaunchOptions launch_options; | |
| 82 launch_options.wait = true; | |
| 83 launch_options.start_hidden = true; | |
|
cpu_(ooo_6.6-7.5)
2013/06/14 23:25:28
setup does not launch other process while doing th
Sorin Jianu
2013/06/15 00:10:44
setup.exe is the only process we create here, no o
| |
| 84 CommandLine setup_path(exe_path); | |
| 85 setup_path.AppendArguments(cl, false); | |
| 86 | |
| 87 base::ProcessHandle ph; | |
| 88 int exit_code = 0; | |
| 89 if (!base::LaunchProcess(setup_path, launch_options, &ph) || | |
| 90 !base::WaitForExitCode(ph, &exit_code)) | |
| 91 return ComponentUnpacker::kDeltaPatchProcessFailure; | |
| 92 | |
|
cpu_(ooo_6.6-7.5)
2013/06/14 23:25:28
when do we close this process handle |ph| ?
Sorin Jianu
2013/06/15 00:10:44
WaitForExitCode closes the handle.
| |
| 93 *error = exit_code; | |
| 94 return *error ? ComponentUnpacker::kDeltaOperationFailure : | |
| 95 ComponentUnpacker::kNone; | |
| 96 } | |
| 97 | |
| OLD | NEW |