Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/component_updater/component_patcher_win.cc

Issue 17314017: the patcher process runs inside of a job (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/process_util.h" 13 #include "base/process_util.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/win/scoped_handle.h"
15 #include "chrome/installer/util/util_constants.h" 16 #include "chrome/installer/util/util_constants.h"
16 17
17 namespace { 18 namespace {
18 19
19 std::string PatchTypeToCommandLineSwitch( 20 std::string PatchTypeToCommandLineSwitch(
20 ComponentPatcher::PatchType patch_type) { 21 ComponentPatcher::PatchType patch_type) {
21 if (patch_type == ComponentPatcher::kPatchTypeCourgette) 22 if (patch_type == ComponentPatcher::kPatchTypeCourgette)
22 return std::string(installer::kCourgette); 23 return std::string(installer::kCourgette);
23 else if (patch_type == ComponentPatcher::kPatchTypeBsdiff) 24 else if (patch_type == ComponentPatcher::kPatchTypeBsdiff)
24 return std::string(installer::kBsdiff); 25 return std::string(installer::kBsdiff);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return ComponentUnpacker::kDeltaPatchProcessFailure; 73 return ComponentUnpacker::kDeltaPatchProcessFailure;
73 74
74 const std::string patch_type_str(PatchTypeToCommandLineSwitch(patch_type)); 75 const std::string patch_type_str(PatchTypeToCommandLineSwitch(patch_type));
75 76
76 CommandLine cl(CommandLine::NO_PROGRAM); 77 CommandLine cl(CommandLine::NO_PROGRAM);
77 cl.AppendSwitchASCII(installer::switches::kPatch, patch_type_str.c_str()); 78 cl.AppendSwitchASCII(installer::switches::kPatch, patch_type_str.c_str());
78 cl.AppendSwitchPath(installer::switches::kInputFile, input_file); 79 cl.AppendSwitchPath(installer::switches::kInputFile, input_file);
79 cl.AppendSwitchPath(installer::switches::kPatchFile, patch_file); 80 cl.AppendSwitchPath(installer::switches::kPatchFile, patch_file);
80 cl.AppendSwitchPath(installer::switches::kOutputFile, output_file); 81 cl.AppendSwitchPath(installer::switches::kOutputFile, output_file);
81 82
83 // Create the child process in a job object. The job object prevents leaving
84 // child processes around when the parent process exits, either gracefully or
85 // accidentally.
86 base::win::ScopedHandle job(CreateJobObject(NULL, NULL));
87 if (!job || !base::SetJobObjectAsKillOnJobClose(job)) {
88 *error = GetLastError();
89 return ComponentUnpacker::kDeltaPatchProcessFailure;
90 }
91
82 base::LaunchOptions launch_options; 92 base::LaunchOptions launch_options;
83 launch_options.wait = true; 93 launch_options.wait = true;
94 launch_options.job_handle = job;
84 launch_options.start_hidden = true; 95 launch_options.start_hidden = true;
85 CommandLine setup_path(exe_path); 96 CommandLine setup_path(exe_path);
86 setup_path.AppendArguments(cl, false); 97 setup_path.AppendArguments(cl, false);
87 98
88 base::ProcessHandle ph; 99 // |ph| is closed by WaitForExitCode.
100 base::ProcessHandle ph = base::kNullProcessHandle;
89 int exit_code = 0; 101 int exit_code = 0;
90 if (!base::LaunchProcess(setup_path, launch_options, &ph) || 102 if (!base::LaunchProcess(setup_path, launch_options, &ph) ||
91 !base::WaitForExitCode(ph, &exit_code)) 103 !base::WaitForExitCode(ph, &exit_code)) {
104 *error = GetLastError();
92 return ComponentUnpacker::kDeltaPatchProcessFailure; 105 return ComponentUnpacker::kDeltaPatchProcessFailure;
106 }
93 107
94 *error = exit_code; 108 *error = exit_code;
95 return *error ? ComponentUnpacker::kDeltaOperationFailure : 109 return *error ? ComponentUnpacker::kDeltaOperationFailure :
96 ComponentUnpacker::kNone; 110 ComponentUnpacker::kNone;
97 } 111 }
98 112
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698