Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Unified Diff: rlz/chromeos/lib/rlz_value_store_chromeos.h

Issue 11365107: [cros] RlzValueStore implementation for ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert to Chrome-only Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « rlz/chromeos/lib/machine_id_chromeos.cc ('k') | rlz/chromeos/lib/rlz_value_store_chromeos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: rlz/chromeos/lib/rlz_value_store_chromeos.h
diff --git a/rlz/mac/lib/rlz_value_store_mac.h b/rlz/chromeos/lib/rlz_value_store_chromeos.h
similarity index 44%
copy from rlz/mac/lib/rlz_value_store_mac.h
copy to rlz/chromeos/lib/rlz_value_store_chromeos.h
index b7ffb4e820ebf07657dec1fbf9cb10e10d16a891..245ae0081a8df9d540d52cfa28d1a192abbb31bb 100644
--- a/rlz/mac/lib/rlz_value_store_mac.h
+++ b/rlz/chromeos/lib/rlz_value_store_chromeos.h
@@ -2,22 +2,41 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef RLZ_MAC_LIB_RLZ_VALUE_STORE_MAC_H_
-#define RLZ_MAC_LIB_RLZ_VALUE_STORE_MAC_H_
+#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"
-#include "base/compiler_specific.h"
-#include "base/memory/scoped_nsobject.h"
-@class NSDictionary;
-@class NSMutableDictionary;
+namespace base {
+class ListValue;
+class SequencedTaskRunner;
+class Value;
+}
+
+template <typename T> struct DefaultSingletonTraits;
namespace rlz_lib {
-// An implementation of RlzValueStore for mac. It stores information in a
-// plist file in the user's Application Support folder.
-class RlzValueStoreMac : public RlzValueStore {
+// 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;
@@ -47,34 +66,32 @@ class RlzValueStoreMac : public RlzValueStore {
virtual void CollectGarbage() OVERRIDE;
private:
- // |dict| is the dictionary that backs all data. plist_path is the name of the
- // plist file, used solely for implementing HasAccess().
- RlzValueStoreMac(NSMutableDictionary* dict, NSString* plist_path);
- virtual ~RlzValueStoreMac();
- friend class ScopedRlzValueStoreLock;
-
- // Returns the backing dictionary that should be written to disk.
- NSDictionary* dictionary();
-
- // Returns the dictionary to which all data should be written. Usually, this
- // is just |dictionary()|, but if supplementary branding is used, it's a
- // subdirectory at key "brand_<supplementary branding code>".
- // Note that windows stores data at
- // rlz/name (e.g. "pingtime")/supplementalbranding/productcode
- // Mac on the other hand does
- // supplementalbranding/productcode/pingtime.
- NSMutableDictionary* WorkingDict();
-
- // Returns the subdirectory of |WorkingDict()| used to store data for
- // product p.
- NSMutableDictionary* ProductDict(Product p);
-
- scoped_nsobject<NSMutableDictionary> dict_;
- scoped_nsobject<NSString> plist_path_;
-
- DISALLOW_COPY_AND_ASSIGN(RlzValueStoreMac);
+ 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_MAC_LIB_RLZ_VALUE_STORE_MAC_H_
+#endif // RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
« no previous file with comments | « rlz/chromeos/lib/machine_id_chromeos.cc ('k') | rlz/chromeos/lib/rlz_value_store_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698