OLD | NEW |
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 | 102 |
103 bool IsUpdatePendingRestart() { | 103 bool IsUpdatePendingRestart() { |
104 base::FilePath new_chrome_exe; | 104 base::FilePath new_chrome_exe; |
105 if (!GetNewerChromeFile(&new_chrome_exe)) | 105 if (!GetNewerChromeFile(&new_chrome_exe)) |
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 base::FilePath new_chrome_exe; | 111 if (!IsUpdatePendingRestart()) |
112 if (!GetNewerChromeFile(&new_chrome_exe)) | |
113 return false; | |
114 if (!base::PathExists(new_chrome_exe)) | |
115 return false; | 112 return false; |
116 base::FilePath cur_chrome_exe; | 113 base::FilePath cur_chrome_exe; |
117 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe)) | 114 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe)) |
118 return false; | 115 return false; |
| 116 bool user_install = InstallUtil::IsPerUserInstall(cur_chrome_exe); |
| 117 |
| 118 // Ask Google Update to elevate and rename if the current process is in a |
| 119 // per-machine install. Failing that, fall back to the direct approach. |
| 120 if (!user_install && InvokeGoogleUpdateForRename()) |
| 121 return true; |
119 | 122 |
120 // Open up the registry key containing current version and rename information. | 123 // Open up the registry key containing current version and rename information. |
121 bool user_install = InstallUtil::IsPerUserInstall(cur_chrome_exe); | |
122 HKEY reg_root = user_install ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 124 HKEY reg_root = user_install ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
123 BrowserDistribution *dist = BrowserDistribution::GetDistribution(); | 125 BrowserDistribution *dist = BrowserDistribution::GetDistribution(); |
124 base::win::RegKey key; | 126 base::win::RegKey key; |
125 if (key.Open(reg_root, dist->GetVersionKey().c_str(), | 127 if (key.Open(reg_root, dist->GetVersionKey().c_str(), |
126 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 128 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { |
127 // First try to rename exe by launching rename command ourselves. | 129 // First try to rename exe by launching rename command ourselves. |
128 std::wstring rename_cmd; | 130 std::wstring rename_cmd; |
129 if (key.ReadValue(google_update::kRegRenameCmdField, | 131 if (key.ReadValue(google_update::kRegRenameCmdField, |
130 &rename_cmd) == ERROR_SUCCESS) { | 132 &rename_cmd) == ERROR_SUCCESS) { |
131 base::LaunchOptions options; | 133 base::LaunchOptions options; |
132 options.wait = true; | 134 options.wait = true; |
133 options.start_hidden = true; | 135 options.start_hidden = true; |
134 base::Process process = base::LaunchProcess(rename_cmd, options); | 136 base::Process process = base::LaunchProcess(rename_cmd, options); |
135 if (process.IsValid()) { | 137 if (process.IsValid()) { |
136 DWORD exit_code; | 138 DWORD exit_code; |
137 ::GetExitCodeProcess(process.Handle(), &exit_code); | 139 ::GetExitCodeProcess(process.Handle(), &exit_code); |
138 if (exit_code == installer::RENAME_SUCCESSFUL) | 140 if (exit_code == installer::RENAME_SUCCESSFUL) |
139 return true; | 141 return true; |
140 } | 142 } |
141 } | 143 } |
142 } | 144 } |
143 | 145 |
144 // Rename didn't work so try to rename by calling Google Update | 146 return false; |
145 return InvokeGoogleUpdateForRename(); | |
146 } | 147 } |
147 | 148 |
148 bool IsRunningOldChrome() { | 149 bool IsRunningOldChrome() { |
149 // This figures out the actual file name that the section containing the | 150 // This figures out the actual file name that the section containing the |
150 // mapped exe refers to. This is used instead of GetModuleFileName because the | 151 // mapped exe refers to. This is used instead of GetModuleFileName because the |
151 // .exe may have been renamed out from under us while we've been running which | 152 // .exe may have been renamed out from under us while we've been running which |
152 // GetModuleFileName won't notice. | 153 // GetModuleFileName won't notice. |
153 wchar_t mapped_file_name[MAX_PATH * 2] = {}; | 154 wchar_t mapped_file_name[MAX_PATH * 2] = {}; |
154 | 155 |
155 if (!::GetMappedFileName(::GetCurrentProcess(), | 156 if (!::GetMappedFileName(::GetCurrentProcess(), |
(...skipping 13 matching lines...) Expand all Loading... |
169 return false; | 170 return false; |
170 // At this point the chrome.exe has been swapped with the new one. | 171 // At this point the chrome.exe has been swapped with the new one. |
171 if (!RelaunchChromeBrowser(command_line)) { | 172 if (!RelaunchChromeBrowser(command_line)) { |
172 // The re-launch fails. Feel free to panic now. | 173 // The re-launch fails. Feel free to panic now. |
173 NOTREACHED(); | 174 NOTREACHED(); |
174 } | 175 } |
175 return true; | 176 return true; |
176 } | 177 } |
177 | 178 |
178 } // namespace upgrade_util | 179 } // namespace upgrade_util |
OLD | NEW |