chromium/chrome/updater/prefs.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_UPDATER_PREFS_H_
#define CHROME_UPDATER_PREFS_H_

#include <string>

#include "base/functional/function_ref.h"
#include "base/memory/ref_counted.h"
#include "chrome/updater/util/util.h"

class PrefService;

namespace updater {

enum class UpdaterScope;

extern const char kPrefUpdateTime[];

class UpdaterPrefs : public base::RefCountedThreadSafe<UpdaterPrefs> {};

class LocalPrefs : virtual public UpdaterPrefs {};

class GlobalPrefs : virtual public UpdaterPrefs {};

// Open the global prefs. These prefs are protected by a mutex, and shared by
// all updaters on the system. Returns nullptr if the mutex cannot be acquired.
scoped_refptr<GlobalPrefs> CreateGlobalPrefs(UpdaterScope scope);

// Similar to `CreateGlobalPrefs`, but bypasses the `WrongUser` check for tests.
scoped_refptr<GlobalPrefs> CreateGlobalPrefsForTesting(UpdaterScope scope);

// Open the version-specific prefs. These prefs are not protected by any mutex
// and not shared with other versions of the updater.
scoped_refptr<LocalPrefs> CreateLocalPrefs(UpdaterScope scope);

// Commits prefs changes to storage. This function should only be called
// when the changes must be written immediately, for instance, during program
// shutdown. The function must be called in the scope of a task executor.
void PrefsCommitPendingWrites(PrefService* pref_service);

}  // namespace updater

#endif  // CHROME_UPDATER_PREFS_H_