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

Side by Side Diff: chrome/browser/first_run/upgrade_util_win.cc

Issue 2382493002: Do not launch rename process directly from system-level Chrome. (Closed)
Patch Set: Created 4 years, 2 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
« 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 (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 "chrome/browser/first_run/upgrade_util.h" 5 #include "chrome/browser/first_run/upgrade_util.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <psapi.h> 8 #include <psapi.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 10
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return false; 106 return false;
107 return base::PathExists(new_chrome_exe); 107 return base::PathExists(new_chrome_exe);
108 } 108 }
109 109
110 bool SwapNewChromeExeIfPresent() { 110 bool SwapNewChromeExeIfPresent() {
111 if (!IsUpdatePendingRestart()) 111 if (!IsUpdatePendingRestart())
112 return false; 112 return false;
113 base::FilePath cur_chrome_exe; 113 base::FilePath cur_chrome_exe;
114 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe)) 114 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe))
115 return false; 115 return false;
116 bool user_install = InstallUtil::IsPerUserInstall(cur_chrome_exe);
117 116
118 // Ask Google Update to elevate and rename if the current process is in a 117 // If this is a system-level install, ask Google Update to launch an elevated
119 // per-machine install. Failing that, fall back to the direct approach. 118 // process to rename Chrome executables.
120 if (!user_install && InvokeGoogleUpdateForRename()) 119 if (!InstallUtil::IsPerUserInstall(cur_chrome_exe))
121 return true; 120 return InvokeGoogleUpdateForRename();
122 121
123 // Open up the registry key containing current version and rename information. 122 // If this is a user-level install, directly launch a process to rename Chrome
124 HKEY reg_root = user_install ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 123 // executables. Obtain the command to launch the process from the registry.
125 BrowserDistribution *dist = BrowserDistribution::GetDistribution();
126 base::win::RegKey key; 124 base::win::RegKey key;
127 if (key.Open(reg_root, dist->GetVersionKey().c_str(), 125 if (key.Open(HKEY_CURRENT_USER,
126 BrowserDistribution::GetDistribution()->GetVersionKey().c_str(),
128 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { 127 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
129 // First try to rename exe by launching rename command ourselves.
130 std::wstring rename_cmd; 128 std::wstring rename_cmd;
131 if (key.ReadValue(google_update::kRegRenameCmdField, 129 if (key.ReadValue(google_update::kRegRenameCmdField,
132 &rename_cmd) == ERROR_SUCCESS) { 130 &rename_cmd) == ERROR_SUCCESS) {
133 base::LaunchOptions options; 131 base::LaunchOptions options;
134 options.wait = true; 132 options.wait = true;
135 options.start_hidden = true; 133 options.start_hidden = true;
136 base::Process process = base::LaunchProcess(rename_cmd, options); 134 base::Process process = base::LaunchProcess(rename_cmd, options);
137 if (process.IsValid()) { 135 if (process.IsValid()) {
138 DWORD exit_code; 136 DWORD exit_code;
139 ::GetExitCodeProcess(process.Handle(), &exit_code); 137 ::GetExitCodeProcess(process.Handle(), &exit_code);
(...skipping 30 matching lines...) Expand all
170 return false; 168 return false;
171 // At this point the chrome.exe has been swapped with the new one. 169 // At this point the chrome.exe has been swapped with the new one.
172 if (!RelaunchChromeBrowser(command_line)) { 170 if (!RelaunchChromeBrowser(command_line)) {
173 // The re-launch fails. Feel free to panic now. 171 // The re-launch fails. Feel free to panic now.
174 NOTREACHED(); 172 NOTREACHED();
175 } 173 }
176 return true; 174 return true;
177 } 175 }
178 176
179 } // namespace upgrade_util 177 } // namespace upgrade_util
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