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
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SYNC_SERVICE_GLUE_SYNC_TRANSPORT_DATA_PREFS_H_
#define COMPONENTS_SYNC_SERVICE_GLUE_SYNC_TRANSPORT_DATA_PREFS_H_
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/signin/public/base/gaia_id_hash.h"
#include "google_apis/gaia/gaia_id.h"
class PrefRegistrySimple;
class PrefService;
namespace syncer {
// Thin wrapper for "bookkeeping" sync preferences, such as the last synced
// time, whether the last shutdown was clean, etc. Does *NOT* include sync
// preferences which are directly user-controlled, such as the set of selected
// types.
//
// In order to use this class RegisterProfilePrefs() needs to be invoked first.
class SyncTransportDataPrefs {
public:
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
// `pref_service` must not be null and must outlive this object.
SyncTransportDataPrefs(PrefService* pref_service,
const signin::GaiaIdHash& gaia_id_hash);
SyncTransportDataPrefs(const SyncTransportDataPrefs&) = delete;
SyncTransportDataPrefs& operator=(const SyncTransportDataPrefs&) = delete;
~SyncTransportDataPrefs();
// Clears all account-keyed preferences for the current account (i.e. the one
// passed into the constructor).
void ClearForCurrentAccount();
// Clears all account-keyed preferences for all accounts that are NOT in
// `available_gaia_ids`.
static void KeepAccountSettingsPrefsOnlyForUsers(
PrefService* pref_service,
const std::vector<signin::GaiaIdHash>& available_gaia_ids);
// The Gaia ID for which the sync machinery was last active, and for which
// there may be data around. Cleared when sync gets disabled (typically on
// signout) and data was removed.
void SetCurrentSyncingGaiaId(const GaiaId& gaia_id);
GaiaId GetCurrentSyncingGaiaId() const;
void ClearCurrentSyncingGaiaId();
static bool HasCurrentSyncingGaiaId(const PrefService* pref_service);
static void ClearCurrentSyncingGaiaId(PrefService* pref_service);
// All of the following prefs are Gaia-keyed (to the `gaia_id_hash`) passed
// to the constructor):
void SetCacheGuid(const std::string& cache_guid);
std::string GetCacheGuid() const;
void SetBirthday(const std::string& birthday);
std::string GetBirthday() const;
void SetBagOfChips(const std::string& bag_of_chips);
std::string GetBagOfChips() const;
base::Time GetLastSyncedTime() const;
void SetLastSyncedTime(base::Time time);
base::Time GetLastPollTime() const;
void SetLastPollTime(base::Time time);
base::TimeDelta GetPollInterval() const;
void SetPollInterval(base::TimeDelta interval);
private:
// Never null.
const raw_ptr<PrefService> pref_service_;
const signin::GaiaIdHash gaia_id_hash_;
SEQUENCE_CHECKER(sequence_checker_);
};
} // namespace syncer
#endif // COMPONENTS_SYNC_SERVICE_GLUE_SYNC_TRANSPORT_DATA_PREFS_H_
|