This source file includes following definitions.
- ReadBrandFromFile
- SetBrand
- ClearBrandForCurrentSession
- GetBrand
- InitBrand
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_util.h"
#include "base/task_runner_util.h"
#include "base/threading/worker_pool.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/pref_names.h"
#include "chromeos/system/statistics_provider.h"
#include "content/public/browser/browser_thread.h"
namespace google_util {
namespace chromeos {
namespace {
const base::FilePath::CharType kRLZBrandFilePath[] =
FILE_PATH_LITERAL("/opt/oem/etc/BRAND_CODE");
std::string ReadBrandFromFile() {
std::string brand;
base::FilePath brand_file_path(kRLZBrandFilePath);
if (!base::ReadFileToString(brand_file_path, &brand))
LOG(WARNING) << "Brand code file missing: " << brand_file_path.value();
base::TrimWhitespace(brand, base::TRIM_ALL, &brand);
return brand;
}
void SetBrand(const base::Closure& callback, const std::string& brand) {
g_browser_process->local_state()->SetString(prefs::kRLZBrand, brand);
callback.Run();
}
bool g_brand_empty = false;
}
void ClearBrandForCurrentSession() {
DCHECK(!content::BrowserThread::IsThreadInitialized(
content::BrowserThread::UI) ||
content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
g_brand_empty = true;
}
std::string GetBrand() {
DCHECK(!content::BrowserThread::IsThreadInitialized(
content::BrowserThread::UI) ||
content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (g_brand_empty)
return std::string();
DCHECK(g_browser_process->local_state());
return g_browser_process->local_state()->GetString(prefs::kRLZBrand);
}
void InitBrand(const base::Closure& callback) {
::chromeos::system::StatisticsProvider* provider =
::chromeos::system::StatisticsProvider::GetInstance();
std::string brand;
const bool found = provider->GetMachineStatistic(
::chromeos::system::kRlzBrandCodeKey, &brand);
if (found && !brand.empty()) {
SetBrand(callback, brand);
return;
}
base::PostTaskAndReplyWithResult(
base::WorkerPool::GetTaskRunner(false ).get(),
FROM_HERE,
base::Bind(&ReadBrandFromFile),
base::Bind(&SetBrand, callback));
}
}
}