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
3 // found in the LICENSE file.
5 // This file defines specific implementation of BrowserDistribution class for
8 #include "chrome/installer/util/google_chrome_distribution.h"
13 #include "base/files/file_path.h"
14 #include "base/path_service.h"
15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "base/win/registry.h"
19 #include "base/win/windows_version.h"
20 #include "chrome/common/chrome_icon_resources_win.h"
21 #include "chrome/common/net/test_server_locations.h"
22 #include "chrome/installer/util/app_registration_data.h"
23 #include "chrome/installer/util/channel_info.h"
24 #include "chrome/installer/util/google_update_constants.h"
25 #include "chrome/installer/util/google_update_settings.h"
26 #include "chrome/installer/util/helper.h"
27 #include "chrome/installer/util/install_util.h"
28 #include "chrome/installer/util/installer_util_strings.h"
29 #include "chrome/installer/util/l10n_string_util.h"
30 #include "chrome/installer/util/uninstall_metrics.h"
31 #include "chrome/installer/util/updating_app_registration_data.h"
32 #include "chrome/installer/util/util_constants.h"
33 #include "chrome/installer/util/wmi.h"
37 const wchar_t kChromeGuid
[] = L
"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
38 const wchar_t kBrowserAppId
[] = L
"Chrome";
39 const wchar_t kBrowserProgIdPrefix
[] = L
"ChromeHTML";
40 const wchar_t kBrowserProgIdDesc
[] = L
"Chrome HTML Document";
41 const wchar_t kCommandExecuteImplUuid
[] =
42 L
"{5C65F4B0-3651-4514-B207-D10CB699B14B}";
44 // Substitute the locale parameter in uninstall URL with whatever
45 // Google Update tells us is the locale. In case we fail to find
46 // the locale, we use US English.
47 base::string16
LocalizeUrl(const wchar_t* url
) {
48 base::string16 language
;
49 if (!GoogleUpdateSettings::GetLanguage(&language
))
50 language
= L
"en-US"; // Default to US English.
51 return base::ReplaceStringPlaceholders(url
, language
.c_str(), NULL
);
54 base::string16
GetUninstallSurveyUrl() {
55 const wchar_t kSurveyUrl
[] = L
"https://support.google.com/chrome/"
56 L
"contact/chromeuninstall3?hl=$1";
57 return LocalizeUrl(kSurveyUrl
);
62 GoogleChromeDistribution::GoogleChromeDistribution()
63 : BrowserDistribution(CHROME_BROWSER
,
64 scoped_ptr
<AppRegistrationData
>(
65 new UpdatingAppRegistrationData(kChromeGuid
))) {
68 GoogleChromeDistribution::GoogleChromeDistribution(
69 scoped_ptr
<AppRegistrationData
> app_reg_data
)
70 : BrowserDistribution(CHROME_BROWSER
, app_reg_data
.Pass()) {
73 void GoogleChromeDistribution::DoPostUninstallOperations(
74 const Version
& version
,
75 const base::FilePath
& local_data_path
,
76 const base::string16
& distribution_data
) {
77 // Send the Chrome version and OS version as params to the form.
78 // It would be nice to send the locale, too, but I don't see an
79 // easy way to get that in the existing code. It's something we
80 // can add later, if needed.
81 // We depend on installed_version.GetString() not having spaces or other
82 // characters that need escaping: 0.2.13.4. Should that change, we will
83 // need to escape the string before using it in a URL.
84 const base::string16 kVersionParam
= L
"crversion";
85 const base::string16 kOSParam
= L
"os";
86 base::win::OSInfo::VersionNumber version_number
=
87 base::win::OSInfo::GetInstance()->version_number();
88 base::string16 os_version
= base::StringPrintf(L
"%d.%d.%d",
89 version_number
.major
, version_number
.minor
, version_number
.build
);
91 base::FilePath iexplore
;
92 if (!PathService::Get(base::DIR_PROGRAM_FILES
, &iexplore
))
95 iexplore
= iexplore
.AppendASCII("Internet Explorer");
96 iexplore
= iexplore
.AppendASCII("iexplore.exe");
98 base::string16 command
= L
"\"" + iexplore
.value() + L
"\" " +
99 GetUninstallSurveyUrl() +
100 L
"&" + kVersionParam
+ L
"=" + base::ASCIIToUTF16(version
.GetString()) +
101 L
"&" + kOSParam
+ L
"=" + os_version
;
103 base::string16 uninstall_metrics
;
104 if (installer::ExtractUninstallMetricsFromFile(local_data_path
,
105 &uninstall_metrics
)) {
106 // The user has opted into anonymous usage data collection, so append
107 // metrics and distribution data.
108 command
+= uninstall_metrics
;
109 if (!distribution_data
.empty()) {
111 command
+= distribution_data
;
116 // The reason we use WMI to launch the process is because the uninstall
117 // process runs inside a Job object controlled by the shell. As long as there
118 // are processes running, the shell will not close the uninstall applet. WMI
119 // allows us to escape from the Job object so the applet will close.
120 installer::WMIProcess::Launch(command
, &pid
);
123 base::string16
GoogleChromeDistribution::GetActiveSetupGuid() {
127 base::string16
GoogleChromeDistribution::GetBaseAppName() {
128 // I'd really like to return L ## PRODUCT_FULLNAME_STRING; but that's no good
129 // since it'd be "Chromium" in a non-Chrome build, which isn't at all what I
131 return L
"Google Chrome";
134 base::string16
GoogleChromeDistribution::GetShortcutName(
135 ShortcutType shortcut_type
) {
136 int string_id
= IDS_PRODUCT_NAME_BASE
;
137 switch (shortcut_type
) {
138 case SHORTCUT_CHROME_ALTERNATE
:
139 string_id
= IDS_OEM_MAIN_SHORTCUT_NAME_BASE
;
141 case SHORTCUT_APP_LAUNCHER
:
142 string_id
= IDS_APP_LIST_SHORTCUT_NAME_BASE
;
145 DCHECK_EQ(shortcut_type
, SHORTCUT_CHROME
);
148 return installer::GetLocalizedString(string_id
);
151 int GoogleChromeDistribution::GetIconIndex(ShortcutType shortcut_type
) {
152 if (shortcut_type
== SHORTCUT_APP_LAUNCHER
)
153 return icon_resources::kAppLauncherIndex
;
154 DCHECK(shortcut_type
== SHORTCUT_CHROME
||
155 shortcut_type
== SHORTCUT_CHROME_ALTERNATE
) << shortcut_type
;
156 return icon_resources::kApplicationIndex
;
159 base::string16
GoogleChromeDistribution::GetBaseAppId() {
160 return kBrowserAppId
;
163 base::string16
GoogleChromeDistribution::GetBrowserProgIdPrefix() {
164 return kBrowserProgIdPrefix
;
167 base::string16
GoogleChromeDistribution::GetBrowserProgIdDesc() {
168 return kBrowserProgIdDesc
;
171 base::string16
GoogleChromeDistribution::GetInstallSubDir() {
172 base::string16
sub_dir(installer::kGoogleChromeInstallSubDir1
);
173 sub_dir
.append(L
"\\");
174 sub_dir
.append(installer::kGoogleChromeInstallSubDir2
);
178 base::string16
GoogleChromeDistribution::GetPublisherName() {
179 const base::string16
& publisher_name
=
180 installer::GetLocalizedString(IDS_ABOUT_VERSION_COMPANY_NAME_BASE
);
181 return publisher_name
;
184 base::string16
GoogleChromeDistribution::GetAppDescription() {
185 const base::string16
& app_description
=
186 installer::GetLocalizedString(IDS_SHORTCUT_TOOLTIP_BASE
);
187 return app_description
;
190 std::string
GoogleChromeDistribution::GetSafeBrowsingName() {
191 return "googlechrome";
194 std::string
GoogleChromeDistribution::GetNetworkStatsServer() const {
195 return chrome_common_net::kEchoTestServerLocation
;
198 base::string16
GoogleChromeDistribution::GetDistributionData(HKEY root_key
) {
199 base::string16
sub_key(google_update::kRegPathClientState
);
200 sub_key
.append(L
"\\");
201 sub_key
.append(GetAppGuid());
203 base::win::RegKey
client_state_key(
204 root_key
, sub_key
.c_str(), KEY_READ
| KEY_WOW64_32KEY
);
205 base::string16 result
;
206 base::string16 brand_value
;
207 if (client_state_key
.ReadValue(google_update::kRegRLZBrandField
,
208 &brand_value
) == ERROR_SUCCESS
) {
209 result
= google_update::kRegRLZBrandField
;
211 result
.append(brand_value
);
215 base::string16 client_value
;
216 if (client_state_key
.ReadValue(google_update::kRegClientField
,
217 &client_value
) == ERROR_SUCCESS
) {
218 result
.append(google_update::kRegClientField
);
220 result
.append(client_value
);
224 base::string16 ap_value
;
225 // If we fail to read the ap key, send up "&ap=" anyway to indicate
226 // that this was probably a stable channel release.
227 client_state_key
.ReadValue(google_update::kRegApField
, &ap_value
);
228 result
.append(google_update::kRegApField
);
230 result
.append(ap_value
);
235 base::string16
GoogleChromeDistribution::GetUninstallLinkName() {
236 const base::string16
& link_name
=
237 installer::GetLocalizedString(IDS_UNINSTALL_CHROME_BASE
);
241 base::string16
GoogleChromeDistribution::GetUninstallRegPath() {
242 return L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
246 base::string16
GoogleChromeDistribution::GetIconFilename() {
247 return installer::kChromeExe
;
250 bool GoogleChromeDistribution::GetCommandExecuteImplClsid(
251 base::string16
* handler_class_uuid
) {
252 if (handler_class_uuid
)
253 *handler_class_uuid
= kCommandExecuteImplUuid
;
257 // This method checks if we need to change "ap" key in Google Update to try
258 // full installer as fall back method in case incremental installer fails.
259 // - If incremental installer fails we append a magic string ("-full"), if
260 // it is not present already, so that Google Update server next time will send
261 // full installer to update Chrome on the local machine
262 // - If we are currently running full installer, we remove this magic
263 // string (if it is present) regardless of whether installer failed or not.
264 // There is no fall-back for full installer :)
265 void GoogleChromeDistribution::UpdateInstallStatus(bool system_install
,
266 installer::ArchiveType archive_type
,
267 installer::InstallStatus install_status
) {
268 GoogleUpdateSettings::UpdateInstallStatus(system_install
,
269 archive_type
, InstallUtil::GetInstallReturnCode(install_status
),
273 bool GoogleChromeDistribution::ShouldSetExperimentLabels() {
277 bool GoogleChromeDistribution::HasUserExperiments() {