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

Side by Side Diff: rlz/chromeos/lib/rlz_value_store_chromeos.h

Issue 11308196: [cros] RlzValueStore made protected by a cross-process lock and not persisted over browser lifetime… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years 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
« no previous file with comments | « chrome/browser/rlz/rlz_unittest.cc ('k') | rlz/chromeos/lib/rlz_value_store_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_ 5 #ifndef RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
6 #define RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_ 6 #define RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
7 7
8 #include "base/prefs/persistent_pref_store.h" 8 #include "base/file_path.h"
9 #include "base/threading/non_thread_safe.h" 9 #include "base/threading/non_thread_safe.h"
10 #include "base/values.h"
10 #include "rlz/lib/rlz_value_store.h" 11 #include "rlz/lib/rlz_value_store.h"
11 12
12 namespace base { 13 namespace base {
13 class ListValue; 14 class ListValue;
14 class SequencedTaskRunner; 15 class SequencedTaskRunner;
15 class Value; 16 class Value;
16 } 17 }
17 18
18 template <typename T> struct DefaultSingletonTraits;
19
20 namespace rlz_lib { 19 namespace rlz_lib {
21 20
22 // An implementation of RlzValueStore for ChromeOS. Unlike Mac and Win 21 // An implementation of RlzValueStore for ChromeOS.
23 // counterparts, it's non thread-safe and should only be accessed on a single 22 class RlzValueStoreChromeOS : public RlzValueStore,
24 // Thread instance that has a MessageLoop. 23 public base::NonThreadSafe {
25 class RlzValueStoreChromeOS : public RlzValueStore {
26 public: 24 public:
27 static RlzValueStoreChromeOS* GetInstance(); 25 // // Sets the task runner that will be used by ImportantFileWriter for write
26 // // operations.
27 // static void SetFileTaskRunner(base::SequencedTaskRunner* file_task_runner);
28 28
29 // Sets the MessageLoopProxy that underlying PersistentPrefStore will post I/O 29 // Creates new instance and synchronously reads data from file.
30 // tasks to. Must be called before the first GetInstance() call. 30 RlzValueStoreChromeOS(const FilePath& store_path);
31 static void SetIOTaskRunner(base::SequencedTaskRunner* io_task_runner); 31 virtual ~RlzValueStoreChromeOS();
32
33 // Must be invoked during shutdown to commit pending I/O.
34 static void Cleanup();
35
36 // Resets the store to its initial state. Should only be used for testing.
37 // Same restrictions as for calling GetInstance() for the first time apply,
38 // i.e. must call SetIOTaskRunner first.
39 static void ResetForTesting();
40 32
41 // RlzValueStore overrides: 33 // RlzValueStore overrides:
42 virtual bool HasAccess(AccessType type) OVERRIDE; 34 virtual bool HasAccess(AccessType type) OVERRIDE;
43 35
44 virtual bool WritePingTime(Product product, int64 time) OVERRIDE; 36 virtual bool WritePingTime(Product product, int64 time) OVERRIDE;
45 virtual bool ReadPingTime(Product product, int64* time) OVERRIDE; 37 virtual bool ReadPingTime(Product product, int64* time) OVERRIDE;
46 virtual bool ClearPingTime(Product product) OVERRIDE; 38 virtual bool ClearPingTime(Product product) OVERRIDE;
47 39
48 virtual bool WriteAccessPointRlz(AccessPoint access_point, 40 virtual bool WriteAccessPointRlz(AccessPoint access_point,
49 const char* new_rlz) OVERRIDE; 41 const char* new_rlz) OVERRIDE;
(...skipping 11 matching lines...) Expand all
61 53
62 virtual bool AddStatefulEvent(Product product, 54 virtual bool AddStatefulEvent(Product product,
63 const char* event_rlz) OVERRIDE; 55 const char* event_rlz) OVERRIDE;
64 virtual bool IsStatefulEvent(Product product, 56 virtual bool IsStatefulEvent(Product product,
65 const char* event_rlz) OVERRIDE; 57 const char* event_rlz) OVERRIDE;
66 virtual bool ClearAllStatefulEvents(Product product) OVERRIDE; 58 virtual bool ClearAllStatefulEvents(Product product) OVERRIDE;
67 59
68 virtual void CollectGarbage() OVERRIDE; 60 virtual void CollectGarbage() OVERRIDE;
69 61
70 private: 62 private:
71 friend struct DefaultSingletonTraits<RlzValueStoreChromeOS>; 63 // Reads RLZ store from file.
64 void ReadStore();
72 65
73 // Used by JsonPrefStore for write operations. 66 // Writes RLZ store back to file.
74 static base::SequencedTaskRunner* io_task_runner_; 67 void WriteStore();
75 68
76 static bool created_;
77
78 RlzValueStoreChromeOS();
79 virtual ~RlzValueStoreChromeOS();
80
81 // Initializes RLZ store.
82 void ReadPrefs();
83
84 // Retrieves list at path |list_name| from JSON store.
85 base::ListValue* GetList(std::string list_name);
86 // Adds |value| to list at |list_name| path in JSON store. 69 // Adds |value| to list at |list_name| path in JSON store.
87 bool AddValueToList(std::string list_name, base::Value* value); 70 bool AddValueToList(std::string list_name, base::Value* value);
88 // Removes |value| from list at |list_name| path in JSON store. 71 // Removes |value| from list at |list_name| path in JSON store.
89 bool RemoveValueFromList(std::string list_name, const base::Value& value); 72 bool RemoveValueFromList(std::string list_name, const base::Value& value);
90 73
91 // Store with RLZ data. 74 // In-memory store with RLZ data.
92 scoped_refptr<PersistentPrefStore> rlz_store_; 75 scoped_ptr<base::DictionaryValue> rlz_store_;
76
77 FilePath store_path_;
78
79 bool read_only_;
93 80
94 DISALLOW_COPY_AND_ASSIGN(RlzValueStoreChromeOS); 81 DISALLOW_COPY_AND_ASSIGN(RlzValueStoreChromeOS);
95 }; 82 };
96 83
97 } // namespace rlz_lib 84 } // namespace rlz_lib
98 85
99 #endif // RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_ 86 #endif // RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
OLDNEW
« no previous file with comments | « chrome/browser/rlz/rlz_unittest.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