• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
9 
10 #include "chrome/installer/util/browser_distribution.h"
11 
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/path_service.h"
17 #include "base/win/registry.h"
18 #include "base/win/windows_version.h"
19 #include "chrome/common/chrome_icon_resources_win.h"
20 #include "chrome/common/env_vars.h"
21 #include "chrome/installer/util/app_registration_data.h"
22 #include "chrome/installer/util/chrome_app_host_distribution.h"
23 #include "chrome/installer/util/chrome_frame_distribution.h"
24 #include "chrome/installer/util/chromium_binaries_distribution.h"
25 #include "chrome/installer/util/google_chrome_binaries_distribution.h"
26 #include "chrome/installer/util/google_chrome_distribution.h"
27 #include "chrome/installer/util/google_chrome_sxs_distribution.h"
28 #include "chrome/installer/util/install_util.h"
29 #include "chrome/installer/util/l10n_string_util.h"
30 #include "chrome/installer/util/master_preferences.h"
31 #include "chrome/installer/util/non_updating_app_registration_data.h"
32 
33 #include "installer_util_strings.h"  // NOLINT
34 
35 using installer::MasterPreferences;
36 
37 namespace {
38 
39 const wchar_t kChromiumActiveSetupGuid[] =
40     L"{7D2B3E1D-D096-4594-9D8F-A6667F12E0AC}";
41 
42 const wchar_t kCommandExecuteImplUuid[] =
43     L"{A2DF06F9-A21A-44A8-8A99-8B9C84F29160}";
44 
45 // The BrowserDistribution objects are never freed.
46 BrowserDistribution* g_browser_distribution = NULL;
47 BrowserDistribution* g_chrome_frame_distribution = NULL;
48 BrowserDistribution* g_binaries_distribution = NULL;
49 BrowserDistribution* g_chrome_app_host_distribution = NULL;
50 
GetCurrentDistributionType()51 BrowserDistribution::Type GetCurrentDistributionType() {
52   // TODO(erikwright): If the app host is installed, but not Chrome, perhaps
53   // this should return CHROME_APP_HOST.
54   return BrowserDistribution::CHROME_BROWSER;
55 }
56 
57 }  // end namespace
58 
BrowserDistribution()59 BrowserDistribution::BrowserDistribution()
60     : type_(CHROME_BROWSER),
61       app_reg_data_(make_scoped_ptr(
62           new NonUpdatingAppRegistrationData(L"Software\\Chromium"))) {
63 }
64 
BrowserDistribution(Type type,scoped_ptr<AppRegistrationData> app_reg_data)65 BrowserDistribution::BrowserDistribution(
66     Type type, scoped_ptr<AppRegistrationData> app_reg_data)
67     : type_(type), app_reg_data_(app_reg_data.Pass()) {
68 }
69 
~BrowserDistribution()70 BrowserDistribution::~BrowserDistribution() {}
71 
72 template<class DistributionClass>
GetOrCreateBrowserDistribution(BrowserDistribution ** dist)73 BrowserDistribution* BrowserDistribution::GetOrCreateBrowserDistribution(
74     BrowserDistribution** dist) {
75   if (!*dist) {
76     DistributionClass* temp = new DistributionClass();
77     if (base::subtle::NoBarrier_CompareAndSwap(
78             reinterpret_cast<base::subtle::AtomicWord*>(dist), NULL,
79             reinterpret_cast<base::subtle::AtomicWord>(temp)) != NULL)
80       delete temp;
81   }
82 
83   return *dist;
84 }
85 
GetDistribution()86 BrowserDistribution* BrowserDistribution::GetDistribution() {
87   return GetSpecificDistribution(GetCurrentDistributionType());
88 }
89 
90 // static
GetSpecificDistribution(BrowserDistribution::Type type)91 BrowserDistribution* BrowserDistribution::GetSpecificDistribution(
92     BrowserDistribution::Type type) {
93   BrowserDistribution* dist = NULL;
94 
95   switch (type) {
96     case CHROME_BROWSER:
97 #if defined(GOOGLE_CHROME_BUILD)
98       if (InstallUtil::IsChromeSxSProcess()) {
99         dist = GetOrCreateBrowserDistribution<GoogleChromeSxSDistribution>(
100             &g_browser_distribution);
101       } else {
102         dist = GetOrCreateBrowserDistribution<GoogleChromeDistribution>(
103             &g_browser_distribution);
104       }
105 #else
106       dist = GetOrCreateBrowserDistribution<BrowserDistribution>(
107           &g_browser_distribution);
108 #endif
109       break;
110 
111     case CHROME_FRAME:
112       dist = GetOrCreateBrowserDistribution<ChromeFrameDistribution>(
113           &g_chrome_frame_distribution);
114       break;
115 
116     case CHROME_APP_HOST:
117       dist = GetOrCreateBrowserDistribution<ChromeAppHostDistribution>(
118           &g_chrome_app_host_distribution);
119       break;
120 
121     default:
122       DCHECK_EQ(CHROME_BINARIES, type);
123 #if defined(GOOGLE_CHROME_BUILD)
124       dist = GetOrCreateBrowserDistribution<GoogleChromeBinariesDistribution>(
125           &g_binaries_distribution);
126 #else
127       dist = GetOrCreateBrowserDistribution<ChromiumBinariesDistribution>(
128           &g_binaries_distribution);
129 #endif
130   }
131 
132   return dist;
133 }
134 
GetAppRegistrationData() const135 const AppRegistrationData& BrowserDistribution::GetAppRegistrationData() const {
136   return *app_reg_data_;
137 }
138 
GetAppGuid() const139 base::string16 BrowserDistribution::GetAppGuid() const {
140   return app_reg_data_->GetAppGuid();
141 }
142 
GetStateKey() const143 base::string16 BrowserDistribution::GetStateKey() const {
144   return app_reg_data_->GetStateKey();
145 }
146 
GetStateMediumKey() const147 base::string16 BrowserDistribution::GetStateMediumKey() const {
148   return app_reg_data_->GetStateMediumKey();
149 }
150 
GetVersionKey() const151 base::string16 BrowserDistribution::GetVersionKey() const {
152   return app_reg_data_->GetVersionKey();
153 }
154 
DoPostUninstallOperations(const Version & version,const base::FilePath & local_data_path,const base::string16 & distribution_data)155 void BrowserDistribution::DoPostUninstallOperations(
156     const Version& version, const base::FilePath& local_data_path,
157     const base::string16& distribution_data) {
158 }
159 
GetActiveSetupGuid()160 base::string16 BrowserDistribution::GetActiveSetupGuid() {
161   return kChromiumActiveSetupGuid;
162 }
163 
GetBaseAppName()164 base::string16 BrowserDistribution::GetBaseAppName() {
165   return L"Chromium";
166 }
167 
GetDisplayName()168 base::string16 BrowserDistribution::GetDisplayName() {
169   return GetShortcutName(SHORTCUT_CHROME);
170 }
171 
GetShortcutName(ShortcutType shortcut_type)172 base::string16 BrowserDistribution::GetShortcutName(
173     ShortcutType shortcut_type) {
174   switch (shortcut_type) {
175     case SHORTCUT_CHROME_ALTERNATE:
176       // TODO(calamity): Change IDS_OEM_MAIN_SHORTCUT_NAME in
177       // chromium_strings.grd to "The Internet" (so that it doesn't collide with
178       // the value in google_chrome_strings.grd) then change this to
179       // installer::GetLocalizedString(IDS_OEM_MAIN_SHORTCUT_NAME_BASE)
180       return L"The Internet";
181     case SHORTCUT_APP_LAUNCHER:
182       return installer::GetLocalizedString(IDS_APP_LIST_SHORTCUT_NAME_BASE);
183     default:
184       DCHECK_EQ(shortcut_type, SHORTCUT_CHROME);
185       return GetBaseAppName();
186   }
187 }
188 
GetIconIndex(ShortcutType shortcut_type)189 int BrowserDistribution::GetIconIndex(ShortcutType shortcut_type) {
190   if (shortcut_type == SHORTCUT_APP_LAUNCHER)
191     return icon_resources::kAppLauncherIndex;
192   DCHECK(shortcut_type == SHORTCUT_CHROME ||
193          shortcut_type == SHORTCUT_CHROME_ALTERNATE) << shortcut_type;
194   return icon_resources::kApplicationIndex;
195 }
196 
GetIconFilename()197 base::string16 BrowserDistribution::GetIconFilename() {
198   return installer::kChromeExe;
199 }
200 
GetStartMenuShortcutSubfolder(Subfolder subfolder_type)201 base::string16 BrowserDistribution::GetStartMenuShortcutSubfolder(
202     Subfolder subfolder_type) {
203   switch (subfolder_type) {
204     case SUBFOLDER_APPS:
205       return installer::GetLocalizedString(IDS_APP_SHORTCUTS_SUBDIR_NAME_BASE);
206     default:
207       DCHECK_EQ(subfolder_type, SUBFOLDER_CHROME);
208       return GetShortcutName(SHORTCUT_CHROME);
209   }
210 }
211 
GetBaseAppId()212 base::string16 BrowserDistribution::GetBaseAppId() {
213   return L"Chromium";
214 }
215 
GetBrowserProgIdPrefix()216 base::string16 BrowserDistribution::GetBrowserProgIdPrefix() {
217   // This used to be "ChromiumHTML", but was forced to become "ChromiumHTM"
218   // because of http://crbug.com/153349.  See the declaration of this function
219   // in the header file for more details.
220   return L"ChromiumHTM";
221 }
222 
GetBrowserProgIdDesc()223 base::string16 BrowserDistribution::GetBrowserProgIdDesc() {
224   return L"Chromium HTML Document";
225 }
226 
227 
GetInstallSubDir()228 base::string16 BrowserDistribution::GetInstallSubDir() {
229   return L"Chromium";
230 }
231 
GetPublisherName()232 base::string16 BrowserDistribution::GetPublisherName() {
233   return L"Chromium";
234 }
235 
GetAppDescription()236 base::string16 BrowserDistribution::GetAppDescription() {
237   return L"Browse the web";
238 }
239 
GetLongAppDescription()240 base::string16 BrowserDistribution::GetLongAppDescription() {
241   const base::string16& app_description =
242       installer::GetLocalizedString(IDS_PRODUCT_DESCRIPTION_BASE);
243   return app_description;
244 }
245 
GetSafeBrowsingName()246 std::string BrowserDistribution::GetSafeBrowsingName() {
247   return "chromium";
248 }
249 
GetNetworkStatsServer() const250 std::string BrowserDistribution::GetNetworkStatsServer() const {
251   return "";
252 }
253 
GetDistributionData(HKEY root_key)254 base::string16 BrowserDistribution::GetDistributionData(HKEY root_key) {
255   return L"";
256 }
257 
GetUninstallLinkName()258 base::string16 BrowserDistribution::GetUninstallLinkName() {
259   return L"Uninstall Chromium";
260 }
261 
GetUninstallRegPath()262 base::string16 BrowserDistribution::GetUninstallRegPath() {
263   return L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Chromium";
264 }
265 
266 BrowserDistribution::DefaultBrowserControlPolicy
GetDefaultBrowserControlPolicy()267     BrowserDistribution::GetDefaultBrowserControlPolicy() {
268   return DEFAULT_BROWSER_FULL_CONTROL;
269 }
270 
CanCreateDesktopShortcuts()271 bool BrowserDistribution::CanCreateDesktopShortcuts() {
272   return true;
273 }
274 
GetChromeChannel(base::string16 * channel)275 bool BrowserDistribution::GetChromeChannel(base::string16* channel) {
276   return false;
277 }
278 
GetCommandExecuteImplClsid(base::string16 * handler_class_uuid)279 bool BrowserDistribution::GetCommandExecuteImplClsid(
280     base::string16* handler_class_uuid) {
281   if (handler_class_uuid)
282     *handler_class_uuid = kCommandExecuteImplUuid;
283   return true;
284 }
285 
AppHostIsSupported()286 bool BrowserDistribution::AppHostIsSupported() {
287   return false;
288 }
289 
UpdateInstallStatus(bool system_install,installer::ArchiveType archive_type,installer::InstallStatus install_status)290 void BrowserDistribution::UpdateInstallStatus(bool system_install,
291     installer::ArchiveType archive_type,
292     installer::InstallStatus install_status) {
293 }
294 
ShouldSetExperimentLabels()295 bool BrowserDistribution::ShouldSetExperimentLabels() {
296   return false;
297 }
298 
HasUserExperiments()299 bool BrowserDistribution::HasUserExperiments() {
300   return false;
301 }
302