| Index: chrome/browser/google/google_util_chromeos.cc
|
| diff --git a/chrome/browser/google/google_util_chromeos.cc b/chrome/browser/google/google_util_chromeos.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3dca85c364bc0e4f018e50f650f13159787c8d3f
|
| --- /dev/null
|
| +++ b/chrome/browser/google/google_util_chromeos.cc
|
| @@ -0,0 +1,63 @@
|
| +// Copyright (c) 2012 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 "base/basictypes.h"
|
| +#include "base/bind.h"
|
| +#include "base/file_path.h"
|
| +#include "base/file_util.h"
|
| +#include "base/logging.h"
|
| +#include "base/string_util.h"
|
| +#include "base/threading/worker_pool.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/prefs/pref_service.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +using content::BrowserThread;
|
| +
|
| +namespace google_util {
|
| +namespace chromeos {
|
| +
|
| +namespace {
|
| +
|
| +// Path to file that stores the RLZ brand code on ChromeOS.
|
| +const char kRLZBrandFilePath[] =
|
| + FILE_PATH_LITERAL("/opt/oem/etc/rlz_brand_code");
|
| +
|
| +// Reads the brand code from file |kRLZBrandFilePath| to |brand|.
|
| +void ReadBrandFromFile(std::string* brand) {
|
| + 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);
|
| + LOG(ERROR) << "Brand code: " << *brand;
|
| +}
|
| +
|
| +// Sets the brand code to |brand|.
|
| +void SetBrand(std::string* brand, const base::Closure& callback) {
|
| + g_browser_process->local_state()->SetString(prefs::kRLZBrand, *brand);
|
| + delete brand;
|
| + callback.Run();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +std::string GetBrand() {
|
| + DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) ||
|
| + BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + PrefService* local_state = g_browser_process->local_state();
|
| + return local_state ? local_state->GetString(prefs::kRLZBrand) : std::string();
|
| +}
|
| +
|
| +void SetBrandFromFile(const base::Closure& callback) {
|
| + std::string* brand = new std::string;
|
| + base::WorkerPool::PostTaskAndReply(
|
| + FROM_HERE,
|
| + base::Bind(&ReadBrandFromFile, brand),
|
| + base::Bind(&SetBrand, brand, callback),
|
| + /* task_is_slow= */ false);
|
| +}
|
| +
|
| +} // namespace chromeos
|
| +} // namespace google_util
|
|
|