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

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

Issue 816403003: Make callers of CommandLine use it via the base:: namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years, 12 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_mac.cc ('k') | chrome/browser/fullscreen_mac.mm » ('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 "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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 RelaunchMode RelaunchModeStringToEnum(const std::string& relaunch_mode) { 110 RelaunchMode RelaunchModeStringToEnum(const std::string& relaunch_mode) {
111 if (relaunch_mode == kRelaunchModeMetro) 111 if (relaunch_mode == kRelaunchModeMetro)
112 return RELAUNCH_MODE_METRO; 112 return RELAUNCH_MODE_METRO;
113 113
114 if (relaunch_mode == kRelaunchModeDesktop) 114 if (relaunch_mode == kRelaunchModeDesktop)
115 return RELAUNCH_MODE_DESKTOP; 115 return RELAUNCH_MODE_DESKTOP;
116 116
117 // On Windows 7 if the current browser is in Chrome OS mode, then restart 117 // On Windows 7 if the current browser is in Chrome OS mode, then restart
118 // into Chrome OS mode. 118 // into Chrome OS mode.
119 if ((base::win::GetVersion() == base::win::VERSION_WIN7) && 119 if ((base::win::GetVersion() == base::win::VERSION_WIN7) &&
120 CommandLine::ForCurrentProcess()->HasSwitch(switches::kViewerConnect) && 120 base::CommandLine::ForCurrentProcess()->HasSwitch(
121 !g_browser_process->local_state()->HasPrefPath(prefs::kRelaunchMode)) { 121 switches::kViewerConnect) &&
122 !g_browser_process->local_state()->HasPrefPath(prefs::kRelaunchMode)) {
122 // TODO(ananta) 123 // TODO(ananta)
123 // On Windows 8, the delegate execute process looks up the previously 124 // On Windows 8, the delegate execute process looks up the previously
124 // launched mode from the registry and relaunches into that mode. We need 125 // launched mode from the registry and relaunches into that mode. We need
125 // something similar on Windows 7. For now, set the pref to ensure that 126 // something similar on Windows 7. For now, set the pref to ensure that
126 // we get relaunched into Chrome OS mode. 127 // we get relaunched into Chrome OS mode.
127 g_browser_process->local_state()->SetString( 128 g_browser_process->local_state()->SetString(
128 prefs::kRelaunchMode, upgrade_util::kRelaunchModeMetro); 129 prefs::kRelaunchMode, upgrade_util::kRelaunchModeMetro);
129 return RELAUNCH_MODE_METRO; 130 return RELAUNCH_MODE_METRO;
130 } 131 }
131 132
132 return RELAUNCH_MODE_DEFAULT; 133 return RELAUNCH_MODE_DEFAULT;
133 } 134 }
134 135
135 bool RelaunchChromeHelper(const CommandLine& command_line, 136 bool RelaunchChromeHelper(const base::CommandLine& command_line,
136 const RelaunchMode& relaunch_mode) { 137 const RelaunchMode& relaunch_mode) {
137 scoped_ptr<base::Environment> env(base::Environment::Create()); 138 scoped_ptr<base::Environment> env(base::Environment::Create());
138 std::string version_str; 139 std::string version_str;
139 140
140 // Get the version variable and remove it from the environment. 141 // Get the version variable and remove it from the environment.
141 if (env->GetVar(chrome::kChromeVersionEnvVar, &version_str)) 142 if (env->GetVar(chrome::kChromeVersionEnvVar, &version_str))
142 env->UnSetVar(chrome::kChromeVersionEnvVar); 143 env->UnSetVar(chrome::kChromeVersionEnvVar);
143 else 144 else
144 version_str.clear(); 145 version_str.clear();
145 146
146 base::FilePath chrome_exe; 147 base::FilePath chrome_exe;
147 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 148 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
148 NOTREACHED(); 149 NOTREACHED();
149 return false; 150 return false;
150 } 151 }
151 152
152 // Explicitly make sure to relaunch chrome.exe rather than old_chrome.exe. 153 // Explicitly make sure to relaunch chrome.exe rather than old_chrome.exe.
153 // This can happen when old_chrome.exe is launched by a user. 154 // This can happen when old_chrome.exe is launched by a user.
154 CommandLine chrome_exe_command_line = command_line; 155 base::CommandLine chrome_exe_command_line = command_line;
155 chrome_exe_command_line.SetProgram( 156 chrome_exe_command_line.SetProgram(
156 chrome_exe.DirName().Append(installer::kChromeExe)); 157 chrome_exe.DirName().Append(installer::kChromeExe));
157 158
158 if (base::win::GetVersion() < base::win::VERSION_WIN8 && 159 if (base::win::GetVersion() < base::win::VERSION_WIN8 &&
159 relaunch_mode != RELAUNCH_MODE_METRO && 160 relaunch_mode != RELAUNCH_MODE_METRO &&
160 relaunch_mode != RELAUNCH_MODE_DESKTOP) 161 relaunch_mode != RELAUNCH_MODE_DESKTOP)
161 return base::LaunchProcess(chrome_exe_command_line, 162 return base::LaunchProcess(chrome_exe_command_line,
162 base::LaunchOptions()).IsValid(); 163 base::LaunchOptions()).IsValid();
163 164
164 // On Windows 8 we always use the delegate_execute for re-launching chrome. 165 // On Windows 8 we always use the delegate_execute for re-launching chrome.
(...skipping 13 matching lines...) Expand all
178 // The |mutex| handle needs to be leaked. See comment above. 179 // The |mutex| handle needs to be leaked. See comment above.
179 if (!mutex) { 180 if (!mutex) {
180 NOTREACHED(); 181 NOTREACHED();
181 return false; 182 return false;
182 } 183 }
183 if (::GetLastError() == ERROR_ALREADY_EXISTS) { 184 if (::GetLastError() == ERROR_ALREADY_EXISTS) {
184 NOTREACHED() << "Relaunch mutex already exists"; 185 NOTREACHED() << "Relaunch mutex already exists";
185 return false; 186 return false;
186 } 187 }
187 188
188 CommandLine relaunch_cmd(CommandLine::NO_PROGRAM); 189 base::CommandLine relaunch_cmd(base::CommandLine::NO_PROGRAM);
189 relaunch_cmd.AppendSwitchPath(switches::kRelaunchShortcut, 190 relaunch_cmd.AppendSwitchPath(switches::kRelaunchShortcut,
190 ShellIntegration::GetStartMenuShortcut(chrome_exe)); 191 ShellIntegration::GetStartMenuShortcut(chrome_exe));
191 relaunch_cmd.AppendSwitchNative(switches::kWaitForMutex, mutex_name); 192 relaunch_cmd.AppendSwitchNative(switches::kWaitForMutex, mutex_name);
192 193
193 if (relaunch_mode != RELAUNCH_MODE_DEFAULT) { 194 if (relaunch_mode != RELAUNCH_MODE_DEFAULT) {
194 relaunch_cmd.AppendSwitch(relaunch_mode == RELAUNCH_MODE_METRO? 195 relaunch_cmd.AppendSwitch(relaunch_mode == RELAUNCH_MODE_METRO?
195 switches::kForceImmersive : switches::kForceDesktop); 196 switches::kForceImmersive : switches::kForceDesktop);
196 } 197 }
197 198
198 base::string16 params(relaunch_cmd.GetCommandLineString()); 199 base::string16 params(relaunch_cmd.GetCommandLineString());
(...skipping 14 matching lines...) Expand all
213 if (!pid) 214 if (!pid)
214 return false; 215 return false;
215 // The next call appears to be needed if we are relaunching from desktop into 216 // The next call appears to be needed if we are relaunching from desktop into
216 // metro mode. The observed effect if not done is that chrome starts in metro 217 // metro mode. The observed effect if not done is that chrome starts in metro
217 // mode but it is not given focus and it gets killed by windows after a few 218 // mode but it is not given focus and it gets killed by windows after a few
218 // seconds. 219 // seconds.
219 ::AllowSetForegroundWindow(pid); 220 ::AllowSetForegroundWindow(pid);
220 return true; 221 return true;
221 } 222 }
222 223
223 bool RelaunchChromeBrowser(const CommandLine& command_line) { 224 bool RelaunchChromeBrowser(const base::CommandLine& command_line) {
224 return RelaunchChromeHelper(command_line, RELAUNCH_MODE_DEFAULT); 225 return RelaunchChromeHelper(command_line, RELAUNCH_MODE_DEFAULT);
225 } 226 }
226 227
227 bool RelaunchChromeWithMode(const CommandLine& command_line, 228 bool RelaunchChromeWithMode(const base::CommandLine& command_line,
228 const RelaunchMode& relaunch_mode) { 229 const RelaunchMode& relaunch_mode) {
229 return RelaunchChromeHelper(command_line, relaunch_mode); 230 return RelaunchChromeHelper(command_line, relaunch_mode);
230 } 231 }
231 232
232 bool IsUpdatePendingRestart() { 233 bool IsUpdatePendingRestart() {
233 base::FilePath new_chrome_exe; 234 base::FilePath new_chrome_exe;
234 if (!GetNewerChromeFile(&new_chrome_exe)) 235 if (!GetNewerChromeFile(&new_chrome_exe))
235 return false; 236 return false;
236 return base::PathExists(new_chrome_exe); 237 return base::PathExists(new_chrome_exe);
237 } 238 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 mapped_file_name, 287 mapped_file_name,
287 arraysize(mapped_file_name))) { 288 arraysize(mapped_file_name))) {
288 return false; 289 return false;
289 } 290 }
290 291
291 base::FilePath file_name(base::FilePath(mapped_file_name).BaseName()); 292 base::FilePath file_name(base::FilePath(mapped_file_name).BaseName());
292 return base::FilePath::CompareEqualIgnoreCase(file_name.value(), 293 return base::FilePath::CompareEqualIgnoreCase(file_name.value(),
293 installer::kChromeOldExe); 294 installer::kChromeOldExe);
294 } 295 }
295 296
296 bool DoUpgradeTasks(const CommandLine& command_line) { 297 bool DoUpgradeTasks(const base::CommandLine& command_line) {
297 // The DelegateExecute verb handler finalizes pending in-use updates for 298 // The DelegateExecute verb handler finalizes pending in-use updates for
298 // metro mode launches, as Chrome cannot be gracefully relaunched when 299 // metro mode launches, as Chrome cannot be gracefully relaunched when
299 // running in this mode. 300 // running in this mode.
300 if (base::win::IsMetroProcess()) 301 if (base::win::IsMetroProcess())
301 return false; 302 return false;
302 if (!SwapNewChromeExeIfPresent() && !IsRunningOldChrome()) 303 if (!SwapNewChromeExeIfPresent() && !IsRunningOldChrome())
303 return false; 304 return false;
304 // At this point the chrome.exe has been swapped with the new one. 305 // At this point the chrome.exe has been swapped with the new one.
305 if (!RelaunchChromeBrowser(command_line)) { 306 if (!RelaunchChromeBrowser(command_line)) {
306 // The re-launch fails. Feel free to panic now. 307 // The re-launch fails. Feel free to panic now.
307 NOTREACHED(); 308 NOTREACHED();
308 } 309 }
309 return true; 310 return true;
310 } 311 }
311 312
312 } // namespace upgrade_util 313 } // namespace upgrade_util
OLDNEW
« no previous file with comments | « chrome/browser/first_run/upgrade_util_mac.cc ('k') | chrome/browser/fullscreen_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698