| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/component_updater/component_patcher_win.h" | 5 #include "chrome/browser/component_updater/component_patcher_win.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 return base::FilePath(); | 54 return base::FilePath(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 // Applies the patch to the input file. Returns kNone if the patch was | 59 // Applies the patch to the input file. Returns kNone if the patch was |
| 60 // successfully applied, kDeltaOperationFailure if the patch operation | 60 // successfully applied, kDeltaOperationFailure if the patch operation |
| 61 // encountered errors, and kDeltaPatchProcessFailure if there was an error | 61 // encountered errors, and kDeltaPatchProcessFailure if there was an error |
| 62 // when running the patch code out of process. In the error case, detailed error | 62 // when running the patch code out of process. In the error case, detailed error |
| 63 // information could be returned in the error parameter. | 63 // information could be returned in the error parameter. |
| 64 ComponentUnpacker::Error ComponentPatcherWin::Patch( | 64 component_updater::Error ComponentPatcherWin::Patch( |
| 65 PatchType patch_type, | 65 PatchType patch_type, |
| 66 const base::FilePath& input_file, | 66 const base::FilePath& input_file, |
| 67 const base::FilePath& patch_file, | 67 const base::FilePath& patch_file, |
| 68 const base::FilePath& output_file, | 68 const base::FilePath& output_file, |
| 69 int* error) { | 69 int* error) { |
| 70 *error = 0; | 70 *error = 0; |
| 71 | 71 |
| 72 const base::FilePath exe_path = FindSetupProgram(); | 72 const base::FilePath exe_path = FindSetupProgram(); |
| 73 if (exe_path.empty()) | 73 if (exe_path.empty()) |
| 74 return ComponentUnpacker::kDeltaPatchProcessFailure; | 74 return component_updater::kDeltaPatchProcessFailure; |
| 75 | 75 |
| 76 const std::string patch_type_str(PatchTypeToCommandLineSwitch(patch_type)); | 76 const std::string patch_type_str(PatchTypeToCommandLineSwitch(patch_type)); |
| 77 | 77 |
| 78 CommandLine cl(CommandLine::NO_PROGRAM); | 78 CommandLine cl(CommandLine::NO_PROGRAM); |
| 79 cl.AppendSwitchASCII(installer::switches::kPatch, patch_type_str.c_str()); | 79 cl.AppendSwitchASCII(installer::switches::kPatch, patch_type_str.c_str()); |
| 80 cl.AppendSwitchPath(installer::switches::kInputFile, input_file); | 80 cl.AppendSwitchPath(installer::switches::kInputFile, input_file); |
| 81 cl.AppendSwitchPath(installer::switches::kPatchFile, patch_file); | 81 cl.AppendSwitchPath(installer::switches::kPatchFile, patch_file); |
| 82 cl.AppendSwitchPath(installer::switches::kOutputFile, output_file); | 82 cl.AppendSwitchPath(installer::switches::kOutputFile, output_file); |
| 83 | 83 |
| 84 // Create the child process in a job object. The job object prevents leaving | 84 // Create the child process in a job object. The job object prevents leaving |
| 85 // child processes around when the parent process exits, either gracefully or | 85 // child processes around when the parent process exits, either gracefully or |
| 86 // accidentally. | 86 // accidentally. |
| 87 base::win::ScopedHandle job(CreateJobObject(NULL, NULL)); | 87 base::win::ScopedHandle job(CreateJobObject(NULL, NULL)); |
| 88 if (!job || | 88 if (!job || |
| 89 !base::SetJobObjectLimitFlags(job, JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE)) { | 89 !base::SetJobObjectLimitFlags(job, JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE)) { |
| 90 *error = GetLastError(); | 90 *error = GetLastError(); |
| 91 return ComponentUnpacker::kDeltaPatchProcessFailure; | 91 return component_updater::kDeltaPatchProcessFailure; |
| 92 } | 92 } |
| 93 | 93 |
| 94 base::LaunchOptions launch_options; | 94 base::LaunchOptions launch_options; |
| 95 launch_options.wait = true; | 95 launch_options.wait = true; |
| 96 launch_options.job_handle = job; | 96 launch_options.job_handle = job; |
| 97 launch_options.start_hidden = true; | 97 launch_options.start_hidden = true; |
| 98 CommandLine setup_path(exe_path); | 98 CommandLine setup_path(exe_path); |
| 99 setup_path.AppendArguments(cl, false); | 99 setup_path.AppendArguments(cl, false); |
| 100 | 100 |
| 101 // |ph| is closed by WaitForExitCode. | 101 // |ph| is closed by WaitForExitCode. |
| 102 base::ProcessHandle ph = base::kNullProcessHandle; | 102 base::ProcessHandle ph = base::kNullProcessHandle; |
| 103 int exit_code = 0; | 103 int exit_code = 0; |
| 104 if (!base::LaunchProcess(setup_path, launch_options, &ph) || | 104 if (!base::LaunchProcess(setup_path, launch_options, &ph) || |
| 105 !base::WaitForExitCode(ph, &exit_code)) { | 105 !base::WaitForExitCode(ph, &exit_code)) { |
| 106 *error = GetLastError(); | 106 *error = GetLastError(); |
| 107 return ComponentUnpacker::kDeltaPatchProcessFailure; | 107 return component_updater::kDeltaPatchProcessFailure; |
| 108 } | 108 } |
| 109 | 109 |
| 110 *error = exit_code; | 110 *error = exit_code; |
| 111 return *error ? ComponentUnpacker::kDeltaOperationFailure : | 111 return *error ? component_updater::kDeltaOperationFailure : |
| 112 ComponentUnpacker::kNone; | 112 component_updater::kNone; |
| 113 } | 113 } |
| 114 | 114 |
| OLD | NEW |