Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / google / google_util_chromeos.cc
blob41f1245c6e73253ae744a39214aabb2711e3d840
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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/bind.h"
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string_util.h"
12 #include "base/task_runner_util.h"
13 #include "base/threading/worker_pool.h"
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/browser_thread.h"
18 namespace google_util {
19 namespace chromeos {
21 namespace {
23 // Path to file that stores the RLZ brand code on ChromeOS.
24 const base::FilePath::CharType kRLZBrandFilePath[] =
25 FILE_PATH_LITERAL("/opt/oem/etc/BRAND_CODE");
27 // Reads the brand code from file |kRLZBrandFilePath|.
28 std::string ReadBrandFromFile() {
29 std::string brand;
30 base::FilePath brand_file_path(kRLZBrandFilePath);
31 if (!base::ReadFileToString(brand_file_path, &brand))
32 LOG(WARNING) << "Brand code file missing: " << brand_file_path.value();
33 TrimWhitespace(brand, TRIM_ALL, &brand);
34 return brand;
37 // Sets the brand code to |brand|.
38 void SetBrand(const base::Closure& callback, const std::string& brand) {
39 g_browser_process->local_state()->SetString(prefs::kRLZBrand, brand);
40 callback.Run();
43 // True if brand code has been cleared for the current session.
44 bool g_brand_empty = false;
46 } // namespace
48 void ClearBrandForCurrentSession() {
49 DCHECK(!content::BrowserThread::IsThreadInitialized(
50 content::BrowserThread::UI) ||
51 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
52 g_brand_empty = true;
55 std::string GetBrand() {
56 DCHECK(!content::BrowserThread::IsThreadInitialized(
57 content::BrowserThread::UI) ||
58 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
59 if (g_brand_empty)
60 return std::string();
61 DCHECK(g_browser_process->local_state());
62 return g_browser_process->local_state()->GetString(prefs::kRLZBrand);
65 void SetBrandFromFile(const base::Closure& callback) {
66 base::PostTaskAndReplyWithResult(
67 base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(),
68 FROM_HERE,
69 base::Bind(&ReadBrandFromFile),
70 base::Bind(&SetBrand, callback));
73 } // namespace chromeos
74 } // namespace google_util