OLD | NEW |
---|---|
(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(); | |
Peter Kasting
2012/12/01 03:06:22
Nit: Is this log something you'll be able to captu
Ivan Korotkov
2012/12/02 12:01:15
Yes, I'd like to have this in log reports.
| |
33 TrimWhitespace(*brand, TRIM_ALL, brand); | |
34 } | |
35 | |
36 // Sets the brand code to |brand|. | |
37 void SetBrand(std::string* brand, const base::Closure& callback) { | |
38 g_browser_process->local_state()->SetString(prefs::kRLZBrand, *brand); | |
39 delete brand; | |
40 callback.Run(); | |
41 } | |
42 | |
43 } // namespace | |
44 | |
45 std::string GetBrand() { | |
46 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || | |
Peter Kasting
2012/12/01 03:06:22
Nit: If you change to this:
DCHECK(
!cont
Ivan Korotkov
2012/12/02 12:01:15
Done :)
| |
47 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
48 PrefService* local_state = g_browser_process->local_state(); | |
49 return local_state ? local_state->GetString(prefs::kRLZBrand) : std::string(); | |
Peter Kasting
2012/12/01 03:06:22
Can this ever be NULL? We shouldn't NULL-check if
Ivan Korotkov
2012/12/02 12:01:15
I don't think it should ever be, only if GetBrand
| |
50 } | |
51 | |
52 void SetBrandFromFile(const base::Closure& callback) { | |
53 std::string* brand = new std::string; | |
Peter Kasting
2012/12/01 03:06:22
Instead of allocating this, can we just pass the s
Ivan Korotkov
2012/12/02 12:01:15
Wow, I've missed this method completely. Thanks!
| |
54 base::WorkerPool::PostTaskAndReply( | |
55 FROM_HERE, | |
56 base::Bind(&ReadBrandFromFile, brand), | |
57 base::Bind(&SetBrand, brand, callback), | |
58 /* task_is_slow= */ false); | |
59 } | |
60 | |
61 } // namespace chromeos | |
62 } // namespace google_util | |
OLD | NEW |