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

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

Issue 274453010: Prototype fix for version shear across updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 | « chrome/browser/first_run/upgrade_util_win.h ('k') | 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 <shellapi.h> 9 #include <shellapi.h>
9 10
10 #include <algorithm> 11 #include <algorithm>
11 #include <string> 12 #include <string>
12 13
13 #include "base/base_paths.h" 14 #include "base/base_paths.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/environment.h" 16 #include "base/environment.h"
16 #include "base/file_util.h" 17 #include "base/file_util.h"
17 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 const RelaunchMode& relaunch_mode) { 117 const RelaunchMode& relaunch_mode) {
117 scoped_ptr<base::Environment> env(base::Environment::Create()); 118 scoped_ptr<base::Environment> env(base::Environment::Create());
118 std::string version_str; 119 std::string version_str;
119 120
120 // Get the version variable and remove it from the environment. 121 // Get the version variable and remove it from the environment.
121 if (env->GetVar(chrome::kChromeVersionEnvVar, &version_str)) 122 if (env->GetVar(chrome::kChromeVersionEnvVar, &version_str))
122 env->UnSetVar(chrome::kChromeVersionEnvVar); 123 env->UnSetVar(chrome::kChromeVersionEnvVar);
123 else 124 else
124 version_str.clear(); 125 version_str.clear();
125 126
127
grt (UTC plus 2) 2014/05/09 16:53:08 nit: remove extra newline
robertshield 2014/05/15 16:49:35 Done.
128 CommandLine chrome_exe_command_line = command_line;
129 base::FilePath current_exe_path(command_line.GetProgram().DirName());
grt (UTC plus 2) 2014/05/09 16:53:08 i'm not sure about this. i recently fixed a bugabo
robertshield 2014/05/15 16:49:35 Done.
130 current_exe_path = current_exe_path.Append(installer::kChromeExe);
131 chrome_exe_command_line.SetProgram(current_exe_path);
132
126 if (base::win::GetVersion() < base::win::VERSION_WIN8) 133 if (base::win::GetVersion() < base::win::VERSION_WIN8)
127 return base::LaunchProcess(command_line, base::LaunchOptions(), NULL); 134 return base::LaunchProcess(chrome_exe_command_line,
135 base::LaunchOptions(), NULL);
128 136
129 // On Windows 8 we always use the delegate_execute for re-launching chrome. 137 // On Windows 8 we always use the delegate_execute for re-launching chrome.
130 // 138 //
131 // Pass this Chrome's Start Menu shortcut path to the relauncher so it can 139 // Pass this Chrome's Start Menu shortcut path to the relauncher so it can
132 // re-activate chrome via ShellExecute. 140 // re-activate chrome via ShellExecute.
133 base::FilePath chrome_exe; 141 base::FilePath chrome_exe;
134 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 142 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
135 NOTREACHED(); 143 NOTREACHED();
136 return false; 144 return false;
137 } 145 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 if (exit_code == installer::RENAME_SUCCESSFUL) 247 if (exit_code == installer::RENAME_SUCCESSFUL)
240 return true; 248 return true;
241 } 249 }
242 } 250 }
243 } 251 }
244 252
245 // Rename didn't work so try to rename by calling Google Update 253 // Rename didn't work so try to rename by calling Google Update
246 return InvokeGoogleUpdateForRename(); 254 return InvokeGoogleUpdateForRename();
247 } 255 }
248 256
257 bool IsRunningOldChrome() {
258 // This figures out the actual file name that the section containing the
259 // mapped exe refers to. This is used instead of GetModuleFileName because the
260 // .exe may have been renamed out from under us while we've been running which
261 // GetModuleFileName won't notice.
262 wchar_t mapped_file_name[MAX_PATH * 2] = {};
263 DWORD returned_chars =
grt (UTC plus 2) 2014/05/09 16:53:08 since returned_chars isn't really used, how about:
robertshield 2014/05/15 16:49:35 Done.
264 ::GetMappedFileName(::GetCurrentProcess(),
265 reinterpret_cast<void*>(::GetModuleHandle(NULL)),
266 mapped_file_name,
267 MAX_PATH * 2);
grt (UTC plus 2) 2014/05/09 16:53:08 arraysize(mapped_file_name)
robertshield 2014/05/15 16:49:35 Done.
268 if (returned_chars != 0) {
269 base::FilePath file_name(base::FilePath(mapped_file_name).BaseName());
270 if (base::FilePath::CompareEqualIgnoreCase(file_name.value(),
271 installer::kChromeOldExe)) {
272 return true;
273 }
274 }
275 return false;
276 }
277
249 bool DoUpgradeTasks(const CommandLine& command_line) { 278 bool DoUpgradeTasks(const CommandLine& command_line) {
250 // The DelegateExecute verb handler finalizes pending in-use updates for 279 // The DelegateExecute verb handler finalizes pending in-use updates for
251 // metro mode launches, as Chrome cannot be gracefully relaunched when 280 // metro mode launches, as Chrome cannot be gracefully relaunched when
252 // running in this mode. 281 // running in this mode.
253 if (base::win::IsMetroProcess()) 282 if (base::win::IsMetroProcess())
254 return false; 283 return false;
255 if (!SwapNewChromeExeIfPresent()) 284 if (!SwapNewChromeExeIfPresent() && !IsRunningOldChrome())
256 return false; 285 return false;
257 // At this point the chrome.exe has been swapped with the new one. 286 // At this point the chrome.exe has been swapped with the new one.
258 if (!RelaunchChromeBrowser(command_line)) { 287 if (!RelaunchChromeBrowser(command_line)) {
259 // The re-launch fails. Feel free to panic now. 288 // The re-launch fails. Feel free to panic now.
260 NOTREACHED(); 289 NOTREACHED();
261 } 290 }
262 return true; 291 return true;
263 } 292 }
264 293
265 } // namespace upgrade_util 294 } // namespace upgrade_util
OLDNEW
« no previous file with comments | « chrome/browser/first_run/upgrade_util_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698