Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: chrome/browser/google/google_util_chromeos.cc

Issue 11412067: [rlz,cros] RLZ glue for ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Header guard Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "base/basictypes.h"
6 #include "base/bind.h"
7 #include "base/file_path.h"
8 #include "base/file_util.h"
9 #include "base/logging.h"
10 #include "base/string_util.h"
11 #include "base/threading/worker_pool.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/common/pref_names.h"
15 #include "content/public/browser/browser_thread.h"
16
17 using content::BrowserThread;
18
19 namespace google_util {
20 namespace chromeos {
21
22 namespace {
23
24 // Path to file that stores the RLZ brand code on ChromeOS.
25 const char kRLZBrandFilePath[] =
26 FILE_PATH_LITERAL("/opt/oem/etc/rlz_brand_code");
27
28 // Reads the brand code from file |kRLZBrandFilePath| to |brand|.
29 void ReadBrandFromFile(std::string* brand) {
30 FilePath brand_file_path(kRLZBrandFilePath);
31 if (!file_util::ReadFileToString(brand_file_path, brand))
32 LOG(WARNING) << "Brand code file missing: " << brand_file_path.value();
33 TrimWhitespace(*brand, TRIM_ALL, brand);
34 LOG(ERROR) << "Brand code: " << *brand;
35 }
36
37 // Sets the brand code to |brand|.
38 void SetBrand(std::string* brand, const base::Closure& callback) {
39 g_browser_process->local_state()->SetString(prefs::kRLZBrand, *brand);
40 delete brand;
41 callback.Run();
42 }
43
44 } // namespace
45
46 std::string GetBrand() {
47 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) ||
48 BrowserThread::CurrentlyOn(BrowserThread::UI));
49 PrefService* local_state = g_browser_process->local_state();
50 return local_state ? local_state->GetString(prefs::kRLZBrand) : std::string();
51 }
52
53 void SetBrandFromFile(const base::Closure& callback) {
54 std::string* brand = new std::string;
55 base::WorkerPool::PostTaskAndReply(
56 FROM_HERE,
57 base::Bind(&ReadBrandFromFile, brand),
58 base::Bind(&SetBrand, brand, callback),
59 /* task_is_slow= */ false);
60 }
61
62 } // namespace chromeos
63 } // namespace google_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698