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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// Copyright 2016 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 COMPONENTS_UPDATE_CLIENT_PERSISTED_DATA_H_
#define COMPONENTS_UPDATE_CLIENT_PERSISTED_DATA_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/sequence_checker.h"
#include "base/values.h"
class PrefRegistrySimple;
class PrefService;
namespace base {
class Version;
} // namespace base
namespace update_client {
class ActivityDataService;
// A PersistedData is a wrapper layer around a PrefService, designed to maintain
// update data that outlives the browser process and isn't exposed outside of
// update_client.
//
// The public methods of this class should be called only on the thread that
// initializes it - which also has to match the thread the PrefService has been
// initialized on.
class PersistedData {
public:
// Constructs a provider using the specified |pref_service| and
// |activity_data_service|.
// The associated preferences are assumed to already be registered.
// The |pref_service| and |activity_data_service| must outlive the entire
// update_client.
PersistedData(PrefService* pref_service,
ActivityDataService* activity_data_service);
~PersistedData();
// Returns the DateLastRollCall (the server-localized calendar date number the
// |id| was last checked by this client on) for the specified |id|.
// -2 indicates that there is no recorded date number for the |id|.
int GetDateLastRollCall(const std::string& id) const;
// Returns the DateLastActive (the server-localized calendar date number the
// |id| was last active by this client on) for the specified |id|.
// -1 indicates that there is no recorded date for the |id| (i.e. this is the
// first time the |id| is active).
// -2 indicates that the |id| has an unknown value of last active date.
int GetDateLastActive(const std::string& id) const;
// Returns the PingFreshness (a random token that is written into the profile
// data whenever the DateLastRollCall it is modified) for the specified |id|.
// "" indicates that there is no recorded freshness value for the |id|.
std::string GetPingFreshness(const std::string& id) const;
// Records the DateLastRollCall for the specified |ids|. |datenum| must be a
// non-negative integer: calls with a negative |datenum| are simply ignored.
// Calls to SetDateLastRollCall that occur prior to the persisted data store
// has been fully initialized are ignored. Also sets the PingFreshness.
void SetDateLastRollCall(const std::vector<std::string>& ids, int datenum);
// Records the DateLastActive for the specified |ids|. |datenum| must be a
// non-negative integer: calls with a negative |datenum| are simply ignored.
// Calls to SetDateLastActive that occur prior to the persisted data store
// has been fully initialized or the active bit of the |ids| are not set
// are ignored.
// This function also clears the active bits of the specified |ids| if they
// are set.
void SetDateLastActive(const std::vector<std::string>& ids, int datenum);
// This is called only via update_client's RegisterUpdateClientPreferences.
static void RegisterPrefs(PrefRegistrySimple* registry);
// These functions return cohort data for the specified |id|. "Cohort"
// indicates the membership of the client in any release channels components
// have set up in a machine-readable format, while "CohortName" does so in a
// human-readable form. "CohortHint" indicates the client's channel selection
// preference.
std::string GetCohort(const std::string& id) const;
std::string GetCohortHint(const std::string& id) const;
std::string GetCohortName(const std::string& id) const;
// These functions set cohort data for the specified |id|.
void SetCohort(const std::string& id, const std::string& cohort);
void SetCohortHint(const std::string& id, const std::string& cohort_hint);
void SetCohortName(const std::string& id, const std::string& cohort_name);
// Returns true if the active bit of the specified |id| is set.
bool GetActiveBit(const std::string& id) const;
// The following two functions returns the number of days since the last
// time the client checked for update/was active.
// -1 indicates that this is the first time the client reports
// an update check/active for the specified |id|.
// -2 indicates that the client has no information about the
// update check/last active of the specified |id|.
int GetDaysSinceLastRollCall(const std::string& id) const;
int GetDaysSinceLastActive(const std::string& id) const;
// These functions access |pv| data for the specified |id|. Returns an empty
// version, if the version is not found.
base::Version GetProductVersion(const std::string& id) const;
void SetProductVersion(const std::string& id, const base::Version& pv);
// These functions access the fingerprint for the specified |id|.
std::string GetFingerprint(const std::string& id) const;
void SetFingerprint(const std::string& id, const std::string& fingerprint);
private:
// Returns nullptr if the app key does not exist.
const base::Value* GetAppKey(const std::string& id) const;
// Returns an existing or newly created app key under a root pref.
base::Value* GetOrCreateAppKey(const std::string& id, base::Value* root);
// Returns fallback if the key does not exist.
int GetInt(const std::string& id, const std::string& key, int fallback) const;
// Returns the empty string if the key does not exist.
std::string GetString(const std::string& id, const std::string& key) const;
void SetString(const std::string& id,
const std::string& key,
const std::string& value);
SEQUENCE_CHECKER(sequence_checker_);
PrefService* pref_service_;
ActivityDataService* activity_data_service_;
DISALLOW_COPY_AND_ASSIGN(PersistedData);
};
} // namespace update_client
#endif // COMPONENTS_UPDATE_CLIENT_PERSISTED_DATA_H_
|