| OLD | NEW |
| 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 SequencedTaskRunner; |
| 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. |
| 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::SequencedTaskRunner* io_task_runner); |
| 33 |
| 34 // Resets the store to its initial state. Should only be used for testing. |
| 35 // Same restrictions as for calling GetInstance() for the first time apply, |
| 36 // i.e. must call SetIOTaskRunner first. |
| 37 static void ResetForTesting(); |
| 38 |
| 39 // RlzValueStore overrides: |
| 21 virtual bool HasAccess(AccessType type) OVERRIDE; | 40 virtual bool HasAccess(AccessType type) OVERRIDE; |
| 22 | 41 |
| 23 virtual bool WritePingTime(Product product, int64 time) OVERRIDE; | 42 virtual bool WritePingTime(Product product, int64 time) OVERRIDE; |
| 24 virtual bool ReadPingTime(Product product, int64* time) OVERRIDE; | 43 virtual bool ReadPingTime(Product product, int64* time) OVERRIDE; |
| 25 virtual bool ClearPingTime(Product product) OVERRIDE; | 44 virtual bool ClearPingTime(Product product) OVERRIDE; |
| 26 | 45 |
| 27 virtual bool WriteAccessPointRlz(AccessPoint access_point, | 46 virtual bool WriteAccessPointRlz(AccessPoint access_point, |
| 28 const char* new_rlz) OVERRIDE; | 47 const char* new_rlz) OVERRIDE; |
| 29 virtual bool ReadAccessPointRlz(AccessPoint access_point, | 48 virtual bool ReadAccessPointRlz(AccessPoint access_point, |
| 30 char* rlz, | 49 char* rlz, |
| 31 size_t rlz_size) OVERRIDE; | 50 size_t rlz_size) OVERRIDE; |
| 32 virtual bool ClearAccessPointRlz(AccessPoint access_point) OVERRIDE; | 51 virtual bool ClearAccessPointRlz(AccessPoint access_point) OVERRIDE; |
| 33 | 52 |
| 34 virtual bool AddProductEvent(Product product, const char* event_rlz) OVERRIDE; | 53 virtual bool AddProductEvent(Product product, const char* event_rlz) OVERRIDE; |
| 35 virtual bool ReadProductEvents(Product product, | 54 virtual bool ReadProductEvents(Product product, |
| 36 std::vector<std::string>* events) OVERRIDE; | 55 std::vector<std::string>* events) OVERRIDE; |
| 37 virtual bool ClearProductEvent(Product product, | 56 virtual bool ClearProductEvent(Product product, |
| 38 const char* event_rlz) OVERRIDE; | 57 const char* event_rlz) OVERRIDE; |
| 39 virtual bool ClearAllProductEvents(Product product) OVERRIDE; | 58 virtual bool ClearAllProductEvents(Product product) OVERRIDE; |
| 40 | 59 |
| 41 virtual bool AddStatefulEvent(Product product, | 60 virtual bool AddStatefulEvent(Product product, |
| 42 const char* event_rlz) OVERRIDE; | 61 const char* event_rlz) OVERRIDE; |
| 43 virtual bool IsStatefulEvent(Product product, | 62 virtual bool IsStatefulEvent(Product product, |
| 44 const char* event_rlz) OVERRIDE; | 63 const char* event_rlz) OVERRIDE; |
| 45 virtual bool ClearAllStatefulEvents(Product product) OVERRIDE; | 64 virtual bool ClearAllStatefulEvents(Product product) OVERRIDE; |
| 46 | 65 |
| 47 virtual void CollectGarbage() OVERRIDE; | 66 virtual void CollectGarbage() OVERRIDE; |
| 48 | 67 |
| 49 private: | 68 private: |
| 50 // |dict| is the dictionary that backs all data. plist_path is the name of the | 69 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 | 70 |
| 56 // Returns the backing dictionary that should be written to disk. | 71 // Used by JsonPrefStore for write operations. |
| 57 NSDictionary* dictionary(); | 72 static base::SequencedTaskRunner* io_task_runner_; |
| 58 | 73 |
| 59 // Returns the dictionary to which all data should be written. Usually, this | 74 static bool created_; |
| 60 // is just |dictionary()|, but if supplementary branding is used, it's a | |
| 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 | 75 |
| 68 // Returns the subdirectory of |WorkingDict()| used to store data for | 76 RlzValueStoreChromeOS(); |
| 69 // product p. | 77 virtual ~RlzValueStoreChromeOS(); |
| 70 NSMutableDictionary* ProductDict(Product p); | |
| 71 | 78 |
| 72 scoped_nsobject<NSMutableDictionary> dict_; | 79 // Initializes RLZ store. |
| 73 scoped_nsobject<NSString> plist_path_; | 80 void ReadPrefs(); |
| 74 | 81 |
| 75 DISALLOW_COPY_AND_ASSIGN(RlzValueStoreMac); | 82 // Retrieves list at path |list_name| from JSON store. |
| 83 base::ListValue* GetList(std::string list_name); |
| 84 // Adds |value| to list at |list_name| path in JSON store. |
| 85 bool AddValueToList(std::string list_name, base::Value* value); |
| 86 // Removes |value| from list at |list_name| path in JSON store. |
| 87 bool RemoveValueFromList(std::string list_name, const base::Value& value); |
| 88 |
| 89 // Store with RLZ data. |
| 90 scoped_refptr<PersistentPrefStore> rlz_store_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(RlzValueStoreChromeOS); |
| 76 }; | 93 }; |
| 77 | 94 |
| 78 } // namespace rlz_lib | 95 } // namespace rlz_lib |
| 79 | 96 |
| 80 #endif // RLZ_MAC_LIB_RLZ_VALUE_STORE_MAC_H_ | 97 #endif // RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_ |
| OLD | NEW |