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

Side by Side Diff: win8/delegate_execute/chrome_util.cc

Issue 759903002: Upgrade the windows specific version of LaunchProcess to avoid raw handles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix chrome build Created 6 years 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
« no previous file with comments | « remoting/host/setup/daemon_installer_win.cc ('k') | win8/test/metro_registration_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "win8/delegate_execute/chrome_util.h" 5 #include "win8/delegate_execute/chrome_util.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <limits> 12 #include <limits>
13 #include <string> 13 #include <string>
14 14
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/md5.h" 17 #include "base/md5.h"
18 #include "base/process/kill.h" 18 #include "base/process/kill.h"
19 #include "base/process/launch.h" 19 #include "base/process/launch.h"
20 #include "base/process/process_handle.h" 20 #include "base/process/process.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/win/registry.h" 23 #include "base/win/registry.h"
24 #include "base/win/scoped_comptr.h" 24 #include "base/win/scoped_comptr.h"
25 #include "base/win/scoped_handle.h" 25 #include "base/win/scoped_handle.h"
26 #include "base/win/win_util.h" 26 #include "base/win/win_util.h"
27 #include "chrome/installer/util/browser_distribution.h" 27 #include "chrome/installer/util/browser_distribution.h"
28 #include "chrome/installer/util/install_util.h" 28 #include "chrome/installer/util/install_util.h"
29 #include "chrome/installer/util/util_constants.h" 29 #include "chrome/installer/util/util_constants.h"
30 #include "google_update/google_update_idl.h" 30 #include "google_update/google_update_idl.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 namespace delegate_execute { 97 namespace delegate_execute {
98 98
99 void UpdateChromeIfNeeded(const base::FilePath& chrome_exe) { 99 void UpdateChromeIfNeeded(const base::FilePath& chrome_exe) {
100 #if defined(GOOGLE_CHROME_BUILD) 100 #if defined(GOOGLE_CHROME_BUILD)
101 // Nothing to do if a browser is already running or if there's no 101 // Nothing to do if a browser is already running or if there's no
102 // new_chrome.exe. 102 // new_chrome.exe.
103 if (IsBrowserRunning(chrome_exe) || !NewChromeExeExists(chrome_exe)) 103 if (IsBrowserRunning(chrome_exe) || !NewChromeExeExists(chrome_exe))
104 return; 104 return;
105 105
106 base::win::ScopedHandle process_handle; 106 base::Process process;
107 107
108 if (InstallUtil::IsPerUserInstall(chrome_exe.value().c_str())) { 108 if (InstallUtil::IsPerUserInstall(chrome_exe.value().c_str())) {
109 // Read the update command from the registry. 109 // Read the update command from the registry.
110 base::string16 update_command; 110 base::string16 update_command;
111 if (!GetUpdateCommand(true, &update_command)) { 111 if (!GetUpdateCommand(true, &update_command)) {
112 AtlTrace("%hs. Failed to read update command from registry.\n", 112 AtlTrace("%hs. Failed to read update command from registry.\n",
113 __FUNCTION__); 113 __FUNCTION__);
114 } else { 114 } else {
115 // Run the update command. 115 // Run the update command.
116 base::LaunchOptions launch_options; 116 base::LaunchOptions launch_options;
117 launch_options.start_hidden = true; 117 launch_options.start_hidden = true;
118 if (!base::LaunchProcess(update_command, launch_options, 118 process = base::LaunchProcess(update_command, launch_options);
119 &process_handle)) { 119 if (!process.IsValid()) {
120 AtlTrace("%hs. Failed to launch command to finalize update; " 120 AtlTrace("%hs. Failed to launch command to finalize update; "
121 "error %u.\n", __FUNCTION__, ::GetLastError()); 121 "error %u.\n", __FUNCTION__, ::GetLastError());
122 } 122 }
123 } 123 }
124 } else { 124 } else {
125 // Run the update command via Google Update. 125 // Run the update command via Google Update.
126 HRESULT hr = S_OK; 126 HRESULT hr = S_OK;
127 base::win::ScopedComPtr<IProcessLauncher> process_launcher; 127 base::win::ScopedComPtr<IProcessLauncher> process_launcher;
128 hr = process_launcher.CreateInstance(__uuidof(ProcessLauncherClass)); 128 hr = process_launcher.CreateInstance(__uuidof(ProcessLauncherClass));
129 if (FAILED(hr)) { 129 if (FAILED(hr)) {
130 AtlTrace("%hs. Failed to Create ProcessLauncher; hr=0x%X.\n", 130 AtlTrace("%hs. Failed to Create ProcessLauncher; hr=0x%X.\n",
131 __FUNCTION__, hr); 131 __FUNCTION__, hr);
132 } else { 132 } else {
133 ULONG_PTR handle = 0; 133 ULONG_PTR handle = 0;
134 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 134 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
135 hr = process_launcher->LaunchCmdElevated( 135 hr = process_launcher->LaunchCmdElevated(
136 dist->GetAppGuid().c_str(), kRenameCommandValue, 136 dist->GetAppGuid().c_str(), kRenameCommandValue,
137 GetCurrentProcessId(), &handle); 137 GetCurrentProcessId(), &handle);
138 if (FAILED(hr)) { 138 if (FAILED(hr)) {
139 AtlTrace("%hs. Failed to launch command to finalize update; " 139 AtlTrace("%hs. Failed to launch command to finalize update; "
140 "hr=0x%X.\n", __FUNCTION__, hr); 140 "hr=0x%X.\n", __FUNCTION__, hr);
141 } else { 141 } else {
142 process_handle.Set(reinterpret_cast<base::ProcessHandle>(handle)); 142 process = base::Process(reinterpret_cast<base::ProcessHandle>(handle));
143 } 143 }
144 } 144 }
145 } 145 }
146 146
147 // Wait for the update to complete and report the results. 147 // Wait for the update to complete and report the results.
148 if (process_handle.IsValid()) { 148 if (process.IsValid()) {
149 int exit_code = 0; 149 int exit_code = 0;
150 // WaitForExitCode will close the handle in all cases. 150 if (!base::WaitForExitCodeWithTimeout(
151 if (!base::WaitForExitCode(process_handle.Take(), &exit_code)) { 151 process.Handle(), &exit_code,
152 base::TimeDelta::FromMilliseconds(INFINITE))) {
152 AtlTrace("%hs. Failed to get result when finalizing update.\n", 153 AtlTrace("%hs. Failed to get result when finalizing update.\n",
153 __FUNCTION__); 154 __FUNCTION__);
154 } else if (exit_code != installer::RENAME_SUCCESSFUL) { 155 } else if (exit_code != installer::RENAME_SUCCESSFUL) {
155 AtlTrace("%hs. Failed to finalize update with exit code %d.\n", 156 AtlTrace("%hs. Failed to finalize update with exit code %d.\n",
156 __FUNCTION__, exit_code); 157 __FUNCTION__, exit_code);
157 } else { 158 } else {
158 AtlTrace("%hs. Finalized pending update.\n", __FUNCTION__); 159 AtlTrace("%hs. Finalized pending update.\n", __FUNCTION__);
159 } 160 }
160 } 161 }
161 #endif 162 #endif
162 } 163 }
163 164
164 } // delegate_execute 165 } // delegate_execute
OLDNEW
« no previous file with comments | « remoting/host/setup/daemon_installer_win.cc ('k') | win8/test/metro_registration_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698