Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4296)

Unified Diff: chrome/browser/google/google_brand.cc

Issue 316963002: Move branding information out of google_util (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/google/google_brand.cc
diff --git a/chrome/browser/google/google_brand.cc b/chrome/browser/google/google_brand.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5267e14b69079d831519b0b1b33418ff78e34310
--- /dev/null
+++ b/chrome/browser/google/google_brand.cc
@@ -0,0 +1,157 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/google/google_brand.h"
+
+#include <string>
+#include <vector>
+
+#include "base/command_line.h"
+#include "base/strings/string16.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/google/google_url_tracker.h"
+#include "chrome/common/net/url_fixer_upper.h"
+#include "chrome/installer/util/google_update_settings.h"
+#include "components/google/core/browser/google_switches.h"
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
+#include "net/base/url_util.h"
+#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.
+
+#if defined(OS_MACOSX)
+#include "chrome/browser/mac/keystone_glue.h"
+#elif defined(OS_CHROMEOS)
+#include "chrome/browser/google/google_brand_chromeos.h"
+#endif
+
+
+// Helpers --------------------------------------------------------------------
+
+namespace {
+
+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.
+
+} // namespace
+
+
+namespace google_brand {
+
+// Global functions -----------------------------------------------------------
+
+#if defined(OS_WIN)
+
+bool GetBrand(std::string* brand) {
+ if (brand_for_testing) {
+ brand->assign(brand_for_testing);
+ return true;
+ }
+
+ base::string16 brand16;
+ bool ret = GoogleUpdateSettings::GetBrand(&brand16);
+ if (ret)
+ brand->assign(base::UTF16ToASCII(brand16));
+ return ret;
+}
+
+bool GetReactivationBrand(std::string* brand) {
+ base::string16 brand16;
+ bool ret = GoogleUpdateSettings::GetReactivationBrand(&brand16);
+ if (ret)
+ brand->assign(base::UTF16ToASCII(brand16));
+ return ret;
+}
+
+#else
+
+bool GetBrand(std::string* brand) {
+ if (brand_for_testing) {
+ brand->assign(brand_for_testing);
+ return true;
+ }
+
+#if defined(OS_MACOSX)
+ brand->assign(keystone_glue::BrandCode());
+#elif defined(OS_CHROMEOS)
+ brand->assign(google_brand::chromeos::GetBrand());
+#else
+ brand->clear();
+#endif
+ return true;
+}
+
+bool GetReactivationBrand(std::string* brand) {
+ brand->clear();
+ return true;
+}
+
+#endif
+
+bool IsOrganic(const std::string& brand) {
+#if defined(OS_MACOSX)
+ if (brand.empty()) {
+ // An empty brand string on Mac is used for channels other than stable,
+ // which are always organic.
+ return true;
+ }
+#endif
+
+ const char* const kBrands[] = {
+ "CHCA", "CHCB", "CHCG", "CHCH", "CHCI", "CHCJ", "CHCK", "CHCL",
+ "CHFO", "CHFT", "CHHS", "CHHM", "CHMA", "CHMB", "CHME", "CHMF",
+ "CHMG", "CHMH", "CHMI", "CHMQ", "CHMV", "CHNB", "CHNC", "CHNG",
+ "CHNH", "CHNI", "CHOA", "CHOB", "CHOC", "CHON", "CHOO", "CHOP",
+ "CHOQ", "CHOR", "CHOS", "CHOT", "CHOU", "CHOX", "CHOY", "CHOZ",
+ "CHPD", "CHPE", "CHPF", "CHPG", "ECBA", "ECBB", "ECDA", "ECDB",
+ "ECSA", "ECSB", "ECVA", "ECVB", "ECWA", "ECWB", "ECWC", "ECWD",
+ "ECWE", "ECWF", "EUBB", "EUBC", "GGLA", "GGLS"
+ };
+ const char* const* end = &kBrands[arraysize(kBrands)];
+ const char* const* found = std::find(&kBrands[0], end, brand);
+ if (found != end)
+ return true;
+
+ return StartsWithASCII(brand, "EUB", true) ||
+ StartsWithASCII(brand, "EUC", true) ||
+ StartsWithASCII(brand, "GGR", true);
+}
+
+bool IsOrganicFirstRun(const std::string& brand) {
+#if defined(OS_MACOSX)
+ if (brand.empty()) {
+ // An empty brand string on Mac is used for channels other than stable,
+ // which are always organic.
+ return true;
+ }
+#endif
+
+ return StartsWithASCII(brand, "GG", true) ||
+ StartsWithASCII(brand, "EU", true);
+}
+
+bool IsInternetCafeBrandCode(const std::string& brand) {
+ const char* const kBrands[] = {
+ "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
+ "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
+ };
+ const char* const* end = &kBrands[arraysize(kBrands)];
+ const char* const* found = std::find(&kBrands[0], end, brand);
+ return found != end;
+}
+
+// BrandForTesting ------------------------------------------------------------
+
+BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) {
+ DCHECK(brand_for_testing == NULL);
+ brand_for_testing = brand_.c_str();
+}
+
+BrandForTesting::~BrandForTesting() {
+ brand_for_testing = NULL;
+}
+
+
+} // namespace google_brand

Powered by Google App Engine
This is Rietveld 408576698