Index: chrome/browser/google/google_util.cc |
diff --git a/chrome/browser/google/google_util.cc b/chrome/browser/google/google_util.cc |
index 0d47f5675ab91f8479ddee5385c3c2b49f715810..b690d907b667f7dfecbde2a75cae6905470ed1b5 100644 |
--- a/chrome/browser/google/google_util.cc |
+++ b/chrome/browser/google/google_util.cc |
@@ -23,6 +23,11 @@ |
#if defined(OS_MACOSX) |
#include "chrome/browser/mac/keystone_glue.h" |
+#elif defined(OS_CHROMEOS) |
+#include "base/file_util.h" |
+#include "base/lazy_instance.h" |
+#include "base/string_util.h" |
+#include "base/threading/thread_restrictions.h" |
#endif |
#if defined(GOOGLE_CHROME_BUILD) |
@@ -55,6 +60,33 @@ bool HasQueryParameter(const std::string& str) { |
bool gUseMockLinkDoctorBaseURLForTesting = false; |
+#if defined(OS_CHROMEOS) |
+// Path to file that stores RLZ brand code on ChromeOS. |
+const char kRLZBrandFilePath[] = |
+ FILE_PATH_LITERAL("/opt/oem/etc/rlz_brand_code"); |
+ |
+// Simple class for caching brand code, meant to be used as a LazyInstance. |
+class BrandCode { |
+ public: |
+ BrandCode() { |
+ // Need to perform I/O for the first time, same as on Win. |
+ base::ThreadRestrictions::ScopedAllowIO allow_io; |
+ FilePath brand_file_path(kRLZBrandFilePath); |
+ if (!file_util::ReadFileToString(brand_file_path, &brand_)) |
+ LOG(WARNING) << "Brand code file missing: " << brand_file_path.value(); |
+ TrimWhitespace(brand_, TRIM_ALL, &brand_); |
+ } |
+ |
+ // Brand code, may be empty. |
+ const std::string& brand() { return brand_; } |
+ |
+ private: |
+ std::string brand_; |
+}; |
+ |
+base::LazyInstance<BrandCode> g_cached_brand = LAZY_INSTANCE_INITIALIZER; |
+#endif |
+ |
} // anonymous namespace |
namespace google_util { |
@@ -140,6 +172,8 @@ bool GetBrand(std::string* brand) { |
#if defined(OS_MACOSX) |
brand->assign(keystone_glue::BrandCode()); |
+#elif defined(OS_CHROMEOS) |
+ brand->assign(g_cached_brand.Get().brand()); |
#else |
brand->clear(); |
#endif |