Home | History | Annotate | Download | only in google
      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 
      9 
     10 #include "base/strings/string_util.h"
     11 #include "base/strings/utf_string_conversions.h"
     12 #include "chrome/installer/util/google_update_settings.h"
     13 
     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
     19 
     20 
     21 // Helpers --------------------------------------------------------------------
     22 
     23 namespace {
     24 
     25 const char* g_brand_for_testing = NULL;
     26 
     27 }  // namespace
     28 
     29 
     30 namespace google_brand {
     31 
     32 // Global functions -----------------------------------------------------------
     33 
     34 #if defined(OS_WIN)
     35 
     36 bool GetBrand(std::string* brand) {
     37   if (g_brand_for_testing) {
     38     brand->assign(g_brand_for_testing);
     39     return true;
     40   }
     41 
     42   base::string16 brand16;
     43   bool ret = GoogleUpdateSettings::GetBrand(&brand16);
     44   if (ret)
     45     brand->assign(base::UTF16ToASCII(brand16));
     46   return ret;
     47 }
     48 
     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;
     55 }
     56 
     57 #else
     58 
     59 bool GetBrand(std::string* brand) {
     60   if (g_brand_for_testing) {
     61     brand->assign(g_brand_for_testing);
     62     return true;
     63   }
     64 
     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;
     73 }
     74 
     75 bool GetReactivationBrand(std::string* brand) {
     76   brand->clear();
     77   return true;
     78 }
     79 
     80 #endif
     81 
     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;
     88   }
     89 #endif
     90 
     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"
    100   };
    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;
    105 
    106   return StartsWithASCII(brand, "EUB", true) ||
    107          StartsWithASCII(brand, "EUC", true) ||
    108          StartsWithASCII(brand, "GGR", true);
    109 }
    110 
    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;
    117   }
    118 #endif
    119 
    120   return StartsWithASCII(brand, "GG", true) ||
    121          StartsWithASCII(brand, "EU", true);
    122 }
    123 
    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",
    128   };
    129   const char* const* end = &kBrands[arraysize(kBrands)];
    130   const char* const* found = std::find(&kBrands[0], end, brand);
    131   return found != end;
    132 }
    133 
    134 // BrandForTesting ------------------------------------------------------------
    135 
    136 BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) {
    137   DCHECK(g_brand_for_testing == NULL);
    138   g_brand_for_testing = brand_.c_str();
    139 }
    140 
    141 BrandForTesting::~BrandForTesting() {
    142   g_brand_for_testing = NULL;
    143 }
    144 
    145 
    146 }  // namespace google_brand
    147