Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / installer / util / browser_distribution.cc
blob94578900e055ddf484e51811836e675d17c8d433
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.
4 //
5 // This file defines a class that contains various method related to branding.
6 // It provides only default implementations of these methods. Usually to add
7 // specific branding, we will need to extend this class with a custom
8 // implementation.
10 #include "chrome/installer/util/browser_distribution.h"
12 #include "base/atomicops.h"
13 #include "base/command_line.h"
14 #include "base/files/file_path.h"
15 #include "base/logging.h"
16 #include "base/win/registry.h"
17 #include "base/win/windows_version.h"
18 #include "chrome/common/chrome_icon_resources_win.h"
19 #include "chrome/common/env_vars.h"
20 #include "chrome/installer/util/app_registration_data.h"
21 #include "chrome/installer/util/chrome_frame_distribution.h"
22 #include "chrome/installer/util/chromium_binaries_distribution.h"
23 #include "chrome/installer/util/google_chrome_binaries_distribution.h"
24 #include "chrome/installer/util/google_chrome_distribution.h"
25 #include "chrome/installer/util/google_chrome_sxs_distribution.h"
26 #include "chrome/installer/util/install_util.h"
27 #include "chrome/installer/util/installer_util_strings.h"
28 #include "chrome/installer/util/l10n_string_util.h"
29 #include "chrome/installer/util/master_preferences.h"
30 #include "chrome/installer/util/non_updating_app_registration_data.h"
32 using installer::MasterPreferences;
34 namespace {
36 const wchar_t kChromiumActiveSetupGuid[] =
37 L"{7D2B3E1D-D096-4594-9D8F-A6667F12E0AC}";
39 const wchar_t kCommandExecuteImplUuid[] =
40 L"{A2DF06F9-A21A-44A8-8A99-8B9C84F29160}";
42 // The BrowserDistribution objects are never freed.
43 BrowserDistribution* g_browser_distribution = NULL;
44 BrowserDistribution* g_chrome_frame_distribution = NULL;
45 BrowserDistribution* g_binaries_distribution = NULL;
47 BrowserDistribution::Type GetCurrentDistributionType() {
48 return BrowserDistribution::CHROME_BROWSER;
51 } // namespace
53 BrowserDistribution::BrowserDistribution()
54 : type_(CHROME_BROWSER),
55 app_reg_data_(make_scoped_ptr(
56 new NonUpdatingAppRegistrationData(L"Software\\Chromium"))) {
59 BrowserDistribution::BrowserDistribution(
60 Type type, scoped_ptr<AppRegistrationData> app_reg_data)
61 : type_(type), app_reg_data_(app_reg_data.Pass()) {
64 BrowserDistribution::~BrowserDistribution() {}
66 template<class DistributionClass>
67 BrowserDistribution* BrowserDistribution::GetOrCreateBrowserDistribution(
68 BrowserDistribution** dist) {
69 if (!*dist) {
70 DistributionClass* temp = new DistributionClass();
71 if (base::subtle::NoBarrier_CompareAndSwap(
72 reinterpret_cast<base::subtle::AtomicWord*>(dist), NULL,
73 reinterpret_cast<base::subtle::AtomicWord>(temp)) != NULL)
74 delete temp;
77 return *dist;
80 BrowserDistribution* BrowserDistribution::GetDistribution() {
81 return GetSpecificDistribution(GetCurrentDistributionType());
84 // static
85 BrowserDistribution* BrowserDistribution::GetSpecificDistribution(
86 BrowserDistribution::Type type) {
87 BrowserDistribution* dist = NULL;
89 switch (type) {
90 case CHROME_BROWSER:
91 #if defined(GOOGLE_CHROME_BUILD)
92 if (InstallUtil::IsChromeSxSProcess()) {
93 dist = GetOrCreateBrowserDistribution<GoogleChromeSxSDistribution>(
94 &g_browser_distribution);
95 } else {
96 dist = GetOrCreateBrowserDistribution<GoogleChromeDistribution>(
97 &g_browser_distribution);
99 #else
100 dist = GetOrCreateBrowserDistribution<BrowserDistribution>(
101 &g_browser_distribution);
102 #endif
103 break;
105 case CHROME_FRAME:
106 dist = GetOrCreateBrowserDistribution<ChromeFrameDistribution>(
107 &g_chrome_frame_distribution);
108 break;
110 default:
111 DCHECK_EQ(CHROME_BINARIES, type);
112 #if defined(GOOGLE_CHROME_BUILD)
113 dist = GetOrCreateBrowserDistribution<GoogleChromeBinariesDistribution>(
114 &g_binaries_distribution);
115 #else
116 dist = GetOrCreateBrowserDistribution<ChromiumBinariesDistribution>(
117 &g_binaries_distribution);
118 #endif
121 return dist;
124 const AppRegistrationData& BrowserDistribution::GetAppRegistrationData() const {
125 return *app_reg_data_;
128 base::string16 BrowserDistribution::GetAppGuid() const {
129 return app_reg_data_->GetAppGuid();
132 base::string16 BrowserDistribution::GetStateKey() const {
133 return app_reg_data_->GetStateKey();
136 base::string16 BrowserDistribution::GetStateMediumKey() const {
137 return app_reg_data_->GetStateMediumKey();
140 base::string16 BrowserDistribution::GetVersionKey() const {
141 return app_reg_data_->GetVersionKey();
144 void BrowserDistribution::DoPostUninstallOperations(
145 const Version& version, const base::FilePath& local_data_path,
146 const base::string16& distribution_data) {
149 base::string16 BrowserDistribution::GetActiveSetupGuid() {
150 return kChromiumActiveSetupGuid;
153 base::string16 BrowserDistribution::GetBaseAppName() {
154 return L"Chromium";
157 base::string16 BrowserDistribution::GetDisplayName() {
158 return GetShortcutName(SHORTCUT_CHROME);
161 base::string16 BrowserDistribution::GetShortcutName(
162 ShortcutType shortcut_type) {
163 switch (shortcut_type) {
164 case SHORTCUT_CHROME_ALTERNATE:
165 // TODO(calamity): Change IDS_OEM_MAIN_SHORTCUT_NAME in
166 // chromium_strings.grd to "The Internet" (so that it doesn't collide with
167 // the value in google_chrome_strings.grd) then change this to
168 // installer::GetLocalizedString(IDS_OEM_MAIN_SHORTCUT_NAME_BASE)
169 return L"The Internet";
170 case SHORTCUT_APP_LAUNCHER:
171 return installer::GetLocalizedString(IDS_APP_LIST_SHORTCUT_NAME_BASE);
172 default:
173 DCHECK_EQ(shortcut_type, SHORTCUT_CHROME);
174 return GetBaseAppName();
178 int BrowserDistribution::GetIconIndex(ShortcutType shortcut_type) {
179 if (shortcut_type == SHORTCUT_APP_LAUNCHER)
180 return icon_resources::kAppLauncherIndex;
181 DCHECK(shortcut_type == SHORTCUT_CHROME ||
182 shortcut_type == SHORTCUT_CHROME_ALTERNATE) << shortcut_type;
183 return icon_resources::kApplicationIndex;
186 base::string16 BrowserDistribution::GetIconFilename() {
187 return installer::kChromeExe;
190 base::string16 BrowserDistribution::GetStartMenuShortcutSubfolder(
191 Subfolder subfolder_type) {
192 switch (subfolder_type) {
193 case SUBFOLDER_APPS:
194 return installer::GetLocalizedString(IDS_APP_SHORTCUTS_SUBDIR_NAME_BASE);
195 default:
196 DCHECK_EQ(subfolder_type, SUBFOLDER_CHROME);
197 return GetShortcutName(SHORTCUT_CHROME);
201 base::string16 BrowserDistribution::GetBaseAppId() {
202 return L"Chromium";
205 base::string16 BrowserDistribution::GetBrowserProgIdPrefix() {
206 // This used to be "ChromiumHTML", but was forced to become "ChromiumHTM"
207 // because of http://crbug.com/153349. See the declaration of this function
208 // in the header file for more details.
209 return L"ChromiumHTM";
212 base::string16 BrowserDistribution::GetBrowserProgIdDesc() {
213 return L"Chromium HTML Document";
217 base::string16 BrowserDistribution::GetInstallSubDir() {
218 return L"Chromium";
221 base::string16 BrowserDistribution::GetPublisherName() {
222 return L"Chromium";
225 base::string16 BrowserDistribution::GetAppDescription() {
226 return L"Browse the web";
229 base::string16 BrowserDistribution::GetLongAppDescription() {
230 const base::string16& app_description =
231 installer::GetLocalizedString(IDS_PRODUCT_DESCRIPTION_BASE);
232 return app_description;
235 std::string BrowserDistribution::GetSafeBrowsingName() {
236 return "chromium";
239 std::string BrowserDistribution::GetNetworkStatsServer() const {
240 return "";
243 base::string16 BrowserDistribution::GetDistributionData(HKEY root_key) {
244 return L"";
247 base::string16 BrowserDistribution::GetUninstallLinkName() {
248 return L"Uninstall Chromium";
251 base::string16 BrowserDistribution::GetUninstallRegPath() {
252 return L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Chromium";
255 BrowserDistribution::DefaultBrowserControlPolicy
256 BrowserDistribution::GetDefaultBrowserControlPolicy() {
257 return DEFAULT_BROWSER_FULL_CONTROL;
260 bool BrowserDistribution::CanCreateDesktopShortcuts() {
261 return true;
264 bool BrowserDistribution::GetChromeChannel(base::string16* channel) {
265 return false;
268 bool BrowserDistribution::GetCommandExecuteImplClsid(
269 base::string16* handler_class_uuid) {
270 if (handler_class_uuid)
271 *handler_class_uuid = kCommandExecuteImplUuid;
272 return true;
275 void BrowserDistribution::UpdateInstallStatus(bool system_install,
276 installer::ArchiveType archive_type,
277 installer::InstallStatus install_status) {
280 bool BrowserDistribution::ShouldSetExperimentLabels() {
281 return false;
284 bool BrowserDistribution::HasUserExperiments() {
285 return false;