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

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

Issue 10699040: Relaunch Chrome in metro-mode with the help of a helper process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ToT Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/shell_integration.h » ('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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/environment.h" 12 #include "base/environment.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/process_util.h" 17 #include "base/process_util.h"
18 #include "base/string_number_conversions.h"
18 #include "base/string_util.h" 19 #include "base/string_util.h"
19 #include "base/win/metro.h" 20 #include "base/win/metro.h"
20 #include "base/win/registry.h" 21 #include "base/win/registry.h"
21 #include "base/win/scoped_comptr.h" 22 #include "base/win/scoped_comptr.h"
22 #include "chrome/browser/first_run/upgrade_util_win.h" 23 #include "chrome/browser/first_run/upgrade_util_win.h"
24 #include "chrome/browser/shell_integration.h"
23 #include "chrome/common/chrome_constants.h" 25 #include "chrome/common/chrome_constants.h"
24 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
25 #include "chrome/installer/util/browser_distribution.h" 27 #include "chrome/installer/util/browser_distribution.h"
26 #include "chrome/installer/util/google_update_constants.h" 28 #include "chrome/installer/util/google_update_constants.h"
27 #include "chrome/installer/util/install_util.h" 29 #include "chrome/installer/util/install_util.h"
28 #include "chrome/installer/util/shell_util.h" 30 #include "chrome/installer/util/shell_util.h"
29 #include "chrome/installer/util/util_constants.h" 31 #include "chrome/installer/util/util_constants.h"
30 #include "google_update/google_update_idl.h" 32 #include "google_update/google_update_idl.h"
31 33
32 namespace { 34 namespace {
(...skipping 20 matching lines...) Expand all
53 DWORD exit_code; 55 DWORD exit_code;
54 ::GetExitCodeProcess(handle, &exit_code); 56 ::GetExitCodeProcess(handle, &exit_code);
55 ::CloseHandle(handle); 57 ::CloseHandle(handle);
56 if (exit_code == installer::RENAME_SUCCESSFUL) 58 if (exit_code == installer::RENAME_SUCCESSFUL)
57 return true; 59 return true;
58 } 60 }
59 } 61 }
60 return false; 62 return false;
61 } 63 }
62 64
65 FilePath GetMetroRelauncherPath(const FilePath& chrome_exe,
66 const std::string version_str) {
67 FilePath path(chrome_exe.DirName());
68
69 // The relauncher is ordinarily in the version directory. When running in a
70 // build tree however (where CHROME_VERSION is not set in the environment)
71 // look for it in Chrome's directory.
72 if (!version_str.empty())
73 path = path.AppendASCII(version_str);
74
75 return path.Append(installer::kDelegateExecuteExe);
76 }
77
63 } // namespace 78 } // namespace
64 79
65 namespace upgrade_util { 80 namespace upgrade_util {
66 81
67 bool RelaunchChromeBrowser(const CommandLine& command_line) { 82 bool RelaunchChromeBrowser(const CommandLine& command_line) {
68 scoped_ptr<base::Environment> env(base::Environment::Create()); 83 scoped_ptr<base::Environment> env(base::Environment::Create());
69 env->UnSetVar(chrome::kChromeVersionEnvVar); 84 std::string version_str;
70 return base::LaunchProcess(command_line, base::LaunchOptions(), NULL); 85
86 // Get the version variable and remove it from the environment.
87 if (env->GetVar(chrome::kChromeVersionEnvVar, &version_str))
88 env->UnSetVar(chrome::kChromeVersionEnvVar);
89 else
90 version_str.clear();
91
92 if (!base::win::IsMetroProcess())
93 return base::LaunchProcess(command_line, base::LaunchOptions(), NULL);
94
95 // Pass this Chrome's Start Menu shortcut path and handle to the relauncher.
96 // The relauncher will wait for this Chrome to exit then reactivate it by
97 // way of the Start Menu shortcut.
98 FilePath chrome_exe;
99 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
100 NOTREACHED();
101 return false;
102 }
103
104 // Get a handle to this process that can be passed to the relauncher.
105 HANDLE current_process = GetCurrentProcess();
106 base::win::ScopedHandle process_handle;
107 if (!::DuplicateHandle(current_process, current_process, current_process,
108 process_handle.Receive(), SYNCHRONIZE, TRUE, 0)) {
109 DPCHECK(false);
110 return false;
111 }
112
113 // Make the command line for the relauncher.
114 CommandLine relaunch_cmd(GetMetroRelauncherPath(chrome_exe, version_str));
115 relaunch_cmd.AppendSwitchPath(switches::kRelaunchShortcut,
116 ShellIntegration::GetStartMenuShortcut(chrome_exe));
117 relaunch_cmd.AppendSwitchNative(switches::kWaitForHandle,
118 base::UintToString16(reinterpret_cast<uint32>(process_handle.Get())));
119
120 base::LaunchOptions launch_options;
121 launch_options.inherit_handles = true;
122 if (!base::LaunchProcess(relaunch_cmd, launch_options, NULL)) {
123 DPLOG(ERROR) << "Failed to launch relauncher \""
124 << relaunch_cmd.GetCommandLineString() << "\"";
125 return false;
126 }
127
128 return true;
71 } 129 }
72 130
73 bool IsUpdatePendingRestart() { 131 bool IsUpdatePendingRestart() {
74 FilePath new_chrome_exe; 132 FilePath new_chrome_exe;
75 if (!GetNewerChromeFile(&new_chrome_exe)) 133 if (!GetNewerChromeFile(&new_chrome_exe))
76 return false; 134 return false;
77 return file_util::PathExists(new_chrome_exe); 135 return file_util::PathExists(new_chrome_exe);
78 } 136 }
79 137
80 bool SwapNewChromeExeIfPresent() { 138 bool SwapNewChromeExeIfPresent() {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return false; 208 return false;
151 // At this point the chrome.exe has been swapped with the new one. 209 // At this point the chrome.exe has been swapped with the new one.
152 if (!RelaunchChromeBrowser(command_line)) { 210 if (!RelaunchChromeBrowser(command_line)) {
153 // The re-launch fails. Feel free to panic now. 211 // The re-launch fails. Feel free to panic now.
154 NOTREACHED(); 212 NOTREACHED();
155 } 213 }
156 return true; 214 return true;
157 } 215 }
158 216
159 } // namespace upgrade_util 217 } // namespace upgrade_util
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/shell_integration.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698