Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/google/google_util.h" | 5 #include "chrome/browser/google/google_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/google/google_url_tracker.h" | 17 #include "chrome/browser/google/google_url_tracker.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/net/url_util.h" | 19 #include "chrome/common/net/url_util.h" |
| 20 #include "chrome/installer/util/google_update_settings.h" | 20 #include "chrome/installer/util/google_update_settings.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 23 | 23 |
| 24 #if defined(OS_MACOSX) | 24 #if defined(OS_MACOSX) |
| 25 #include "chrome/browser/mac/keystone_glue.h" | 25 #include "chrome/browser/mac/keystone_glue.h" |
| 26 #elif defined(OS_CHROMEOS) | |
| 27 #include "base/file_util.h" | |
| 28 #include "base/lazy_instance.h" | |
| 29 #include "base/string_util.h" | |
| 30 #include "base/threading/thread_restrictions.h" | |
| 26 #endif | 31 #endif |
| 27 | 32 |
| 28 #if defined(GOOGLE_CHROME_BUILD) | 33 #if defined(GOOGLE_CHROME_BUILD) |
| 29 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h" | 34 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h" |
| 30 #endif | 35 #endif |
| 31 | 36 |
| 32 #ifndef LINKDOCTOR_SERVER_REQUEST_URL | 37 #ifndef LINKDOCTOR_SERVER_REQUEST_URL |
| 33 #define LINKDOCTOR_SERVER_REQUEST_URL "" | 38 #define LINKDOCTOR_SERVER_REQUEST_URL "" |
| 34 #endif | 39 #endif |
| 35 | 40 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 48 itr != parameters.end(); | 53 itr != parameters.end(); |
| 49 ++itr) { | 54 ++itr) { |
| 50 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) | 55 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) |
| 51 return true; | 56 return true; |
| 52 } | 57 } |
| 53 return false; | 58 return false; |
| 54 } | 59 } |
| 55 | 60 |
| 56 bool gUseMockLinkDoctorBaseURLForTesting = false; | 61 bool gUseMockLinkDoctorBaseURLForTesting = false; |
| 57 | 62 |
| 63 #if defined(OS_CHROMEOS) | |
|
Peter Kasting
2012/11/19 20:59:10
Nit: Maybe this whole block should go in its own .
Ivan Korotkov
2012/11/28 14:24:22
Done.
| |
| 64 // Path to file that stores RLZ brand code on ChromeOS. | |
| 65 const char kRLZBrandFilePath[] = | |
| 66 FILE_PATH_LITERAL("/opt/oem/etc/rlz_brand_code"); | |
| 67 | |
| 68 // Simple class for caching brand code, meant to be used as a LazyInstance. | |
|
Peter Kasting
2012/11/19 20:59:10
Do we really need thread-safety? I thought the go
| |
| 69 class BrandCode { | |
| 70 public: | |
| 71 BrandCode() { | |
|
Peter Kasting
2012/11/19 20:59:10
Nit: Don't inline non-accessor methods, even for c
| |
| 72 // Need to perform I/O for the first time, same as on Win. | |
| 73 // TODO(ivankr): as discussed, this will be moved to OOBE->EULA stage. | |
|
Peter Kasting
2012/11/19 20:59:10
Can this be done now? I'm leery of adding ScopedA
Ivan Korotkov
2012/11/28 14:24:22
Done.
| |
| 74 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 75 FilePath brand_file_path(kRLZBrandFilePath); | |
| 76 if (!file_util::ReadFileToString(brand_file_path, &brand_)) | |
| 77 LOG(WARNING) << "Brand code file missing: " << brand_file_path.value(); | |
| 78 TrimWhitespace(brand_, TRIM_ALL, &brand_); | |
| 79 } | |
| 80 | |
| 81 // Brand code, may be empty. | |
| 82 const std::string& brand() { return brand_; } | |
| 83 | |
| 84 private: | |
| 85 std::string brand_; | |
| 86 }; | |
|
Peter Kasting
2012/11/19 20:59:10
Nit: DISALLOW_COPY_AND_ASSIGN
| |
| 87 | |
| 88 base::LazyInstance<BrandCode> g_cached_brand = LAZY_INSTANCE_INITIALIZER; | |
| 89 #endif | |
| 90 | |
| 58 } // anonymous namespace | 91 } // anonymous namespace |
| 59 | 92 |
| 60 namespace google_util { | 93 namespace google_util { |
| 61 | 94 |
| 62 GURL LinkDoctorBaseURL() { | 95 GURL LinkDoctorBaseURL() { |
| 63 if (gUseMockLinkDoctorBaseURLForTesting) | 96 if (gUseMockLinkDoctorBaseURLForTesting) |
| 64 return GURL("http://mock.linkdoctor.url/for?testing"); | 97 return GURL("http://mock.linkdoctor.url/for?testing"); |
| 65 return GURL(LINKDOCTOR_SERVER_REQUEST_URL); | 98 return GURL(LINKDOCTOR_SERVER_REQUEST_URL); |
| 66 } | 99 } |
| 67 | 100 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 #else | 166 #else |
| 134 | 167 |
| 135 bool GetBrand(std::string* brand) { | 168 bool GetBrand(std::string* brand) { |
| 136 if (brand_for_testing) { | 169 if (brand_for_testing) { |
| 137 brand->assign(brand_for_testing); | 170 brand->assign(brand_for_testing); |
| 138 return true; | 171 return true; |
| 139 } | 172 } |
| 140 | 173 |
| 141 #if defined(OS_MACOSX) | 174 #if defined(OS_MACOSX) |
| 142 brand->assign(keystone_glue::BrandCode()); | 175 brand->assign(keystone_glue::BrandCode()); |
| 176 #elif defined(OS_CHROMEOS) | |
| 177 brand->assign(g_cached_brand.Get().brand()); | |
| 143 #else | 178 #else |
| 144 brand->clear(); | 179 brand->clear(); |
| 145 #endif | 180 #endif |
| 146 return true; | 181 return true; |
| 147 } | 182 } |
| 148 | 183 |
| 149 bool GetReactivationBrand(std::string* brand) { | 184 bool GetReactivationBrand(std::string* brand) { |
| 150 brand->clear(); | 185 brand->clear(); |
| 151 return true; | 186 return true; |
| 152 } | 187 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 const char* const kBrands[] = { | 351 const char* const kBrands[] = { |
| 317 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 352 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
| 318 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | 353 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", |
| 319 }; | 354 }; |
| 320 const char* const* end = &kBrands[arraysize(kBrands)]; | 355 const char* const* end = &kBrands[arraysize(kBrands)]; |
| 321 const char* const* found = std::find(&kBrands[0], end, brand); | 356 const char* const* found = std::find(&kBrands[0], end, brand); |
| 322 return found != end; | 357 return found != end; |
| 323 } | 358 } |
| 324 | 359 |
| 325 } // namespace google_util | 360 } // namespace google_util |
| OLD | NEW |