OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/lazy_instance.h" | |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
12 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.h" |
13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 | 18 |
18 namespace google_util { | 19 namespace google_util { |
(...skipping 14 matching lines...) Expand all Loading... | |
33 TrimWhitespace(brand, TRIM_ALL, &brand); | 34 TrimWhitespace(brand, TRIM_ALL, &brand); |
34 return brand; | 35 return brand; |
35 } | 36 } |
36 | 37 |
37 // Sets the brand code to |brand|. | 38 // Sets the brand code to |brand|. |
38 void SetBrand(const base::Closure& callback, const std::string& brand) { | 39 void SetBrand(const base::Closure& callback, const std::string& brand) { |
39 g_browser_process->local_state()->SetString(prefs::kRLZBrand, brand); | 40 g_browser_process->local_state()->SetString(prefs::kRLZBrand, brand); |
40 callback.Run(); | 41 callback.Run(); |
41 } | 42 } |
42 | 43 |
44 base::LazyInstance<std::string> g_temporary_brand = LAZY_INSTANCE_INITIALIZER; | |
45 | |
43 } // namespace | 46 } // namespace |
44 | 47 |
48 void SetTemporaryBrand(const std::string& brand) { | |
49 DCHECK( | |
50 !content::BrowserThread::IsWellKnownThread(content::BrowserThread::UI) || | |
51 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
52 g_temporary_brand.Get().assign(brand); | |
53 } | |
54 | |
45 std::string GetBrand() { | 55 std::string GetBrand() { |
46 DCHECK( | 56 DCHECK( |
47 !content::BrowserThread::IsWellKnownThread(content::BrowserThread::UI) || | 57 !content::BrowserThread::IsWellKnownThread(content::BrowserThread::UI) || |
48 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 58 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
59 // Get() should not be called as it creates an instance. | |
60 if (!(g_temporary_brand == NULL)) | |
Peter Kasting
2012/12/11 20:21:49
Nit: Why not just use !=?
Ivan Korotkov
2012/12/12 13:05:56
LazyInstance has no operator!=. This looks like th
| |
61 return g_temporary_brand.Get(); | |
49 DCHECK(g_browser_process->local_state()); | 62 DCHECK(g_browser_process->local_state()); |
50 return g_browser_process->local_state()->GetString(prefs::kRLZBrand); | 63 return g_browser_process->local_state()->GetString(prefs::kRLZBrand); |
51 } | 64 } |
52 | 65 |
53 void SetBrandFromFile(const base::Closure& callback) { | 66 void SetBrandFromFile(const base::Closure& callback) { |
54 base::PostTaskAndReplyWithResult( | 67 base::PostTaskAndReplyWithResult( |
55 base::WorkerPool::GetTaskRunner(false /* task_is_slow */), | 68 base::WorkerPool::GetTaskRunner(false /* task_is_slow */), |
56 FROM_HERE, | 69 FROM_HERE, |
57 base::Bind(&ReadBrandFromFile), | 70 base::Bind(&ReadBrandFromFile), |
58 base::Bind(&SetBrand, callback)); | 71 base::Bind(&SetBrand, callback)); |
59 } | 72 } |
60 | 73 |
61 } // namespace chromeos | 74 } // namespace chromeos |
62 } // namespace google_util | 75 } // namespace google_util |
OLD | NEW |