Index: chrome/browser/google/google_util_chromeos.cc |
diff --git a/chrome/browser/google/google_util_chromeos.cc b/chrome/browser/google/google_util_chromeos.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..769c73e1fa6ace913690f590f40898aa123d4e67 |
--- /dev/null |
+++ b/chrome/browser/google/google_util_chromeos.cc |
@@ -0,0 +1,62 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/basictypes.h" |
+#include "base/bind.h" |
+#include "base/file_path.h" |
+#include "base/file_util.h" |
+#include "base/logging.h" |
+#include "base/string_util.h" |
+#include "base/threading/worker_pool.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/prefs/pref_service.h" |
+#include "chrome/common/pref_names.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+using content::BrowserThread; |
+ |
+namespace google_util { |
+namespace chromeos { |
+ |
+namespace { |
+ |
+// Path to file that stores the RLZ brand code on ChromeOS. |
+const char kRLZBrandFilePath[] = |
+ FILE_PATH_LITERAL("/opt/oem/etc/rlz_brand_code"); |
+ |
+// Reads the brand code from file |kRLZBrandFilePath| to |brand|. |
+void ReadBrandFromFile(std::string* brand) { |
+ FilePath brand_file_path(kRLZBrandFilePath); |
+ if (!file_util::ReadFileToString(brand_file_path, brand)) |
+ 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.
|
+ TrimWhitespace(*brand, TRIM_ALL, brand); |
+} |
+ |
+// Sets the brand code to |brand|. |
+void SetBrand(std::string* brand, const base::Closure& callback) { |
+ g_browser_process->local_state()->SetString(prefs::kRLZBrand, *brand); |
+ delete brand; |
+ callback.Run(); |
+} |
+ |
+} // namespace |
+ |
+std::string GetBrand() { |
+ 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 :)
|
+ BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ PrefService* local_state = g_browser_process->local_state(); |
+ 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
|
+} |
+ |
+void SetBrandFromFile(const base::Closure& callback) { |
+ 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!
|
+ base::WorkerPool::PostTaskAndReply( |
+ FROM_HERE, |
+ base::Bind(&ReadBrandFromFile, brand), |
+ base::Bind(&SetBrand, brand, callback), |
+ /* task_is_slow= */ false); |
+} |
+ |
+} // namespace chromeos |
+} // namespace google_util |