Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / google / google_brand.cc
blob516918dd45a8fc0daeab891e22adbea69387ced8
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"
7 #include <string>
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"
18 #endif
21 // Helpers --------------------------------------------------------------------
23 namespace {
25 const char* g_brand_for_testing = NULL;
27 } // namespace
30 namespace google_brand {
32 // Global functions -----------------------------------------------------------
34 #if defined(OS_WIN)
36 bool GetBrand(std::string* brand) {
37 if (g_brand_for_testing) {
38 brand->assign(g_brand_for_testing);
39 return true;
42 base::string16 brand16;
43 bool ret = GoogleUpdateSettings::GetBrand(&brand16);
44 if (ret)
45 brand->assign(base::UTF16ToASCII(brand16));
46 return ret;
49 bool GetReactivationBrand(std::string* brand) {
50 base::string16 brand16;
51 bool ret = GoogleUpdateSettings::GetReactivationBrand(&brand16);
52 if (ret)
53 brand->assign(base::UTF16ToASCII(brand16));
54 return ret;
57 #else
59 bool GetBrand(std::string* brand) {
60 if (g_brand_for_testing) {
61 brand->assign(g_brand_for_testing);
62 return true;
65 #if defined(OS_MACOSX)
66 brand->assign(keystone_glue::BrandCode());
67 #elif defined(OS_CHROMEOS)
68 brand->assign(google_brand::chromeos::GetBrand());
69 #else
70 brand->clear();
71 #endif
72 return true;
75 bool GetReactivationBrand(std::string* brand) {
76 brand->clear();
77 return true;
80 #endif
82 bool IsOrganic(const std::string& brand) {
83 #if defined(OS_MACOSX)
84 if (brand.empty()) {
85 // An empty brand string on Mac is used for channels other than stable,
86 // which are always organic.
87 return true;
89 #endif
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);
103 if (found != end)
104 return true;
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)
113 if (brand.empty()) {
114 // An empty brand string on Mac is used for channels other than stable,
115 // which are always organic.
116 return true;
118 #endif
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);
131 return found != end;
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