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

Side by Side Diff: chrome/installer/launcher_support/chrome_launcher_support.cc

Issue 422453004: Remove some dead app host code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
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/installer/launcher_support/chrome_launcher_support.h" 5 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <tchar.h>
9 8
10 #include "base/command_line.h"
11 #include "base/file_util.h" 9 #include "base/file_util.h"
12 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
13 #include "base/logging.h"
14 #include "base/process/launch.h"
15 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
16 #include "base/win/registry.h" 12 #include "base/win/registry.h"
17 13
18 #ifndef OFFICIAL_BUILD 14 #ifndef OFFICIAL_BUILD
19 #include "base/path_service.h" 15 #include "base/path_service.h"
20 #endif 16 #endif
21 17
22 namespace chrome_launcher_support { 18 namespace chrome_launcher_support {
23 19
24 namespace { 20 namespace {
25 21
26 // TODO(huangs) Refactor the constants: http://crbug.com/148538 22 // TODO(huangs) Refactor the constants: http://crbug.com/148538
27 const wchar_t kGoogleRegClientStateKey[] = 23 const wchar_t kGoogleRegClientStateKey[] =
28 L"Software\\Google\\Update\\ClientState"; 24 L"Software\\Google\\Update\\ClientState";
29 const wchar_t kGoogleRegClientsKey[] = L"Software\\Google\\Update\\Clients"; 25 const wchar_t kGoogleRegClientsKey[] = L"Software\\Google\\Update\\Clients";
30 const wchar_t kRegVersionField[] = L"pv"; 26 const wchar_t kRegVersionField[] = L"pv";
31 27
32 // Copied from chrome_appid.cc. 28 // Copied from chrome_appid.cc.
33 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; 29 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
34 30
35 // Copied from google_chrome_distribution.cc. 31 // Copied from google_chrome_distribution.cc.
36 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 32 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
37 33
38 // Copied frome google_chrome_sxs_distribution.cc. 34 // Copied frome google_chrome_sxs_distribution.cc.
39 const wchar_t kSxSBrowserAppGuid[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; 35 const wchar_t kSxSBrowserAppGuid[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
40 36
41 // Copied from util_constants.cc. 37 // Copied from util_constants.cc.
42 const wchar_t kChromeAppHostExe[] = L"app_host.exe";
43 const char kChromeAppLauncher[] = "app-launcher";
44 const wchar_t kChromeExe[] = L"chrome.exe"; 38 const wchar_t kChromeExe[] = L"chrome.exe";
45 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
46 const wchar_t kUninstallStringField[] = L"UninstallString"; 39 const wchar_t kUninstallStringField[] = L"UninstallString";
47 40
48 // Reads a string value from the specified product's "ClientState" registry key. 41 // Reads a string value from the specified product's "ClientState" registry key.
49 // Returns true iff the value is present and successfully read. 42 // Returns true iff the value is present and successfully read.
50 bool GetClientStateValue(InstallationLevel level, 43 bool GetClientStateValue(InstallationLevel level,
51 const wchar_t* app_guid, 44 const wchar_t* app_guid,
52 const wchar_t* value_name, 45 const wchar_t* value_name,
53 base::string16* value) { 46 base::string16* value) {
54 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ? 47 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ?
55 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 48 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
(...skipping 17 matching lines...) Expand all
73 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 66 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
74 base::string16 subkey(kGoogleRegClientsKey); 67 base::string16 subkey(kGoogleRegClientsKey);
75 subkey.append(1, L'\\').append(app_guid); 68 subkey.append(1, L'\\').append(app_guid);
76 base::win::RegKey reg_key; 69 base::win::RegKey reg_key;
77 // Google Update always uses 32bit hive. 70 // Google Update always uses 32bit hive.
78 return reg_key.Open(root_key, subkey.c_str(), 71 return reg_key.Open(root_key, subkey.c_str(),
79 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS && 72 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS &&
80 reg_key.HasValue(kRegVersionField); 73 reg_key.HasValue(kRegVersionField);
81 } 74 }
82 75
83 bool IsAppLauncherEnabledAtLevel(InstallationLevel level) {
84 base::string16 uninstall_arguments;
85 if (GetClientStateValue(level,
86 kAppLauncherGuid,
87 kUninstallArgumentsField,
88 &uninstall_arguments)) {
89 return CommandLine::FromString(L"dummy.exe " + uninstall_arguments)
90 .HasSwitch(kChromeAppLauncher) &&
91 !GetAppHostPathForInstallationLevel(level).empty();
92 }
93 return false;
94 }
95
96 // Reads the path to setup.exe from the value "UninstallString" within the 76 // Reads the path to setup.exe from the value "UninstallString" within the
97 // specified product's "ClientState" registry key. Returns an empty FilePath if 77 // specified product's "ClientState" registry key. Returns an empty FilePath if
98 // an error occurs or the product is not installed at the specified level. 78 // an error occurs or the product is not installed at the specified level.
99 base::FilePath GetSetupExeFromRegistry(InstallationLevel level, 79 base::FilePath GetSetupExeFromRegistry(InstallationLevel level,
100 const wchar_t* app_guid) { 80 const wchar_t* app_guid) {
101 base::string16 uninstall; 81 base::string16 uninstall;
102 if (GetClientStateValue(level, app_guid, kUninstallStringField, &uninstall)) { 82 if (GetClientStateValue(level, app_guid, kUninstallStringField, &uninstall)) {
103 base::FilePath setup_exe_path(uninstall); 83 base::FilePath setup_exe_path(uninstall);
104 if (base::PathExists(setup_exe_path)) 84 if (base::PathExists(setup_exe_path))
105 return setup_exe_path; 85 return setup_exe_path;
106 } 86 }
107 return base::FilePath(); 87 return base::FilePath();
108 } 88 }
109 89
110 // Returns the path to an installed |exe_file| (e.g. chrome.exe, app_host.exe) 90 // Returns the path to an installed |exe_file| (e.g. chrome.exe) at the
111 // at the specified level, given |setup_exe_path| from Omaha client state. 91 // specified level, given |setup_exe_path| from Omaha client state. Returns
112 // Returns empty base::FilePath if none found, or if |setup_exe_path| is empty. 92 // empty base::FilePath if none found, or if |setup_exe_path| is empty.
113 base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path, 93 base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path,
114 const wchar_t* exe_file) { 94 const wchar_t* exe_file) {
115 if (!setup_exe_path.empty()) { 95 if (!setup_exe_path.empty()) {
116 // The uninstall path contains the path to setup.exe, which is two levels 96 // The uninstall path contains the path to setup.exe, which is two levels
117 // down from |exe_file|. Move up two levels (plus one to drop the file 97 // down from |exe_file|. Move up two levels (plus one to drop the file
118 // name) and look for chrome.exe from there. 98 // name) and look for chrome.exe from there.
119 base::FilePath exe_path( 99 base::FilePath exe_path(
120 setup_exe_path.DirName().DirName().DirName().Append(exe_file)); 100 setup_exe_path.DirName().DirName().DirName().Append(exe_file));
121 if (base::PathExists(exe_path)) 101 if (base::PathExists(exe_path))
122 return exe_path; 102 return exe_path;
123 // By way of mild future proofing, look up one to see if there's a 103 // By way of mild future proofing, look up one to see if there's a
124 // |exe_file| in the version directory 104 // |exe_file| in the version directory
125 exe_path = setup_exe_path.DirName().DirName().Append(exe_file); 105 exe_path = setup_exe_path.DirName().DirName().Append(exe_file);
126 if (base::PathExists(exe_path)) 106 if (base::PathExists(exe_path))
127 return exe_path; 107 return exe_path;
128 } 108 }
129 return base::FilePath(); 109 return base::FilePath();
130 } 110 }
131 111
132 } // namespace 112 } // namespace
133 113
134 const wchar_t kAppLauncherGuid[] = L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}";
135
136 void UninstallLegacyAppLauncher(InstallationLevel level) {
137 base::FilePath setup_exe(GetSetupExeFromRegistry(level, kAppLauncherGuid));
138 if (setup_exe.empty())
139 return;
140 base::string16 uninstall_arguments;
141 if (GetClientStateValue(level,
142 kAppLauncherGuid,
143 kUninstallArgumentsField,
144 &uninstall_arguments)) {
145 CommandLine uninstall_cmd = CommandLine::FromString(
146 L"\"" + setup_exe.value() + L"\" " + uninstall_arguments);
147
148 VLOG(1) << "Uninstalling legacy app launcher with command line: "
149 << uninstall_cmd.GetCommandLineString();
150 base::LaunchProcess(uninstall_cmd, base::LaunchOptions(), NULL);
151 }
152 }
153
154 base::FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { 114 base::FilePath GetSetupExeForInstallationLevel(InstallationLevel level) {
155 // Look in the registry for Chrome Binaries first. 115 // Look in the registry for Chrome Binaries first.
156 base::FilePath setup_exe_path( 116 base::FilePath setup_exe_path(
157 GetSetupExeFromRegistry(level, kBinariesAppGuid)); 117 GetSetupExeFromRegistry(level, kBinariesAppGuid));
158 // If the above fails, look in the registry for Chrome next. 118 // If the above fails, look in the registry for Chrome next.
159 if (setup_exe_path.empty()) 119 if (setup_exe_path.empty())
160 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid); 120 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid);
161 // If we fail again, then setup_exe_path would be empty. 121 // If we fail again, then setup_exe_path would be empty.
162 return setup_exe_path; 122 return setup_exe_path;
163 } 123 }
164 124
165 base::FilePath GetChromePathForInstallationLevel(InstallationLevel level) { 125 base::FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
166 return FindExeRelativeToSetupExe( 126 return FindExeRelativeToSetupExe(
167 GetSetupExeForInstallationLevel(level), kChromeExe); 127 GetSetupExeForInstallationLevel(level), kChromeExe);
168 } 128 }
169 129
170 base::FilePath GetAppHostPathForInstallationLevel(InstallationLevel level) {
171 return FindExeRelativeToSetupExe(
172 GetSetupExeFromRegistry(level, kAppLauncherGuid), kChromeAppHostExe);
173 }
174
175 base::FilePath GetChromeSxSPathForInstallationLevel(InstallationLevel level) { 130 base::FilePath GetChromeSxSPathForInstallationLevel(InstallationLevel level) {
176 return FindExeRelativeToSetupExe( 131 return FindExeRelativeToSetupExe(
177 GetSetupExeFromRegistry(level, kSxSBrowserAppGuid), kChromeExe); 132 GetSetupExeFromRegistry(level, kSxSBrowserAppGuid), kChromeExe);
178 } 133 }
179 134
180 base::FilePath GetAnyChromePath() { 135 base::FilePath GetAnyChromePath() {
181 base::FilePath chrome_path; 136 base::FilePath chrome_path;
182 if (chrome_path.empty()) 137 if (chrome_path.empty())
183 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); 138 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
184 if (chrome_path.empty()) 139 if (chrome_path.empty())
185 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); 140 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION);
186 return chrome_path; 141 return chrome_path;
187 } 142 }
188 143
189 base::FilePath GetAnyAppHostPath() {
190 base::FilePath app_host_path;
191 if (app_host_path.empty()) {
192 app_host_path = GetAppHostPathForInstallationLevel(
193 SYSTEM_LEVEL_INSTALLATION);
194 }
195 if (app_host_path.empty())
196 app_host_path = GetAppHostPathForInstallationLevel(USER_LEVEL_INSTALLATION);
197 return app_host_path;
198 }
199
200 base::FilePath GetAnyChromeSxSPath() { 144 base::FilePath GetAnyChromeSxSPath() {
201 base::FilePath path = 145 base::FilePath path =
202 GetChromeSxSPathForInstallationLevel(USER_LEVEL_INSTALLATION); 146 GetChromeSxSPathForInstallationLevel(USER_LEVEL_INSTALLATION);
203 if (path.empty()) 147 if (path.empty())
204 path = GetChromeSxSPathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); 148 path = GetChromeSxSPathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
205 return path; 149 return path;
206 } 150 }
207 151
208 bool IsAppHostPresent() {
209 base::FilePath app_host_exe = GetAnyAppHostPath();
210 return !app_host_exe.empty();
211 }
212
213 InstallationState GetAppLauncherInstallationState() {
214 if (IsAppLauncherEnabledAtLevel(SYSTEM_LEVEL_INSTALLATION))
215 return INSTALLED_AT_SYSTEM_LEVEL;
216
217 if (IsAppLauncherEnabledAtLevel(USER_LEVEL_INSTALLATION))
218 return INSTALLED_AT_USER_LEVEL;
219
220 return NOT_INSTALLED;
221 }
222
223 bool IsAppLauncherPresent() {
224 return GetAppLauncherInstallationState() != NOT_INSTALLED;
225 }
226
227 bool IsChromeBrowserPresent() { 152 bool IsChromeBrowserPresent() {
228 return IsProductInstalled(USER_LEVEL_INSTALLATION, kBrowserAppGuid) || 153 return IsProductInstalled(USER_LEVEL_INSTALLATION, kBrowserAppGuid) ||
229 IsProductInstalled(SYSTEM_LEVEL_INSTALLATION, kBrowserAppGuid); 154 IsProductInstalled(SYSTEM_LEVEL_INSTALLATION, kBrowserAppGuid);
230 } 155 }
231 156
232 } // namespace chrome_launcher_support 157 } // namespace chrome_launcher_support
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698