| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 52 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 53 g_brand_empty = true; | 53 g_brand_empty = true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 std::string GetBrand() { | 56 std::string GetBrand() { |
| 57 DCHECK(!content::BrowserThread::IsThreadInitialized( | 57 DCHECK(!content::BrowserThread::IsThreadInitialized( |
| 58 content::BrowserThread::UI) || | 58 content::BrowserThread::UI) || |
| 59 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 59 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 60 if (g_brand_empty) | 60 if (g_brand_empty) |
| 61 return std::string(); | 61 return std::string(); |
| 62 DCHECK(g_browser_process->local_state()); | 62 // Unit tests do not have prefs. |
| 63 if (!g_browser_process->local_state()) |
| 64 return std::string(); |
| 63 return g_browser_process->local_state()->GetString(prefs::kRLZBrand); | 65 return g_browser_process->local_state()->GetString(prefs::kRLZBrand); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void InitBrand(const base::Closure& callback) { | 68 void InitBrand(const base::Closure& callback) { |
| 67 ::chromeos::system::StatisticsProvider* provider = | 69 ::chromeos::system::StatisticsProvider* provider = |
| 68 ::chromeos::system::StatisticsProvider::GetInstance(); | 70 ::chromeos::system::StatisticsProvider::GetInstance(); |
| 69 std::string brand; | 71 std::string brand; |
| 70 const bool found = provider->GetMachineStatistic( | 72 const bool found = provider->GetMachineStatistic( |
| 71 ::chromeos::system::kRlzBrandCodeKey, &brand); | 73 ::chromeos::system::kRlzBrandCodeKey, &brand); |
| 72 if (found && !brand.empty()) { | 74 if (found && !brand.empty()) { |
| 73 SetBrand(callback, brand); | 75 SetBrand(callback, brand); |
| 74 return; | 76 return; |
| 75 } | 77 } |
| 76 | 78 |
| 77 base::PostTaskAndReplyWithResult( | 79 base::PostTaskAndReplyWithResult( |
| 78 base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(), | 80 base::WorkerPool::GetTaskRunner(false /* task_is_slow */).get(), |
| 79 FROM_HERE, | 81 FROM_HERE, |
| 80 base::Bind(&ReadBrandFromFile), | 82 base::Bind(&ReadBrandFromFile), |
| 81 base::Bind(&SetBrand, callback)); | 83 base::Bind(&SetBrand, callback)); |
| 82 } | 84 } |
| 83 | 85 |
| 84 } // namespace chromeos | 86 } // namespace chromeos |
| 85 } // namespace google_brand | 87 } // namespace google_brand |
| OLD | NEW |