| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/common/extensions/api/settings_private.h" | 13 #include "chrome/common/extensions/api/settings_private.h" |
| 14 | 14 |
| 15 class PrefService; | 15 class PrefService; |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 class PrefsUtil { | 20 class PrefsUtil { |
| 21 | 21 |
| 22 public: | 22 public: |
| 23 // Success or error statuses from calling SetPref. |
| 24 enum SetPrefResult { |
| 25 SUCCESS, |
| 26 PREF_NOT_MODIFIABLE, |
| 27 PREF_NOT_FOUND, |
| 28 PREF_TYPE_MISMATCH, |
| 29 PREF_TYPE_UNSUPPORTED |
| 30 }; |
| 31 |
| 23 using TypedPrefMap = std::map<std::string, api::settings_private::PrefType>; | 32 using TypedPrefMap = std::map<std::string, api::settings_private::PrefType>; |
| 24 | 33 |
| 25 explicit PrefsUtil(Profile* profile); | 34 explicit PrefsUtil(Profile* profile); |
| 26 virtual ~PrefsUtil(); | 35 virtual ~PrefsUtil(); |
| 27 | 36 |
| 28 // Gets the list of whitelisted pref keys -- that is, those which correspond | 37 // Gets the list of whitelisted pref keys -- that is, those which correspond |
| 29 // to prefs that clients of the settingsPrivate API may retrieve and | 38 // to prefs that clients of the settingsPrivate API may retrieve and |
| 30 // manipulate. | 39 // manipulate. |
| 31 const TypedPrefMap& GetWhitelistedKeys(); | 40 const TypedPrefMap& GetWhitelistedKeys(); |
| 32 | 41 |
| 33 // Gets the value of the pref with the given |name|. Returns a pointer to an | 42 // Gets the value of the pref with the given |name|. Returns a pointer to an |
| 34 // empty PrefObject if no pref is found for |name|. | 43 // empty PrefObject if no pref is found for |name|. |
| 35 virtual scoped_ptr<api::settings_private::PrefObject> GetPref( | 44 virtual scoped_ptr<api::settings_private::PrefObject> GetPref( |
| 36 const std::string& name); | 45 const std::string& name); |
| 37 | 46 |
| 38 // Sets the pref with the given name and value in the proper PrefService. | 47 // Sets the pref with the given name and value in the proper PrefService. |
| 39 virtual bool SetPref(const std::string& name, const base::Value* value); | 48 virtual SetPrefResult SetPref(const std::string& name, |
| 49 const base::Value* value); |
| 40 | 50 |
| 41 // Appends the given |value| to the list setting specified by the path in | 51 // Appends the given |value| to the list setting specified by the path in |
| 42 // |pref_name|. | 52 // |pref_name|. |
| 43 virtual bool AppendToListCrosSetting(const std::string& pref_name, | 53 virtual bool AppendToListCrosSetting(const std::string& pref_name, |
| 44 const base::Value& value); | 54 const base::Value& value); |
| 45 | 55 |
| 46 // Removes the given |value| from the list setting specified by the path in | 56 // Removes the given |value| from the list setting specified by the path in |
| 47 // |pref_name|. | 57 // |pref_name|. |
| 48 virtual bool RemoveFromListCrosSetting(const std::string& pref_name, | 58 virtual bool RemoveFromListCrosSetting(const std::string& pref_name, |
| 49 const base::Value& value); | 59 const base::Value& value); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 // Returns whether |pref_name| corresponds to a pref that is user modifiable | 72 // Returns whether |pref_name| corresponds to a pref that is user modifiable |
| 63 // (i.e., not made restricted by a user or device policy). | 73 // (i.e., not made restricted by a user or device policy). |
| 64 bool IsPrefUserModifiable(const std::string& pref_name); | 74 bool IsPrefUserModifiable(const std::string& pref_name); |
| 65 | 75 |
| 66 api::settings_private::PrefType GetType(const std::string& name, | 76 api::settings_private::PrefType GetType(const std::string& name, |
| 67 base::Value::Type type); | 77 base::Value::Type type); |
| 68 | 78 |
| 69 scoped_ptr<api::settings_private::PrefObject> GetCrosSettingsPref( | 79 scoped_ptr<api::settings_private::PrefObject> GetCrosSettingsPref( |
| 70 const std::string& name); | 80 const std::string& name); |
| 71 | 81 |
| 72 bool SetCrosSettingsPref(const std::string& name, const base::Value* value); | 82 SetPrefResult SetCrosSettingsPref(const std::string& name, |
| 83 const base::Value* value); |
| 73 | 84 |
| 74 Profile* profile_; // weak | 85 Profile* profile_; // weak |
| 75 }; | 86 }; |
| 76 | 87 |
| 77 } // namespace extensions | 88 } // namespace extensions |
| 78 | 89 |
| 79 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ | 90 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ |
| OLD | NEW |