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
3 // found in the LICENSE file.
5 #ifndef RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
6 #define RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
8 #include "base/files/file_path.h"
9 #include "base/threading/non_thread_safe.h"
10 #include "base/values.h"
11 #include "rlz/lib/rlz_value_store.h"
15 class SequencedTaskRunner
;
21 // An implementation of RlzValueStore for ChromeOS.
22 class RlzValueStoreChromeOS
: public RlzValueStore
,
23 public base::NonThreadSafe
{
25 // // Sets the task runner that will be used by ImportantFileWriter for write
27 // static void SetFileTaskRunner(base::SequencedTaskRunner* file_task_runner);
29 // Creates new instance and synchronously reads data from file.
30 RlzValueStoreChromeOS(const base::FilePath
& store_path
);
31 ~RlzValueStoreChromeOS() override
;
33 // RlzValueStore overrides:
34 bool HasAccess(AccessType type
) override
;
36 bool WritePingTime(Product product
, int64 time
) override
;
37 bool ReadPingTime(Product product
, int64
* time
) override
;
38 bool ClearPingTime(Product product
) override
;
40 bool WriteAccessPointRlz(AccessPoint access_point
,
41 const char* new_rlz
) override
;
42 bool ReadAccessPointRlz(AccessPoint access_point
,
44 size_t rlz_size
) override
;
45 bool ClearAccessPointRlz(AccessPoint access_point
) override
;
47 bool AddProductEvent(Product product
, const char* event_rlz
) override
;
48 bool ReadProductEvents(Product product
,
49 std::vector
<std::string
>* events
) override
;
50 bool ClearProductEvent(Product product
, const char* event_rlz
) override
;
51 bool ClearAllProductEvents(Product product
) override
;
53 bool AddStatefulEvent(Product product
, const char* event_rlz
) override
;
54 bool IsStatefulEvent(Product product
, const char* event_rlz
) override
;
55 bool ClearAllStatefulEvents(Product product
) override
;
57 void CollectGarbage() override
;
60 // Reads RLZ store from file.
63 // Writes RLZ store back to file.
66 // Adds |value| to list at |list_name| path in JSON store.
67 bool AddValueToList(const std::string
& list_name
, base::Value
* value
);
68 // Removes |value| from list at |list_name| path in JSON store.
69 bool RemoveValueFromList(const std::string
& list_name
,
70 const base::Value
& value
);
72 // In-memory store with RLZ data.
73 scoped_ptr
<base::DictionaryValue
> rlz_store_
;
75 base::FilePath store_path_
;
79 DISALLOW_COPY_AND_ASSIGN(RlzValueStoreChromeOS
);
82 } // namespace rlz_lib
84 #endif // RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_