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

Side by Side 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 test helpers 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef RLZ_MAC_LIB_RLZ_VALUE_STORE_MAC_H_ 5 #ifndef RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
6 #define RLZ_MAC_LIB_RLZ_VALUE_STORE_MAC_H_ 6 #define RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
7 7
8 #include "base/prefs/persistent_pref_store.h"
9 #include "base/threading/non_thread_safe.h"
8 #include "rlz/lib/rlz_value_store.h" 10 #include "rlz/lib/rlz_value_store.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_nsobject.h"
11 11
12 @class NSDictionary; 12 namespace base {
13 @class NSMutableDictionary; 13 class ListValue;
14 class MessageLoopProxy;
15 class Value;
16 }
17
18 template <typename T> struct DefaultSingletonTraits;
14 19
15 namespace rlz_lib { 20 namespace rlz_lib {
16 21
17 // An implementation of RlzValueStore for mac. It stores information in a 22 // An implementation of RlzValueStore for ChromeOS. Unlike Mac and Win
18 // plist file in the user's Application Support folder. 23 // counterparts, it's non thread-safe and should only be accessed on a single
19 class RlzValueStoreMac : public RlzValueStore { 24 // Thread instance that has a MessageLoop.
Roger Tawa OOO till Jul 10th 2012/11/06 20:55:11 Why is that a valid assumption? I don't believe i
Ivan Korotkov 2012/11/07 10:49:12 Yes, currently RlzValueStore is accessed on a bloc
25 class RlzValueStoreChromeOS : public RlzValueStore,
26 public base::NonThreadSafe {
20 public: 27 public:
28 static RlzValueStoreChromeOS* GetInstance();
29
30 // Sets the MessageLoopProxy that underlying PersistentPrefStore will post I/O
31 // tasks to. Must be called before the first GetInstance() call.
32 static void SetIOTaskRunner(base::MessageLoopProxy* io_task_runner);
33
34 // RlzValueStore overrides:
21 virtual bool HasAccess(AccessType type) OVERRIDE; 35 virtual bool HasAccess(AccessType type) OVERRIDE;
22 36
23 virtual bool WritePingTime(Product product, int64 time) OVERRIDE; 37 virtual bool WritePingTime(Product product, int64 time) OVERRIDE;
24 virtual bool ReadPingTime(Product product, int64* time) OVERRIDE; 38 virtual bool ReadPingTime(Product product, int64* time) OVERRIDE;
25 virtual bool ClearPingTime(Product product) OVERRIDE; 39 virtual bool ClearPingTime(Product product) OVERRIDE;
26 40
27 virtual bool WriteAccessPointRlz(AccessPoint access_point, 41 virtual bool WriteAccessPointRlz(AccessPoint access_point,
28 const char* new_rlz) OVERRIDE; 42 const char* new_rlz) OVERRIDE;
29 virtual bool ReadAccessPointRlz(AccessPoint access_point, 43 virtual bool ReadAccessPointRlz(AccessPoint access_point,
30 char* rlz, 44 char* rlz,
31 size_t rlz_size) OVERRIDE; 45 size_t rlz_size) OVERRIDE;
32 virtual bool ClearAccessPointRlz(AccessPoint access_point) OVERRIDE; 46 virtual bool ClearAccessPointRlz(AccessPoint access_point) OVERRIDE;
33 47
34 virtual bool AddProductEvent(Product product, const char* event_rlz) OVERRIDE; 48 virtual bool AddProductEvent(Product product, const char* event_rlz) OVERRIDE;
35 virtual bool ReadProductEvents(Product product, 49 virtual bool ReadProductEvents(Product product,
36 std::vector<std::string>* events) OVERRIDE; 50 std::vector<std::string>* events) OVERRIDE;
37 virtual bool ClearProductEvent(Product product, 51 virtual bool ClearProductEvent(Product product,
38 const char* event_rlz) OVERRIDE; 52 const char* event_rlz) OVERRIDE;
39 virtual bool ClearAllProductEvents(Product product) OVERRIDE; 53 virtual bool ClearAllProductEvents(Product product) OVERRIDE;
40 54
41 virtual bool AddStatefulEvent(Product product, 55 virtual bool AddStatefulEvent(Product product,
42 const char* event_rlz) OVERRIDE; 56 const char* event_rlz) OVERRIDE;
43 virtual bool IsStatefulEvent(Product product, 57 virtual bool IsStatefulEvent(Product product,
44 const char* event_rlz) OVERRIDE; 58 const char* event_rlz) OVERRIDE;
45 virtual bool ClearAllStatefulEvents(Product product) OVERRIDE; 59 virtual bool ClearAllStatefulEvents(Product product) OVERRIDE;
46 60
47 virtual void CollectGarbage() OVERRIDE; 61 virtual void CollectGarbage() OVERRIDE;
48 62
49 private: 63 private:
50 // |dict| is the dictionary that backs all data. plist_path is the name of the 64 friend struct DefaultSingletonTraits<RlzValueStoreChromeOS>;
51 // plist file, used solely for implementing HasAccess().
52 RlzValueStoreMac(NSMutableDictionary* dict, NSString* plist_path);
53 virtual ~RlzValueStoreMac();
54 friend class ScopedRlzValueStoreLock;
55 65
56 // Returns the backing dictionary that should be written to disk. 66 // Used by JsonPrefStore to schedule write operations.
57 NSDictionary* dictionary(); 67 static base::MessageLoopProxy* io_task_runner_;
58 68
59 // Returns the dictionary to which all data should be written. Usually, this 69 RlzValueStoreChromeOS();
60 // is just |dictionary()|, but if supplementary branding is used, it's a 70 virtual ~RlzValueStoreChromeOS();
61 // subdirectory at key "brand_<supplementary branding code>".
62 // Note that windows stores data at
63 // rlz/name (e.g. "pingtime")/supplementalbranding/productcode
64 // Mac on the other hand does
65 // supplementalbranding/productcode/pingtime.
66 NSMutableDictionary* WorkingDict();
67 71
68 // Returns the subdirectory of |WorkingDict()| used to store data for 72 // Retrieves list at path |list_name| from JSON store.
69 // product p. 73 base::ListValue* GetList(std::string list_name);
70 NSMutableDictionary* ProductDict(Product p); 74 // Adds |value| to list at |list_name| path in JSON store.
75 bool AddValueToList(std::string list_name, base::Value* value);
76 // Removes |value| from list at |list_name| path in JSON store.
77 bool RemoveValueFromList(std::string list_name, const base::Value& value);
71 78
72 scoped_nsobject<NSMutableDictionary> dict_; 79 // Store with RLZ data.
73 scoped_nsobject<NSString> plist_path_; 80 scoped_refptr<PersistentPrefStore> rlz_store_;
74 81
75 DISALLOW_COPY_AND_ASSIGN(RlzValueStoreMac); 82 DISALLOW_COPY_AND_ASSIGN(RlzValueStoreChromeOS);
76 }; 83 };
77 84
78 } // namespace rlz_lib 85 } // namespace rlz_lib
79 86
80 #endif // RLZ_MAC_LIB_RLZ_VALUE_STORE_MAC_H_ 87 #endif // RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698