blob: 32779ed31316df26728e6b313c5ea87c04b7b3b2 [file] [log] [blame]
// Copyright 2019 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.
#include "chromeos/services/device_sync/cryptauth_key_registry.h"
#include "base/macros.h"
class PrefRegistrySimple;
class PrefService;
namespace chromeos {
namespace device_sync {
// Implementation of CryptAuthKeyRegistry that persists the key-bundle map as a
// preference. The in-memory key bundle map is populated with these persisted
// enrolled key bundles on construction, and the preference is updated whenever
// the in-memory key bundle map changes.
class CryptAuthKeyRegistryImpl : public CryptAuthKeyRegistry {
class Factory {
static Factory* Get();
static void SetFactoryForTesting(Factory* test_factory);
virtual std::unique_ptr<CryptAuthKeyRegistry> BuildInstance(
PrefService* pref_service);
static Factory* test_factory_;
// Registers the prefs used by this class to the given |registry|.
static void RegisterPrefs(PrefRegistrySimple* registry);
~CryptAuthKeyRegistryImpl() override;
// Populates the in-memory key bundle map with the enrolled key bundles
// persisted in a pref.
CryptAuthKeyRegistryImpl(PrefService* pref_service);
// CryptAuthKeyRegistry:
void OnKeyRegistryUpdated() override;
// Converts the registry to a dictionary value in a form suitable for a pref.
base::Value AsDictionary() const;
// Contains preferences that outlive the lifetime of this object and across
// process restarts. Not owned and must outlive this instance.
PrefService* pref_service_;
} // namespace device_sync
} // namespace chromeos