[Android] Added UMA for search by image context menu.
[chromium-blink-merge.git] / chrome / installer / util / browser_distribution.cc
blob4f711419db140c7338e7eeaeef6331f99c93f301
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/path_service.h"
17 #include "base/win/registry.h"
18 #include "base/win/windows_version.h"
19 #include "chrome/common/env_vars.h"
20 #include "chrome/installer/util/chrome_app_host_distribution.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/l10n_string_util.h"
28 #include "chrome/installer/util/master_preferences.h"
30 #include "installer_util_strings.h" // NOLINT
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;
46 BrowserDistribution* g_chrome_app_host_distribution = NULL;
48 // Returns true if currently running in npchrome_frame.dll
49 bool IsChromeFrameModule() {
50 base::FilePath module_path;
51 PathService::Get(base::FILE_MODULE, &module_path);
52 return base::FilePath::CompareEqualIgnoreCase(module_path.BaseName().value(),
53 installer::kChromeFrameDll);
56 BrowserDistribution::Type GetCurrentDistributionType() {
57 // TODO(erikwright): If the app host is installed, but not Chrome, perhaps
58 // this should return CHROME_APP_HOST.
59 static BrowserDistribution::Type type =
60 (MasterPreferences::ForCurrentProcess().install_chrome_frame() ||
61 IsChromeFrameModule()) ?
62 BrowserDistribution::CHROME_FRAME :
63 BrowserDistribution::CHROME_BROWSER;
64 return type;
67 } // end namespace
69 BrowserDistribution::BrowserDistribution()
70 : type_(CHROME_BROWSER) {
73 BrowserDistribution::BrowserDistribution(Type type)
74 : type_(type) {
77 template<class DistributionClass>
78 BrowserDistribution* BrowserDistribution::GetOrCreateBrowserDistribution(
79 BrowserDistribution** dist) {
80 if (!*dist) {
81 DistributionClass* temp = new DistributionClass();
82 if (base::subtle::NoBarrier_CompareAndSwap(
83 reinterpret_cast<base::subtle::AtomicWord*>(dist), NULL,
84 reinterpret_cast<base::subtle::AtomicWord>(temp)) != NULL)
85 delete temp;
88 return *dist;
91 BrowserDistribution* BrowserDistribution::GetDistribution() {
92 return GetSpecificDistribution(GetCurrentDistributionType());
95 // static
96 BrowserDistribution* BrowserDistribution::GetSpecificDistribution(
97 BrowserDistribution::Type type) {
98 BrowserDistribution* dist = NULL;
100 switch (type) {
101 case CHROME_BROWSER:
102 #if defined(GOOGLE_CHROME_BUILD)
103 if (InstallUtil::IsChromeSxSProcess()) {
104 dist = GetOrCreateBrowserDistribution<GoogleChromeSxSDistribution>(
105 &g_browser_distribution);
106 } else {
107 dist = GetOrCreateBrowserDistribution<GoogleChromeDistribution>(
108 &g_browser_distribution);
110 #else
111 dist = GetOrCreateBrowserDistribution<BrowserDistribution>(
112 &g_browser_distribution);
113 #endif
114 break;
116 case CHROME_FRAME:
117 dist = GetOrCreateBrowserDistribution<ChromeFrameDistribution>(
118 &g_chrome_frame_distribution);
119 break;
121 case CHROME_APP_HOST:
122 dist = GetOrCreateBrowserDistribution<ChromeAppHostDistribution>(
123 &g_chrome_app_host_distribution);
124 break;
126 default:
127 DCHECK_EQ(CHROME_BINARIES, type);
128 #if defined(GOOGLE_CHROME_BUILD)
129 dist = GetOrCreateBrowserDistribution<GoogleChromeBinariesDistribution>(
130 &g_binaries_distribution);
131 #else
132 dist = GetOrCreateBrowserDistribution<ChromiumBinariesDistribution>(
133 &g_binaries_distribution);
134 #endif
137 return dist;
140 void BrowserDistribution::DoPostUninstallOperations(
141 const Version& version, const base::FilePath& local_data_path,
142 const string16& distribution_data) {
145 string16 BrowserDistribution::GetActiveSetupGuid() {
146 return kChromiumActiveSetupGuid;
149 string16 BrowserDistribution::GetAppGuid() {
150 return L"";
153 string16 BrowserDistribution::GetBaseAppName() {
154 return L"Chromium";
157 string16 BrowserDistribution::GetAppShortCutName() {
158 return GetBaseAppName();
161 string16 BrowserDistribution::GetAlternateApplicationName() {
162 return L"The Internet";
165 string16 BrowserDistribution::GetBaseAppId() {
166 return L"Chromium";
169 string16 BrowserDistribution::GetInstallSubDir() {
170 return L"Chromium";
173 string16 BrowserDistribution::GetPublisherName() {
174 return L"Chromium";
177 string16 BrowserDistribution::GetAppDescription() {
178 return L"Browse the web";
181 string16 BrowserDistribution::GetLongAppDescription() {
182 const string16& app_description =
183 installer::GetLocalizedString(IDS_PRODUCT_DESCRIPTION_BASE);
184 return app_description;
187 std::string BrowserDistribution::GetSafeBrowsingName() {
188 return "chromium";
191 string16 BrowserDistribution::GetStateKey() {
192 return L"Software\\Chromium";
195 string16 BrowserDistribution::GetStateMediumKey() {
196 return L"Software\\Chromium";
199 std::string BrowserDistribution::GetNetworkStatsServer() const {
200 return "";
203 std::string BrowserDistribution::GetHttpPipeliningTestServer() const {
204 return "";
207 string16 BrowserDistribution::GetDistributionData(HKEY root_key) {
208 return L"";
211 string16 BrowserDistribution::GetUninstallLinkName() {
212 return L"Uninstall Chromium";
215 string16 BrowserDistribution::GetUninstallRegPath() {
216 return L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Chromium";
219 string16 BrowserDistribution::GetVersionKey() {
220 return L"Software\\Chromium";
223 bool BrowserDistribution::CanSetAsDefault() {
224 return true;
227 bool BrowserDistribution::CanCreateDesktopShortcuts() {
228 return true;
231 string16 BrowserDistribution::GetIconFilename() {
232 return string16();
235 int BrowserDistribution::GetIconIndex() {
236 // Assuming that main icon appears first alphabetically in the resource file
237 // for GetIconFilename().
238 return 0;
241 bool BrowserDistribution::GetChromeChannel(string16* channel) {
242 return false;
245 bool BrowserDistribution::GetCommandExecuteImplClsid(
246 string16* handler_class_uuid) {
247 if (handler_class_uuid)
248 *handler_class_uuid = kCommandExecuteImplUuid;
249 return true;
252 bool BrowserDistribution::AppHostIsSupported() {
253 return false;
256 void BrowserDistribution::UpdateInstallStatus(bool system_install,
257 installer::ArchiveType archive_type,
258 installer::InstallStatus install_status) {
261 bool BrowserDistribution::ShouldSetExperimentLabels() {
262 return false;
265 bool BrowserDistribution::HasUserExperiments() {
266 return false;