summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-09 11:04:55 +0000
committerivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-09 11:04:55 +0000
commit7d21a6b37c15011033601f49150e280c2417ce1d (patch)
tree8a893f4b29f773643df8bdef5102b77cf55627a8
parentc80ca12f3e74e8d54653c312bbd3c92afd0fee55 (diff)
downloadchromium_src-7d21a6b37c15011033601f49150e280c2417ce1d.zip
chromium_src-7d21a6b37c15011033601f49150e280c2417ce1d.tar.gz
chromium_src-7d21a6b37c15011033601f49150e280c2417ce1d.tar.bz2
[cros] RlzValueStore implementation for ChromeOS.
BUG=157348 TEST=rlz_unittests Review URL: https://chromiumcodereview.appspot.com/11365107 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166891 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--rlz/chromeos/lib/machine_id_chromeos.cc14
-rw-r--r--rlz/chromeos/lib/rlz_value_store_chromeos.cc284
-rw-r--r--rlz/chromeos/lib/rlz_value_store_chromeos.h97
-rw-r--r--rlz/lib/financial_ping.cc24
-rw-r--r--rlz/lib/lib_values.cc6
-rw-r--r--rlz/lib/rlz_enums.h15
-rw-r--r--rlz/lib/rlz_lib.cc10
-rw-r--r--rlz/lib/rlz_lib.h12
-rw-r--r--rlz/lib/rlz_value_store.h11
-rw-r--r--rlz/rlz.gyp4
-rw-r--r--rlz/test/rlz_test_helpers.cc27
-rw-r--r--rlz/test/rlz_test_helpers.h15
12 files changed, 495 insertions, 24 deletions
diff --git a/rlz/chromeos/lib/machine_id_chromeos.cc b/rlz/chromeos/lib/machine_id_chromeos.cc
new file mode 100644
index 0000000..608fd03
--- /dev/null
+++ b/rlz/chromeos/lib/machine_id_chromeos.cc
@@ -0,0 +1,14 @@
+// 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 "rlz/lib/machine_id.h"
+
+namespace rlz_lib {
+
+bool GetRawMachineId(string16* data, int* more_data) {
+ // Machine IDs are not tracked for ChromeOS.
+ return false;
+}
+
+} // namespace rlz_lib
diff --git a/rlz/chromeos/lib/rlz_value_store_chromeos.cc b/rlz/chromeos/lib/rlz_value_store_chromeos.cc
new file mode 100644
index 0000000..2f75887
--- /dev/null
+++ b/rlz/chromeos/lib/rlz_value_store_chromeos.cc
@@ -0,0 +1,284 @@
+// 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 "rlz/chromeos/lib/rlz_value_store_chromeos.h"
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "base/prefs/json_pref_store.h"
+#include "base/sequenced_task_runner.h"
+#include "base/string_number_conversions.h"
+#include "base/values.h"
+#include "rlz/lib/lib_values.h"
+#include "rlz/lib/recursive_lock.h"
+#include "rlz/lib/rlz_lib.h"
+
+namespace rlz_lib {
+
+namespace {
+
+// Product names.
+const char kProductChrome[] = "chrome";
+const char kProductOther[] = "other";
+
+// Key names.
+const char kPingTimeKey[] = "ping_time";
+const char kAccessPointKey[] = "access_points";
+const char kProductEventKey[] = "product_events";
+const char kStatefulEventKey[] = "stateful_events";
+
+// Brand name used when there is no supplementary brand name.
+const char kNoSupplementaryBrand[] = "_";
+
+// RLZ store filename.
+const FilePath::CharType kRLZDataFileName[] = FILE_PATH_LITERAL("RLZ Data");
+
+// RLZ store path for testing.
+FilePath g_testing_rlz_store_path_;
+
+// Returns file path of the RLZ storage.
+FilePath GetRlzStorePath() {
+ return g_testing_rlz_store_path_.empty() ?
+ file_util::GetHomeDir().Append(kRLZDataFileName) :
+ g_testing_rlz_store_path_.Append(kRLZDataFileName);
+}
+
+// Returns the dictionary key for storing access point-related prefs.
+std::string GetKeyName(std::string key, AccessPoint access_point) {
+ std::string brand = SupplementaryBranding::GetBrand();
+ if (brand.empty())
+ brand = kNoSupplementaryBrand;
+ return key + "." + GetAccessPointName(access_point) + "." + brand;
+}
+
+// Returns the dictionary key for storing product-related prefs.
+std::string GetKeyName(std::string key, Product product) {
+ std::string brand = SupplementaryBranding::GetBrand();
+ if (brand.empty())
+ brand = kNoSupplementaryBrand;
+ return key + "." + GetProductName(product) + "." + brand;
+}
+
+} // namespace
+
+// static
+base::SequencedTaskRunner* RlzValueStoreChromeOS::io_task_runner_ = NULL;
+
+// static
+bool RlzValueStoreChromeOS::created_;
+
+// static
+RlzValueStoreChromeOS* RlzValueStoreChromeOS::GetInstance() {
+ return Singleton<RlzValueStoreChromeOS>::get();
+}
+
+// static
+void RlzValueStoreChromeOS::SetIOTaskRunner(
+ base::SequencedTaskRunner* io_task_runner) {
+ io_task_runner_ = io_task_runner;
+ // Make sure |io_task_runner_| lives until constructor is called.
+ io_task_runner_->AddRef();
+}
+
+// static
+void RlzValueStoreChromeOS::ResetForTesting() {
+ // Make sure we don't create an instance if it didn't exist.
+ if (created_)
+ GetInstance()->ReadPrefs();
+}
+
+RlzValueStoreChromeOS::RlzValueStoreChromeOS() {
+ ReadPrefs();
+ created_ = true;
+}
+
+RlzValueStoreChromeOS::~RlzValueStoreChromeOS() {
+}
+
+bool RlzValueStoreChromeOS::HasAccess(AccessType type) {
+ return type == kReadAccess || !rlz_store_->ReadOnly();
+}
+
+bool RlzValueStoreChromeOS::WritePingTime(Product product, int64 time) {
+ std::string value = base::Int64ToString(time);
+ rlz_store_->SetValue(GetKeyName(kPingTimeKey, product),
+ base::Value::CreateStringValue(value));
+ return true;
+}
+
+bool RlzValueStoreChromeOS::ReadPingTime(Product product, int64* time) {
+ const base::Value* value = NULL;
+ rlz_store_->GetValue(GetKeyName(kPingTimeKey, product), &value);
+ std::string s_value;
+ return value && value->GetAsString(&s_value) &&
+ base::StringToInt64(s_value, time);
+}
+
+bool RlzValueStoreChromeOS::ClearPingTime(Product product) {
+ rlz_store_->RemoveValue(GetKeyName(kPingTimeKey, product));
+ return true;
+}
+
+bool RlzValueStoreChromeOS::WriteAccessPointRlz(AccessPoint access_point,
+ const char* new_rlz) {
+ rlz_store_->SetValue(
+ GetKeyName(kAccessPointKey, access_point),
+ base::Value::CreateStringValue(new_rlz));
+ return true;
+}
+
+bool RlzValueStoreChromeOS::ReadAccessPointRlz(AccessPoint access_point,
+ char* rlz,
+ size_t rlz_size) {
+ const base::Value* value = NULL;
+ rlz_store_->GetValue(
+ GetKeyName(kAccessPointKey, access_point), &value);
+ std::string s_value;
+ if (value)
+ value->GetAsString(&s_value);
+ if (s_value.size() < rlz_size) {
+ strncpy(rlz, s_value.c_str(), rlz_size);
+ return true;
+ }
+ if (rlz_size > 0)
+ *rlz = '\0';
+ return false;
+}
+
+bool RlzValueStoreChromeOS::ClearAccessPointRlz(AccessPoint access_point) {
+ rlz_store_->RemoveValue(
+ GetKeyName(kAccessPointKey, access_point));
+ return true;
+}
+
+bool RlzValueStoreChromeOS::AddProductEvent(Product product,
+ const char* event_rlz) {
+ return AddValueToList(GetKeyName(kProductEventKey, product),
+ base::Value::CreateStringValue(event_rlz));
+}
+
+bool RlzValueStoreChromeOS::ReadProductEvents(
+ Product product,
+ std::vector<std::string>* events) {
+ base::ListValue* events_list = GetList(GetKeyName(kProductEventKey, product));
+ if (!events_list)
+ return false;
+ events->clear();
+ for (size_t i = 0; i < events_list->GetSize(); ++i) {
+ std::string event;
+ if (events_list->GetString(i, &event))
+ events->push_back(event);
+ }
+ return true;
+}
+
+bool RlzValueStoreChromeOS::ClearProductEvent(Product product,
+ const char* event_rlz) {
+ base::StringValue event_value(event_rlz);
+ return RemoveValueFromList(GetKeyName(kProductEventKey, product),
+ event_value);
+}
+
+bool RlzValueStoreChromeOS::ClearAllProductEvents(Product product) {
+ rlz_store_->RemoveValue(GetKeyName(kProductEventKey, product));
+ return true;
+}
+
+bool RlzValueStoreChromeOS::AddStatefulEvent(Product product,
+ const char* event_rlz) {
+ return AddValueToList(GetKeyName(kStatefulEventKey, product),
+ base::Value::CreateStringValue(event_rlz));
+}
+
+bool RlzValueStoreChromeOS::IsStatefulEvent(Product product,
+ const char* event_rlz) {
+ base::ListValue* events_list =
+ GetList(GetKeyName(kStatefulEventKey, product));
+ base::StringValue event_value(event_rlz);
+ return events_list && events_list->Find(event_value) != events_list->end();
+}
+
+bool RlzValueStoreChromeOS::ClearAllStatefulEvents(Product product) {
+ rlz_store_->RemoveValue(GetKeyName(kStatefulEventKey, product));
+ return true;
+}
+
+void RlzValueStoreChromeOS::CollectGarbage() {
+ NOTIMPLEMENTED();
+}
+
+void RlzValueStoreChromeOS::ReadPrefs() {
+ DCHECK(io_task_runner_)
+ << "Calling GetInstance or ResetForTesting before SetIOTaskRunner?";
+ rlz_store_ = new JsonPrefStore(GetRlzStorePath(), io_task_runner_);
+ rlz_store_->ReadPrefs();
+ switch (rlz_store_->GetReadError()) {
+ case PersistentPrefStore::PREF_READ_ERROR_NONE:
+ case PersistentPrefStore::PREF_READ_ERROR_NO_FILE:
+ break;
+ default:
+ LOG(ERROR) << "Error read RLZ store: " << rlz_store_->GetReadError();
+ }
+ // Restore refcount modified by SetIOTaskRunner().
+ io_task_runner_->Release();
+ io_task_runner_ = NULL;
+}
+
+base::ListValue* RlzValueStoreChromeOS::GetList(std::string list_name) {
+ base::Value* list_value = NULL;
+ rlz_store_->GetMutableValue(list_name, &list_value);
+ base::ListValue* list = NULL;
+ if (!list_value || !list_value->GetAsList(&list))
+ return NULL;
+ return list;
+}
+
+bool RlzValueStoreChromeOS::AddValueToList(std::string list_name,
+ base::Value* value) {
+ base::ListValue* list = GetList(list_name);
+ if (!list) {
+ list = new base::ListValue;
+ rlz_store_->SetValue(list_name, list);
+ }
+ if (list->AppendIfNotPresent(value))
+ rlz_store_->ReportValueChanged(list_name);
+ return true;
+}
+
+bool RlzValueStoreChromeOS::RemoveValueFromList(std::string list_name,
+ const base::Value& value) {
+ base::ListValue* list = GetList(list_name);
+ if (!list)
+ return false;
+ rlz_store_->MarkNeedsEmptyValue(list_name);
+ size_t index;
+ if (list->Remove(value, &index))
+ rlz_store_->ReportValueChanged(list_name);
+ return true;
+}
+
+
+ScopedRlzValueStoreLock::ScopedRlzValueStoreLock()
+ : store_(RlzValueStoreChromeOS::GetInstance()) {
+ DCHECK(store_->CalledOnValidThread());
+}
+
+ScopedRlzValueStoreLock::~ScopedRlzValueStoreLock() {
+}
+
+RlzValueStore* ScopedRlzValueStoreLock::GetStore() {
+ return store_;
+}
+
+namespace testing {
+
+void SetRlzStoreDirectory(const FilePath& directory) {
+ g_testing_rlz_store_path_ = directory;
+}
+
+} // namespace testing
+
+} // namespace rlz_lib
diff --git a/rlz/chromeos/lib/rlz_value_store_chromeos.h b/rlz/chromeos/lib/rlz_value_store_chromeos.h
new file mode 100644
index 0000000..245ae00
--- /dev/null
+++ b/rlz/chromeos/lib/rlz_value_store_chromeos.h
@@ -0,0 +1,97 @@
+// 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.
+
+#ifndef RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
+#define RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
+
+#include "base/prefs/persistent_pref_store.h"
+#include "base/threading/non_thread_safe.h"
+#include "rlz/lib/rlz_value_store.h"
+
+namespace base {
+class ListValue;
+class SequencedTaskRunner;
+class Value;
+}
+
+template <typename T> struct DefaultSingletonTraits;
+
+namespace rlz_lib {
+
+// An implementation of RlzValueStore for ChromeOS. Unlike Mac and Win
+// counterparts, it's non thread-safe and should only be accessed on a single
+// Thread instance that has a MessageLoop.
+class RlzValueStoreChromeOS : public RlzValueStore,
+ public base::NonThreadSafe {
+ public:
+ static RlzValueStoreChromeOS* GetInstance();
+
+ // Sets the MessageLoopProxy that underlying PersistentPrefStore will post I/O
+ // tasks to. Must be called before the first GetInstance() call.
+ static void SetIOTaskRunner(base::SequencedTaskRunner* io_task_runner);
+
+ // Resets the store to its initial state. Should only be used for testing.
+ // Same restrictions as for calling GetInstance() for the first time apply,
+ // i.e. must call SetIOTaskRunner first.
+ static void ResetForTesting();
+
+ // RlzValueStore overrides:
+ virtual bool HasAccess(AccessType type) OVERRIDE;
+
+ virtual bool WritePingTime(Product product, int64 time) OVERRIDE;
+ virtual bool ReadPingTime(Product product, int64* time) OVERRIDE;
+ virtual bool ClearPingTime(Product product) OVERRIDE;
+
+ virtual bool WriteAccessPointRlz(AccessPoint access_point,
+ const char* new_rlz) OVERRIDE;
+ virtual bool ReadAccessPointRlz(AccessPoint access_point,
+ char* rlz,
+ size_t rlz_size) OVERRIDE;
+ virtual bool ClearAccessPointRlz(AccessPoint access_point) OVERRIDE;
+
+ virtual bool AddProductEvent(Product product, const char* event_rlz) OVERRIDE;
+ virtual bool ReadProductEvents(Product product,
+ std::vector<std::string>* events) OVERRIDE;
+ virtual bool ClearProductEvent(Product product,
+ const char* event_rlz) OVERRIDE;
+ virtual bool ClearAllProductEvents(Product product) OVERRIDE;
+
+ virtual bool AddStatefulEvent(Product product,
+ const char* event_rlz) OVERRIDE;
+ virtual bool IsStatefulEvent(Product product,
+ const char* event_rlz) OVERRIDE;
+ virtual bool ClearAllStatefulEvents(Product product) OVERRIDE;
+
+ virtual void CollectGarbage() OVERRIDE;
+
+ private:
+ friend struct DefaultSingletonTraits<RlzValueStoreChromeOS>;
+
+ // Used by JsonPrefStore for write operations.
+ static base::SequencedTaskRunner* io_task_runner_;
+
+ static bool created_;
+
+ RlzValueStoreChromeOS();
+ virtual ~RlzValueStoreChromeOS();
+
+ // Initializes RLZ store.
+ void ReadPrefs();
+
+ // Retrieves list at path |list_name| from JSON store.
+ base::ListValue* GetList(std::string list_name);
+ // Adds |value| to list at |list_name| path in JSON store.
+ bool AddValueToList(std::string list_name, base::Value* value);
+ // Removes |value| from list at |list_name| path in JSON store.
+ bool RemoveValueFromList(std::string list_name, const base::Value& value);
+
+ // Store with RLZ data.
+ scoped_refptr<PersistentPrefStore> rlz_store_;
+
+ DISALLOW_COPY_AND_ASSIGN(RlzValueStoreChromeOS);
+};
+
+} // namespace rlz_lib
+
+#endif // RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
diff --git a/rlz/lib/financial_ping.cc b/rlz/lib/financial_ping.cc
index aad3db3..9b7e319 100644
--- a/rlz/lib/financial_ping.cc
+++ b/rlz/lib/financial_ping.cc
@@ -46,6 +46,7 @@ class InternetHandle {
#include "base/bind.h"
#include "base/message_loop.h"
+#include "base/run_loop.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
#include "net/base/load_flags.h"
@@ -194,15 +195,18 @@ namespace {
class FinancialPingUrlFetcherDelegate : public net::URLFetcherDelegate {
public:
- FinancialPingUrlFetcherDelegate(MessageLoop* loop) : loop_(loop) { }
+ FinancialPingUrlFetcherDelegate(const base::Closure& callback)
+ : callback_(callback) {
+ }
virtual void OnURLFetchComplete(const net::URLFetcher* source);
+
private:
- MessageLoop* loop_;
+ base::Closure callback_;
};
void FinancialPingUrlFetcherDelegate::OnURLFetchComplete(
const net::URLFetcher* source) {
- loop_->Quit();
+ callback_.Run();
}
} // namespace
@@ -267,8 +271,12 @@ bool FinancialPing::PingServer(const char* request, std::string* response) {
return true;
#else
// Run a blocking event loop to match the win inet implementation.
- MessageLoop loop;
- FinancialPingUrlFetcherDelegate delegate(&loop);
+ scoped_ptr<MessageLoop> message_loop;
+ // Ensure that we have a MessageLoop.
+ if (!MessageLoop::current())
+ message_loop.reset(new MessageLoop);
+ base::RunLoop loop;
+ FinancialPingUrlFetcherDelegate delegate(loop.QuitClosure());
std::string url = base::StringPrintf("http://%s:%d%s",
kFinancialServer, kFinancialPort,
@@ -289,11 +297,11 @@ bool FinancialPing::PingServer(const char* request, std::string* response) {
fetcher->SetRequestContext(g_context);
const base::TimeDelta kTimeout = base::TimeDelta::FromMinutes(5);
- loop.PostTask(
+ MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&net::URLFetcher::Start, base::Unretained(fetcher.get())));
- loop.PostNonNestableDelayedTask(
- FROM_HERE, MessageLoop::QuitClosure(), kTimeout);
+ MessageLoop::current()->PostNonNestableDelayedTask(
+ FROM_HERE, loop.QuitClosure(), kTimeout);
loop.Run();
diff --git a/rlz/lib/lib_values.cc b/rlz/lib/lib_values.cc
index 68b91d8..9b2c850 100644
--- a/rlz/lib/lib_values.cc
+++ b/rlz/lib/lib_values.cc
@@ -95,9 +95,9 @@ const char* GetAccessPointName(AccessPoint point) {
case PARTNER_AP_5: return "V5";
case CHROME_MAC_OMNIBOX: return "C5";
case CHROME_MAC_HOME_PAGE: return "C6";
- case UNDEFINED_AP_J: return "RJ";
- case UNDEFINED_AP_K: return "RK";
- case UNDEFINED_AP_L: return "RL";
+ case CHROMEOS_OMNIBOX: return "CA";
+ case CHROMEOS_HOME_PAGE: return "CB";
+ case CHROMEOS_RESERVED: return "CC";
case UNDEFINED_AP_M: return "RM";
case UNDEFINED_AP_N: return "RN";
case UNDEFINED_AP_O: return "RO";
diff --git a/rlz/lib/rlz_enums.h b/rlz/lib/rlz_enums.h
index 630db11..0fd0513 100644
--- a/rlz/lib/rlz_enums.h
+++ b/rlz/lib/rlz_enums.h
@@ -21,8 +21,8 @@ enum AccessPoint {
GD_SEARCH_GADGET, // Search gadget when GD in sidebar mode.
GD_WEB_SERVER, // Boxes in web pages shown by local GD web server.
GD_OUTLOOK, // Search box installed within outlook by GD.
- CHROME_OMNIBOX, // Chrome searches through the address bar omnibox.
- CHROME_HOME_PAGE, // Chrome searches through Google as home page.
+ CHROME_OMNIBOX, // Chrome searches through the address bar omnibox (Win).
+ CHROME_HOME_PAGE, // Chrome searches through Google as home page (Win).
FFTB2_BOX, // Firefox Toolbar v2 Search Box.
FFTB3_BOX, // Firefox Toolbar v3+ Search Box.
PINYIN_IME_BHO, // Goopy Input Method Editor BHO (Pinyin).
@@ -55,15 +55,16 @@ enum AccessPoint {
PARTNER_AP_4,
PARTNER_AP_5,
- CHROME_MAC_OMNIBOX, // Chrome searches through the address bar omnibox (mac).
- CHROME_MAC_HOME_PAGE,// Chrome searches through Google as home page (mac).
+ CHROME_MAC_OMNIBOX, // Chrome searches through the address bar omnibox (Mac).
+ CHROME_MAC_HOME_PAGE,// Chrome searches through Google as home page (Mac).
+
+ CHROMEOS_OMNIBOX, // ChromeOS searches through the address bar omnibox.
+ CHROMEOS_HOME_PAGE, // ChromeOS searches through Google as home page.
+ CHROMEOS_RESERVED, // Reserved for ChromeOS.
// Unclaimed access points - should be used first before creating new APs.
// Please also make sure you re-name the enum before using an unclaimed value;
// this acts as a check to ensure we don't have collisions.
- UNDEFINED_AP_J,
- UNDEFINED_AP_K,
- UNDEFINED_AP_L,
UNDEFINED_AP_M,
UNDEFINED_AP_N,
UNDEFINED_AP_O,
diff --git a/rlz/lib/rlz_lib.cc b/rlz/lib/rlz_lib.cc
index 8a1b729..0f67cd4 100644
--- a/rlz/lib/rlz_lib.cc
+++ b/rlz/lib/rlz_lib.cc
@@ -16,6 +16,10 @@
#include "rlz/lib/rlz_value_store.h"
#include "rlz/lib/string_utils.h"
+#if defined(OS_CHROMEOS)
+#include "rlz/chromeos/lib/rlz_value_store_chromeos.h"
+#endif // defined(OS_CHROMEOS)
+
namespace {
// Event information returned from ping response.
@@ -214,6 +218,12 @@ bool SetURLRequestContext(net::URLRequestContextGetter* context) {
}
#endif
+#if defined(OS_CHROMEOS)
+void RLZ_LIB_API SetIOTaskRunner(base::SequencedTaskRunner* io_task_runner) {
+ RlzValueStoreChromeOS::SetIOTaskRunner(io_task_runner);
+}
+#endif
+
bool GetProductEventsAsCgi(Product product, char* cgi, size_t cgi_size) {
if (!cgi || cgi_size <= 0) {
ASSERT_STRING("GetProductEventsAsCgi: Invalid buffer");
diff --git a/rlz/lib/rlz_lib.h b/rlz/lib/rlz_lib.h
index 1f8be5c..a840741 100644
--- a/rlz/lib/rlz_lib.h
+++ b/rlz/lib/rlz_lib.h
@@ -44,6 +44,12 @@
#endif
#endif
+#if defined(OS_CHROMEOS)
+namespace base {
+class SequencedTaskRunner;
+} // namespace base
+#endif
+
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
namespace net {
class URLRequestContextGetter;
@@ -71,6 +77,12 @@ const size_t kMaxPingResponseLength = 0x4000; // 16K
bool RLZ_LIB_API SetURLRequestContext(net::URLRequestContextGetter* context);
#endif
+#if defined(OS_CHROMEOS)
+// Set the MessageLoopProxy used by RLZ store to run I/O tasks on. Should be
+// called before any other API calls.
+void RLZ_LIB_API SetIOTaskRunner(base::SequencedTaskRunner* io_task_runner);
+#endif
+
// RLZ storage functions.
// Get all the events reported by this product as a CGI string to append to
diff --git a/rlz/lib/rlz_value_store.h b/rlz/lib/rlz_value_store.h
index ab7279a..807f100 100644
--- a/rlz/lib/rlz_value_store.h
+++ b/rlz/lib/rlz_value_store.h
@@ -95,7 +95,12 @@ class ScopedRlzValueStoreLock {
RlzValueStore* GetStore();
private:
+#if defined(OS_WIN) || defined(OS_MACOSX)
+ // On ChromeOS, there is a singleton instance of RlzValueStore.
scoped_ptr<RlzValueStore> store_;
+#elif defined(OS_CHROMEOS)
+ class RlzValueStoreChromeOS* store_;
+#endif
#if defined(OS_WIN)
LibMutex lock_;
#elif defined(OS_MACOSX)
@@ -103,11 +108,15 @@ class ScopedRlzValueStoreLock {
#endif
};
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
namespace testing {
// Prefix |directory| to the path where the RLZ data file lives, for tests.
void SetRlzStoreDirectory(const FilePath& directory);
+} // namespace testing
+#endif // defined(OS_MACOSX) || defined(OS_CHROMEOS)
+#if defined(OS_MACOSX)
+namespace testing {
// Returns the path of the plist file used as data store.
std::string RlzPlistFilenameStr();
} // namespace testing
diff --git a/rlz/rlz.gyp b/rlz/rlz.gyp
index cdd66dc..3e04654 100644
--- a/rlz/rlz.gyp
+++ b/rlz/rlz.gyp
@@ -31,6 +31,9 @@
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
],
'sources': [
+ 'chromeos/lib/machine_id_chromeos.cc',
+ 'chromeos/lib/rlz_value_store_chromeos.cc',
+ 'chromeos/lib/rlz_value_store_chromeos.h',
'lib/assert.cc',
'lib/assert.h',
'lib/crc32.h',
@@ -108,6 +111,7 @@
'dependencies': [
':rlz_lib',
'../base/base.gyp:base',
+ '../base/base.gyp:base_prefs',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
'../third_party/zlib/zlib.gyp:zlib',
diff --git a/rlz/test/rlz_test_helpers.cc b/rlz/test/rlz_test_helpers.cc
index 1a1870a..4fe12d4 100644
--- a/rlz/test/rlz_test_helpers.cc
+++ b/rlz/test/rlz_test_helpers.cc
@@ -13,10 +13,13 @@
#include <shlwapi.h>
#include "base/win/registry.h"
#include "rlz/win/lib/rlz_lib.h"
-#elif defined(OS_MACOSX)
+#elif defined(OS_MACOSX) || defined(OS_CHROMEOS)
#include "base/file_path.h"
#include "rlz/lib/rlz_value_store.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "rlz/chromeos/lib/rlz_value_store_chromeos.h"
+#endif
#if defined(OS_WIN)
namespace {
@@ -60,22 +63,40 @@ void UndoOverrideRegistryHives() {
#endif // defined(OS_WIN)
+#if defined(OS_CHROMEOS)
+RlzLibTestNoMachineState::RlzLibTestNoMachineState()
+ : pref_store_io_thread_("test_rlz_pref_store_io_thread") {
+}
+#endif // defined(OS_CHROMEOS)
+
void RlzLibTestNoMachineState::SetUp() {
#if defined(OS_WIN)
OverrideRegistryHives();
#elif defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool pool;
+#endif // defined(OS_WIN)
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path());
-#endif // defined(OS_WIN)
+#endif // defined(OS_MACOSX) || defined(OS_CHROMEOS)
+#if defined(OS_CHROMEOS)
+ base::Thread::Options options;
+ options.message_loop_type = MessageLoop::TYPE_IO;
+ ASSERT_TRUE(pref_store_io_thread_.StartWithOptions(options));
+ rlz_lib::SetIOTaskRunner(pref_store_io_thread_.message_loop_proxy());
+ rlz_lib::RlzValueStoreChromeOS::ResetForTesting();
+#endif // defined(OS_CHROMEOS)
}
void RlzLibTestNoMachineState::TearDown() {
#if defined(OS_WIN)
UndoOverrideRegistryHives();
-#elif defined(OS_MACOSX)
+#elif defined(OS_MACOSX) || defined(OS_CHROMEOS)
rlz_lib::testing::SetRlzStoreDirectory(FilePath());
#endif // defined(OS_WIN)
+#if defined(OS_CHROMEOS)
+ pref_store_io_thread_.Stop();
+#endif // defined(OS_CHROMEOS)
}
void RlzLibTestBase::SetUp() {
diff --git a/rlz/test/rlz_test_helpers.h b/rlz/test/rlz_test_helpers.h
index 66bb525..6ca606d 100644
--- a/rlz/test/rlz_test_helpers.h
+++ b/rlz/test/rlz_test_helpers.h
@@ -10,19 +10,30 @@
#include "base/compiler_specific.h"
#include "testing/gtest/include/gtest/gtest.h"
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
#include "base/scoped_temp_dir.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "base/message_loop.h"
+#include "base/threading/thread.h"
+#endif
class RlzLibTestNoMachineState : public ::testing::Test {
protected:
+#if defined(OS_CHROMEOS)
+ RlzLibTestNoMachineState();
+#endif
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
ScopedTempDir temp_dir_;
#endif
+#if defined(OS_CHROMEOS)
+ base::Thread pref_store_io_thread_;
+ MessageLoop message_loop_;
+#endif
};
class RlzLibTestBase : public RlzLibTestNoMachineState {