OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/google/google_brand.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/command_line.h" | |
11 #include "base/strings/string16.h" | |
12 #include "base/strings/string_number_conversions.h" | |
13 #include "base/strings/string_split.h" | |
14 #include "base/strings/string_util.h" | |
15 #include "base/strings/utf_string_conversions.h" | |
16 #include "chrome/browser/browser_process.h" | |
17 #include "chrome/browser/google/google_url_tracker.h" | |
18 #include "chrome/common/net/url_fixer_upper.h" | |
19 #include "chrome/installer/util/google_update_settings.h" | |
20 #include "components/google/core/browser/google_switches.h" | |
21 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | |
22 #include "net/base/url_util.h" | |
23 #include "url/gurl.h" | |
Peter Kasting
2014/06/04 20:32:16
Are all these truly necessary? For example, you d
blundell
2014/06/05 09:21:43
Done.
| |
24 | |
25 #if defined(OS_MACOSX) | |
26 #include "chrome/browser/mac/keystone_glue.h" | |
27 #elif defined(OS_CHROMEOS) | |
28 #include "chrome/browser/google/google_brand_chromeos.h" | |
29 #endif | |
30 | |
31 | |
32 // Helpers -------------------------------------------------------------------- | |
33 | |
34 namespace { | |
35 | |
36 const char* brand_for_testing = NULL; | |
Peter Kasting
2014/06/04 20:32:16
Nit: I'd prefix this with g_
blundell
2014/06/05 09:21:43
Done.
| |
37 | |
38 } // namespace | |
39 | |
40 | |
41 namespace google_brand { | |
42 | |
43 // Global functions ----------------------------------------------------------- | |
44 | |
45 #if defined(OS_WIN) | |
46 | |
47 bool GetBrand(std::string* brand) { | |
48 if (brand_for_testing) { | |
49 brand->assign(brand_for_testing); | |
50 return true; | |
51 } | |
52 | |
53 base::string16 brand16; | |
54 bool ret = GoogleUpdateSettings::GetBrand(&brand16); | |
55 if (ret) | |
56 brand->assign(base::UTF16ToASCII(brand16)); | |
57 return ret; | |
58 } | |
59 | |
60 bool GetReactivationBrand(std::string* brand) { | |
61 base::string16 brand16; | |
62 bool ret = GoogleUpdateSettings::GetReactivationBrand(&brand16); | |
63 if (ret) | |
64 brand->assign(base::UTF16ToASCII(brand16)); | |
65 return ret; | |
66 } | |
67 | |
68 #else | |
69 | |
70 bool GetBrand(std::string* brand) { | |
71 if (brand_for_testing) { | |
72 brand->assign(brand_for_testing); | |
73 return true; | |
74 } | |
75 | |
76 #if defined(OS_MACOSX) | |
77 brand->assign(keystone_glue::BrandCode()); | |
78 #elif defined(OS_CHROMEOS) | |
79 brand->assign(google_brand::chromeos::GetBrand()); | |
80 #else | |
81 brand->clear(); | |
82 #endif | |
83 return true; | |
84 } | |
85 | |
86 bool GetReactivationBrand(std::string* brand) { | |
87 brand->clear(); | |
88 return true; | |
89 } | |
90 | |
91 #endif | |
92 | |
93 bool IsOrganic(const std::string& brand) { | |
94 #if defined(OS_MACOSX) | |
95 if (brand.empty()) { | |
96 // An empty brand string on Mac is used for channels other than stable, | |
97 // which are always organic. | |
98 return true; | |
99 } | |
100 #endif | |
101 | |
102 const char* const kBrands[] = { | |
103 "CHCA", "CHCB", "CHCG", "CHCH", "CHCI", "CHCJ", "CHCK", "CHCL", | |
104 "CHFO", "CHFT", "CHHS", "CHHM", "CHMA", "CHMB", "CHME", "CHMF", | |
105 "CHMG", "CHMH", "CHMI", "CHMQ", "CHMV", "CHNB", "CHNC", "CHNG", | |
106 "CHNH", "CHNI", "CHOA", "CHOB", "CHOC", "CHON", "CHOO", "CHOP", | |
107 "CHOQ", "CHOR", "CHOS", "CHOT", "CHOU", "CHOX", "CHOY", "CHOZ", | |
108 "CHPD", "CHPE", "CHPF", "CHPG", "ECBA", "ECBB", "ECDA", "ECDB", | |
109 "ECSA", "ECSB", "ECVA", "ECVB", "ECWA", "ECWB", "ECWC", "ECWD", | |
110 "ECWE", "ECWF", "EUBB", "EUBC", "GGLA", "GGLS" | |
111 }; | |
112 const char* const* end = &kBrands[arraysize(kBrands)]; | |
113 const char* const* found = std::find(&kBrands[0], end, brand); | |
114 if (found != end) | |
115 return true; | |
116 | |
117 return StartsWithASCII(brand, "EUB", true) || | |
118 StartsWithASCII(brand, "EUC", true) || | |
119 StartsWithASCII(brand, "GGR", true); | |
120 } | |
121 | |
122 bool IsOrganicFirstRun(const std::string& brand) { | |
123 #if defined(OS_MACOSX) | |
124 if (brand.empty()) { | |
125 // An empty brand string on Mac is used for channels other than stable, | |
126 // which are always organic. | |
127 return true; | |
128 } | |
129 #endif | |
130 | |
131 return StartsWithASCII(brand, "GG", true) || | |
132 StartsWithASCII(brand, "EU", true); | |
133 } | |
134 | |
135 bool IsInternetCafeBrandCode(const std::string& brand) { | |
136 const char* const kBrands[] = { | |
137 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | |
138 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | |
139 }; | |
140 const char* const* end = &kBrands[arraysize(kBrands)]; | |
141 const char* const* found = std::find(&kBrands[0], end, brand); | |
142 return found != end; | |
143 } | |
144 | |
145 // BrandForTesting ------------------------------------------------------------ | |
146 | |
147 BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) { | |
148 DCHECK(brand_for_testing == NULL); | |
149 brand_for_testing = brand_.c_str(); | |
150 } | |
151 | |
152 BrandForTesting::~BrandForTesting() { | |
153 brand_for_testing = NULL; | |
154 } | |
155 | |
156 | |
157 } // namespace google_brand | |
OLD | NEW |