1 // Copyright 2014 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 #include "chrome/browser/google/google_brand.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/installer/util/google_update_settings.h"
14 #if defined(OS_MACOSX)
15 #include "chrome/browser/mac/keystone_glue.h"
16 #elif defined(OS_CHROMEOS)
17 #include "chrome/browser/google/google_brand_chromeos.h"
21 // Helpers --------------------------------------------------------------------
25 const char* g_brand_for_testing
= NULL
;
30 namespace google_brand
{
32 // Global functions -----------------------------------------------------------
36 bool GetBrand(std::string
* brand
) {
37 if (g_brand_for_testing
) {
38 brand
->assign(g_brand_for_testing
);
42 base::string16 brand16
;
43 bool ret
= GoogleUpdateSettings::GetBrand(&brand16
);
45 brand
->assign(base::UTF16ToASCII(brand16
));
49 bool GetReactivationBrand(std::string
* brand
) {
50 base::string16 brand16
;
51 bool ret
= GoogleUpdateSettings::GetReactivationBrand(&brand16
);
53 brand
->assign(base::UTF16ToASCII(brand16
));
59 bool GetBrand(std::string
* brand
) {
60 if (g_brand_for_testing
) {
61 brand
->assign(g_brand_for_testing
);
65 #if defined(OS_MACOSX)
66 brand
->assign(keystone_glue::BrandCode());
67 #elif defined(OS_CHROMEOS)
68 brand
->assign(google_brand::chromeos::GetBrand());
75 bool GetReactivationBrand(std::string
* brand
) {
82 bool IsOrganic(const std::string
& brand
) {
83 #if defined(OS_MACOSX)
85 // An empty brand string on Mac is used for channels other than stable,
86 // which are always organic.
91 const char* const kBrands
[] = {
92 "CHCA", "CHCB", "CHCG", "CHCH", "CHCI", "CHCJ", "CHCK", "CHCL",
93 "CHFO", "CHFT", "CHHS", "CHHM", "CHMA", "CHMB", "CHME", "CHMF",
94 "CHMG", "CHMH", "CHMI", "CHMQ", "CHMV", "CHNB", "CHNC", "CHNG",
95 "CHNH", "CHNI", "CHOA", "CHOB", "CHOC", "CHON", "CHOO", "CHOP",
96 "CHOQ", "CHOR", "CHOS", "CHOT", "CHOU", "CHOX", "CHOY", "CHOZ",
97 "CHPD", "CHPE", "CHPF", "CHPG", "ECBA", "ECBB", "ECDA", "ECDB",
98 "ECSA", "ECSB", "ECVA", "ECVB", "ECWA", "ECWB", "ECWC", "ECWD",
99 "ECWE", "ECWF", "EUBB", "EUBC", "GGLA", "GGLS"
101 const char* const* end
= &kBrands
[arraysize(kBrands
)];
102 const char* const* found
= std::find(&kBrands
[0], end
, brand
);
106 return base::StartsWith(brand
, "EUB", base::CompareCase::SENSITIVE
) ||
107 base::StartsWith(brand
, "EUC", base::CompareCase::SENSITIVE
) ||
108 base::StartsWith(brand
, "GGR", base::CompareCase::SENSITIVE
);
111 bool IsOrganicFirstRun(const std::string
& brand
) {
112 #if defined(OS_MACOSX)
114 // An empty brand string on Mac is used for channels other than stable,
115 // which are always organic.
120 return base::StartsWith(brand
, "GG", base::CompareCase::SENSITIVE
) ||
121 base::StartsWith(brand
, "EU", base::CompareCase::SENSITIVE
);
124 bool IsInternetCafeBrandCode(const std::string
& brand
) {
125 const char* const kBrands
[] = {
126 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
127 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
129 const char* const* end
= &kBrands
[arraysize(kBrands
)];
130 const char* const* found
= std::find(&kBrands
[0], end
, brand
);
134 // BrandForTesting ------------------------------------------------------------
136 BrandForTesting::BrandForTesting(const std::string
& brand
) : brand_(brand
) {
137 DCHECK(g_brand_for_testing
== NULL
);
138 g_brand_for_testing
= brand_
.c_str();
141 BrandForTesting::~BrandForTesting() {
142 g_brand_for_testing
= NULL
;
146 } // namespace google_brand