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 <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.h" | |
17 #include "base/process_util.h" | 18 #include "base/process_util.h" |
19 #include "base/string_number_conversions.h" | |
18 #include "base/string_util.h" | 20 #include "base/string_util.h" |
19 #include "base/win/metro.h" | 21 #include "base/win/metro.h" |
20 #include "base/win/registry.h" | 22 #include "base/win/registry.h" |
21 #include "base/win/scoped_comptr.h" | 23 #include "base/win/scoped_comptr.h" |
22 #include "chrome/browser/first_run/upgrade_util_win.h" | 24 #include "chrome/browser/first_run/upgrade_util_win.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" |
(...skipping 25 matching lines...) Expand all Loading... | |
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 GetRelauncherPath(base::Environment* env, | |
cpu_(ooo_6.6-7.5)
2012/06/29 21:32:39
needs a better name, like GetMetroRelauncherPath
grt (UTC plus 2)
2012/07/31 21:44:03
Done.
| |
66 const FilePath& chrome_exe) { | |
67 std::string version_str; | |
68 | |
cpu_(ooo_6.6-7.5)
2012/06/29 21:32:39
kill this empty line
grt (UTC plus 2)
2012/07/31 21:44:03
Done.
| |
69 FilePath path(chrome_exe.DirName()); | |
70 | |
71 // The relauncher is ordinarily in the version directory. When running in a | |
72 // build tree however (where CHROME_VERSION is not set in the environment) | |
73 // look for it in Chrome's directory. | |
74 if (env->GetVar(chrome::kChromeVersionEnvVar, &version_str)) | |
75 path = path.AppendASCII(version_str); | |
76 | |
77 return path.Append(installer::kDelegateExecuteExe); | |
78 } | |
79 | |
63 } // namespace | 80 } // namespace |
64 | 81 |
65 namespace upgrade_util { | 82 namespace upgrade_util { |
66 | 83 |
67 bool RelaunchChromeBrowser(const CommandLine& command_line) { | 84 bool RelaunchChromeBrowser(const CommandLine& command_line) { |
68 scoped_ptr<base::Environment> env(base::Environment::Create()); | 85 scoped_ptr<base::Environment> env(base::Environment::Create()); |
69 env->UnSetVar(chrome::kChromeVersionEnvVar); | 86 |
70 return base::LaunchProcess(command_line, base::LaunchOptions(), NULL); | 87 if (!base::win::IsMetroProcess()) { |
88 env->UnSetVar(chrome::kChromeVersionEnvVar); | |
89 return base::LaunchProcess(command_line, base::LaunchOptions(), NULL); | |
90 } | |
91 | |
92 // Pass this Chrome's handle and AppUserModelID to the relauncher. The | |
93 // relauncher will wait for this Chrome to exit then reactivate it. | |
94 FilePath chrome_exe; | |
95 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | |
96 NOTREACHED(); | |
97 return false; | |
98 } | |
99 | |
100 // Get a handle to this process that can be passed to the relauncher. | |
101 HANDLE current_process = GetCurrentProcess(); | |
102 base::win::ScopedHandle process_handle; | |
103 if (!::DuplicateHandle(current_process, current_process, current_process, | |
104 process_handle.Receive(), SYNCHRONIZE, TRUE, 0)) { | |
105 DPCHECK(false); | |
106 return false; | |
107 } | |
108 | |
109 // Make the command-line for the relauncher. | |
110 CommandLine relaunch_cmd(GetRelauncherPath(env.get(), chrome_exe)); | |
111 relaunch_cmd.AppendSwitchNative(switches::kActivateApp, | |
112 ShellUtil::GetBrowserModelId(BrowserDistribution::GetDistribution(), | |
113 chrome_exe.value())); | |
114 relaunch_cmd.AppendSwitchNative(switches::kWaitForHandle, | |
115 base::PointerToString16(process_handle.Get())); | |
116 | |
117 // Relaunch. | |
118 base::LaunchOptions launch_options; | |
119 launch_options.inherit_handles = true; | |
120 if (!base::LaunchProcess(relaunch_cmd, launch_options, NULL)) { | |
121 DPLOG(ERROR) << "Failed to launch relauncher \"" | |
122 << relaunch_cmd.GetCommandLineString() << "\""; | |
123 return false; | |
124 } | |
125 | |
126 // Ownership of the duplicated handle has been passed to the child process. | |
127 ignore_result(process_handle.Take()); | |
grt (UTC plus 2)
2012/07/31 21:44:03
It's my understanding that both processes need to
| |
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 return false; | 210 return false; |
153 // At this point the chrome.exe has been swapped with the new one. | 211 // At this point the chrome.exe has been swapped with the new one. |
154 if (!RelaunchChromeBrowser(command_line)) { | 212 if (!RelaunchChromeBrowser(command_line)) { |
155 // The re-launch fails. Feel free to panic now. | 213 // The re-launch fails. Feel free to panic now. |
156 NOTREACHED(); | 214 NOTREACHED(); |
157 } | 215 } |
158 return true; | 216 return true; |
159 } | 217 } |
160 | 218 |
161 } // namespace upgrade_util | 219 } // namespace upgrade_util |
OLD | NEW |