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

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: more removals from sam Created 6 years, 5 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
19 #include "base/path_service.h"
20 #endif
21
22 namespace chrome_launcher_support { 14 namespace chrome_launcher_support {
23 15
24 namespace { 16 namespace {
25 17
26 // TODO(huangs) Refactor the constants: http://crbug.com/148538 18 // TODO(huangs) Refactor the constants: http://crbug.com/148538
27 const wchar_t kGoogleRegClientStateKey[] = 19 const wchar_t kGoogleRegClientStateKey[] =
28 L"Software\\Google\\Update\\ClientState"; 20 L"Software\\Google\\Update\\ClientState";
29 const wchar_t kGoogleRegClientsKey[] = L"Software\\Google\\Update\\Clients";
30 const wchar_t kRegVersionField[] = L"pv";
31 21
32 // Copied from chrome_appid.cc. 22 // Copied from chrome_appid.cc.
33 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; 23 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
34 24
35 // Copied from google_chrome_distribution.cc. 25 // Copied from google_chrome_distribution.cc.
36 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 26 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
37 27
38 // Copied frome google_chrome_sxs_distribution.cc.
39 const wchar_t kSxSBrowserAppGuid[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
40
41 // Copied from util_constants.cc. 28 // 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"; 29 const wchar_t kChromeExe[] = L"chrome.exe";
45 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
46 const wchar_t kUninstallStringField[] = L"UninstallString"; 30 const wchar_t kUninstallStringField[] = L"UninstallString";
47 31
48 // Reads a string value from the specified product's "ClientState" registry key. 32 // Reads a string value from the specified product's "ClientState" registry key.
49 // Returns true iff the value is present and successfully read. 33 // Returns true iff the value is present and successfully read.
50 bool GetClientStateValue(InstallationLevel level, 34 bool GetClientStateValue(InstallationLevel level,
51 const wchar_t* app_guid, 35 const wchar_t* app_guid,
52 const wchar_t* value_name, 36 const wchar_t* value_name,
53 base::string16* value) { 37 base::string16* value) {
54 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ? 38 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ?
55 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 39 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
56 base::string16 subkey(kGoogleRegClientStateKey); 40 base::string16 subkey(kGoogleRegClientStateKey);
57 subkey.append(1, L'\\').append(app_guid); 41 subkey.append(1, L'\\').append(app_guid);
58 base::win::RegKey reg_key; 42 base::win::RegKey reg_key;
59 // Google Update always uses 32bit hive. 43 // Google Update always uses 32bit hive.
60 if (reg_key.Open(root_key, subkey.c_str(), 44 if (reg_key.Open(root_key, subkey.c_str(),
61 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { 45 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
62 if (reg_key.ReadValue(value_name, value) == ERROR_SUCCESS) { 46 if (reg_key.ReadValue(value_name, value) == ERROR_SUCCESS) {
63 return true; 47 return true;
64 } 48 }
65 } 49 }
66 return false; 50 return false;
67 } 51 }
68 52
69 // Determines whether the specified product has a key in "Clients". This
70 // indicates whether the product is installed at the given level.
71 bool IsProductInstalled(InstallationLevel level, const wchar_t* app_guid) {
72 HKEY root_key = (level == USER_LEVEL_INSTALLATION) ?
73 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
74 base::string16 subkey(kGoogleRegClientsKey);
75 subkey.append(1, L'\\').append(app_guid);
76 base::win::RegKey reg_key;
77 // Google Update always uses 32bit hive.
78 return reg_key.Open(root_key, subkey.c_str(),
79 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS &&
80 reg_key.HasValue(kRegVersionField);
81 }
82
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 53 // Reads the path to setup.exe from the value "UninstallString" within the
97 // specified product's "ClientState" registry key. Returns an empty FilePath if 54 // 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. 55 // an error occurs or the product is not installed at the specified level.
99 base::FilePath GetSetupExeFromRegistry(InstallationLevel level, 56 base::FilePath GetSetupExeFromRegistry(InstallationLevel level,
100 const wchar_t* app_guid) { 57 const wchar_t* app_guid) {
101 base::string16 uninstall; 58 base::string16 uninstall;
102 if (GetClientStateValue(level, app_guid, kUninstallStringField, &uninstall)) { 59 if (GetClientStateValue(level, app_guid, kUninstallStringField, &uninstall)) {
103 base::FilePath setup_exe_path(uninstall); 60 base::FilePath setup_exe_path(uninstall);
104 if (base::PathExists(setup_exe_path)) 61 if (base::PathExists(setup_exe_path))
105 return setup_exe_path; 62 return setup_exe_path;
106 } 63 }
107 return base::FilePath(); 64 return base::FilePath();
108 } 65 }
109 66
110 // Returns the path to an installed |exe_file| (e.g. chrome.exe, app_host.exe) 67 // Returns the path to an existing setup.exe at the specified level, if it can
111 // at the specified level, given |setup_exe_path| from Omaha client state. 68 // be found via Omaha client state.
112 // Returns empty base::FilePath if none found, or if |setup_exe_path| is empty. 69 base::FilePath GetSetupExeForInstallationLevel(InstallationLevel level) {
70 // Look in the registry for Chrome Binaries first.
71 base::FilePath setup_exe_path(
72 GetSetupExeFromRegistry(level, kBinariesAppGuid));
73 // If the above fails, look in the registry for Chrome next.
74 if (setup_exe_path.empty())
75 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid);
76 // If we fail again, then setup_exe_path would be empty.
77 return setup_exe_path;
78 }
79
80 // Returns the path to an installed |exe_file| (e.g. chrome.exe) at the
81 // specified level, given |setup_exe_path| from Omaha client state. Returns
82 // empty base::FilePath if none found, or if |setup_exe_path| is empty.
113 base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path, 83 base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path,
114 const wchar_t* exe_file) { 84 const wchar_t* exe_file) {
115 if (!setup_exe_path.empty()) { 85 if (!setup_exe_path.empty()) {
116 // The uninstall path contains the path to setup.exe, which is two levels 86 // 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 87 // down from |exe_file|. Move up two levels (plus one to drop the file
118 // name) and look for chrome.exe from there. 88 // name) and look for chrome.exe from there.
119 base::FilePath exe_path( 89 base::FilePath exe_path(
120 setup_exe_path.DirName().DirName().DirName().Append(exe_file)); 90 setup_exe_path.DirName().DirName().DirName().Append(exe_file));
121 if (base::PathExists(exe_path)) 91 if (base::PathExists(exe_path))
122 return exe_path; 92 return exe_path;
123 // By way of mild future proofing, look up one to see if there's a 93 // By way of mild future proofing, look up one to see if there's a
124 // |exe_file| in the version directory 94 // |exe_file| in the version directory
125 exe_path = setup_exe_path.DirName().DirName().Append(exe_file); 95 exe_path = setup_exe_path.DirName().DirName().Append(exe_file);
126 if (base::PathExists(exe_path)) 96 if (base::PathExists(exe_path))
127 return exe_path; 97 return exe_path;
128 } 98 }
129 return base::FilePath(); 99 return base::FilePath();
130 } 100 }
131 101
132 } // namespace 102 } // namespace
133 103
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) {
155 // Look in the registry for Chrome Binaries first.
156 base::FilePath setup_exe_path(
157 GetSetupExeFromRegistry(level, kBinariesAppGuid));
158 // If the above fails, look in the registry for Chrome next.
159 if (setup_exe_path.empty())
160 setup_exe_path = GetSetupExeFromRegistry(level, kBrowserAppGuid);
161 // If we fail again, then setup_exe_path would be empty.
162 return setup_exe_path;
163 }
164
165 base::FilePath GetChromePathForInstallationLevel(InstallationLevel level) { 104 base::FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
166 return FindExeRelativeToSetupExe( 105 return FindExeRelativeToSetupExe(
167 GetSetupExeForInstallationLevel(level), kChromeExe); 106 GetSetupExeForInstallationLevel(level), kChromeExe);
168 } 107 }
169 108
170 base::FilePath GetAppHostPathForInstallationLevel(InstallationLevel level) {
171 return FindExeRelativeToSetupExe(
172 GetSetupExeFromRegistry(level, kAppLauncherGuid), kChromeAppHostExe);
173 }
174
175 base::FilePath GetChromeSxSPathForInstallationLevel(InstallationLevel level) {
176 return FindExeRelativeToSetupExe(
177 GetSetupExeFromRegistry(level, kSxSBrowserAppGuid), kChromeExe);
178 }
179
180 base::FilePath GetAnyChromePath() { 109 base::FilePath GetAnyChromePath() {
181 base::FilePath chrome_path; 110 base::FilePath chrome_path;
182 if (chrome_path.empty()) 111 if (chrome_path.empty())
183 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); 112 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
184 if (chrome_path.empty()) 113 if (chrome_path.empty())
185 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); 114 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION);
186 return chrome_path; 115 return chrome_path;
187 } 116 }
188 117
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() {
201 base::FilePath path =
202 GetChromeSxSPathForInstallationLevel(USER_LEVEL_INSTALLATION);
203 if (path.empty())
204 path = GetChromeSxSPathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
205 return path;
206 }
207
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() {
228 return IsProductInstalled(USER_LEVEL_INSTALLATION, kBrowserAppGuid) ||
229 IsProductInstalled(SYSTEM_LEVEL_INSTALLATION, kBrowserAppGuid);
230 }
231
232 } // namespace chrome_launcher_support 118 } // namespace chrome_launcher_support
OLDNEW
« no previous file with comments | « chrome/installer/launcher_support/chrome_launcher_support.h ('k') | chrome/installer/setup/install.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698