// Copyright 2015 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 CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ #include #include #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "chrome/common/extensions/api/settings_private.h" class PrefService; class Profile; namespace extensions { class PrefsUtil { public: using TypedPrefMap = std::map; explicit PrefsUtil(Profile* profile); virtual ~PrefsUtil(); // Gets the list of whitelisted pref keys -- that is, those which correspond // to prefs that clients of the settingsPrivate API may retrieve and // manipulate. const TypedPrefMap& GetWhitelistedKeys(); // Gets the value of the pref with the given |name|. Returns a pointer to an // empty PrefObject if no pref is found for |name|. virtual scoped_ptr GetPref( const std::string& name); // Sets the pref with the given name and value in the proper PrefService. virtual bool SetPref(const std::string& name, const base::Value* value); // Appends the given |value| to the list setting specified by the path in // |pref_name|. virtual bool AppendToListCrosSetting(const std::string& pref_name, const base::Value& value); // Removes the given |value| from the list setting specified by the path in // |pref_name|. virtual bool RemoveFromListCrosSetting(const std::string& pref_name, const base::Value& value); // Returns a pointer to the appropriate PrefService instance for the given // |pref_name|. virtual PrefService* FindServiceForPref(const std::string& pref_name); // Returns whether or not the given pref is a CrOS-specific setting. virtual bool IsCrosSetting(const std::string& pref_name); protected: // Returns whether |pref_name| corresponds to a pref whose type is URL. bool IsPrefTypeURL(const std::string& pref_name); // Returns whether |pref_name| corresponds to a pref that is user modifiable // (i.e., not made restricted by a user or device policy). bool IsPrefUserModifiable(const std::string& pref_name); api::settings_private::PrefType GetType(const std::string& name, base::Value::Type type); scoped_ptr GetCrosSettingsPref( const std::string& name); bool SetCrosSettingsPref(const std::string& name, const base::Value* value); Profile* profile_; // weak }; } // namespace extensions #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_