1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_UPDATER_PREFS_H_ 6 #define CHROME_UPDATER_PREFS_H_ 7 8 #include <memory> 9 10 class PrefService; 11 12 namespace updater { 13 14 extern const char kPrefUpdateTime[]; 15 16 class UpdaterPrefs { 17 public: 18 UpdaterPrefs() = default; 19 UpdaterPrefs(const UpdaterPrefs&) = delete; 20 UpdaterPrefs& operator=(const UpdaterPrefs&) = delete; 21 virtual ~UpdaterPrefs() = default; 22 23 virtual PrefService* GetPrefService() const = 0; 24 }; 25 26 class LocalPrefs : public UpdaterPrefs { 27 public: 28 LocalPrefs() = default; 29 ~LocalPrefs() override = default; 30 31 virtual bool GetQualified() const = 0; 32 virtual void SetQualified(bool value) = 0; 33 }; 34 35 class GlobalPrefs : public UpdaterPrefs { 36 public: 37 GlobalPrefs() = default; 38 ~GlobalPrefs() override = default; 39 40 virtual std::string GetActiveVersion() const = 0; 41 virtual void SetActiveVersion(std::string value) = 0; 42 virtual bool GetSwapping() const = 0; 43 virtual void SetSwapping(bool value) = 0; 44 }; 45 46 // Open the global prefs. These prefs are protected by a mutex, and shared by 47 // all updaters on the system. Returns nullptr if the mutex cannot be acquired. 48 std::unique_ptr<GlobalPrefs> CreateGlobalPrefs(); 49 50 // Open the version-specific prefs. These prefs are not protected by any mutex 51 // and not shared with other versions of the updater. 52 std::unique_ptr<LocalPrefs> CreateLocalPrefs(); 53 54 // Commits prefs changes to storage. This function should only be called 55 // when the changes must be written immediately, for instance, during program 56 // shutdown. The function must be called in the scope of a task executor. 57 void PrefsCommitPendingWrites(PrefService* pref_service); 58 59 } // namespace updater 60 61 #endif // CHROME_UPDATER_PREFS_H_ 62