1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
#define RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
#include <stddef.h>
#include <stdint.h>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/threading/non_thread_safe.h"
#include "base/values.h"
#include "rlz/lib/rlz_value_store.h"
namespace base {
class ListValue;
class SequencedTaskRunner;
class Value;
}
namespace rlz_lib {
// An implementation of RlzValueStore for ChromeOS.
class RlzValueStoreChromeOS : public RlzValueStore,
public base::NonThreadSafe {
public:
// // Sets the task runner that will be used by ImportantFileWriter for write
// // operations.
// static void SetFileTaskRunner(base::SequencedTaskRunner* file_task_runner);
// Creates new instance and synchronously reads data from file.
RlzValueStoreChromeOS(const base::FilePath& store_path);
~RlzValueStoreChromeOS() override;
// RlzValueStore overrides:
bool HasAccess(AccessType type) override;
bool WritePingTime(Product product, int64_t time) override;
bool ReadPingTime(Product product, int64_t* time) override;
bool ClearPingTime(Product product) override;
bool WriteAccessPointRlz(AccessPoint access_point,
const char* new_rlz) override;
bool ReadAccessPointRlz(AccessPoint access_point,
char* rlz,
size_t rlz_size) override;
bool ClearAccessPointRlz(AccessPoint access_point) override;
bool AddProductEvent(Product product, const char* event_rlz) override;
bool ReadProductEvents(Product product,
std::vector<std::string>* events) override;
bool ClearProductEvent(Product product, const char* event_rlz) override;
bool ClearAllProductEvents(Product product) override;
bool AddStatefulEvent(Product product, const char* event_rlz) override;
bool IsStatefulEvent(Product product, const char* event_rlz) override;
bool ClearAllStatefulEvents(Product product) override;
void CollectGarbage() override;
private:
// Reads RLZ store from file.
void ReadStore();
// Writes RLZ store back to file.
void WriteStore();
// Adds |value| to list at |list_name| path in JSON store.
bool AddValueToList(const std::string& list_name, base::Value* value);
// Removes |value| from list at |list_name| path in JSON store.
bool RemoveValueFromList(const std::string& list_name,
const base::Value& value);
// In-memory store with RLZ data.
scoped_ptr<base::DictionaryValue> rlz_store_;
base::FilePath store_path_;
bool read_only_;
DISALLOW_COPY_AND_ASSIGN(RlzValueStoreChromeOS);
};
} // namespace rlz_lib
#endif // RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
|