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 namespace prefs_util { | |
21 | |
22 using TypedPrefMap = std::map<std::string, api::settings_private::PrefType>; | 20 using TypedPrefMap = std::map<std::string, api::settings_private::PrefType>; |
stevenjb
2015/06/05 02:23:50
put this inside the class
Oren Blasberg
2015/06/05 20:12:21
Done.
| |
23 | 21 |
24 // Gets the list of whitelisted pref keys -- that is, those which correspond to | 22 class PrefsUtil { |
25 // prefs that clients of the settingsPrivate API may retrieve and manipulate. | 23 public: |
26 const TypedPrefMap& GetWhitelistedKeys(); | 24 explicit PrefsUtil(Profile* profile); |
25 virtual ~PrefsUtil() {} | |
stevenjb
2015/06/05 02:23:50
We should avoid inlining virtual methods, even tri
Oren Blasberg
2015/06/05 20:12:21
Done.
| |
27 | 26 |
28 // Gets the value of the pref with the given |name|. Returns a pointer to an | 27 // Gets the list of whitelisted pref keys -- that is, those which correspond |
29 // empty PrefObject if no pref is found for |name|. | 28 // to prefs that clients of the settingsPrivate API may retrieve and |
30 scoped_ptr<api::settings_private::PrefObject> GetPref(Profile* profile, | 29 // manipulate. |
31 const std::string& name); | 30 const TypedPrefMap& GetWhitelistedKeys(); |
32 | 31 |
33 // Returns whether |pref_name| corresponds to a pref whose type is URL. | 32 // Gets the value of the pref with the given |name|. Returns a pointer to an |
34 bool IsPrefTypeURL(const std::string& pref_name); | 33 // empty PrefObject if no pref is found for |name|. |
34 virtual scoped_ptr<api::settings_private::PrefObject> GetPref( | |
35 const std::string& name); | |
35 | 36 |
36 // Returns whether |pref_name| corresponds to a pref that is user modifiable | 37 // Sets the pref with the given name and value in the proper PrefService. |
37 // (i.e., not made restricted by a user or device policy). | 38 virtual bool SetPref(const std::string& name, const base::Value* value); |
38 bool IsPrefUserModifiable(Profile* profile, const std::string& pref_name); | |
39 | 39 |
40 // Returns a pointer to the appropriate PrefService instance for the given | 40 // Returns a pointer to the appropriate PrefService instance for the given |
41 // |pref_name|. | 41 // |pref_name|. |
42 PrefService* FindServiceForPref(Profile* profile, const std::string& pref_name); | 42 virtual PrefService* FindServiceForPref(const std::string& pref_name); |
43 | 43 |
44 } // namespace prefs_util | 44 protected: |
45 // Returns whether |pref_name| corresponds to a pref whose type is URL. | |
46 bool IsPrefTypeURL(const std::string& pref_name); | |
47 | |
48 // Returns whether |pref_name| corresponds to a pref that is user modifiable | |
49 // (i.e., not made restricted by a user or device policy). | |
50 bool IsPrefUserModifiable(const std::string& pref_name); | |
51 | |
52 api::settings_private::PrefType GetType( | |
53 const std::string& name, base::Value::Type type); | |
stevenjb
2015/06/05 02:23:50
WS between all methods
Oren Blasberg
2015/06/05 20:12:21
Done.
| |
54 scoped_ptr<api::settings_private::PrefObject> GetCrosSettingsPref( | |
55 const std::string& name); | |
56 bool SetCrosSettingsPref(const std::string& name, const base::Value* value); | |
57 | |
58 Profile* profile_; // weak | |
59 }; | |
45 | 60 |
46 } // namespace extensions | 61 } // namespace extensions |
47 | 62 |
48 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ | 63 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_ |
OLD | NEW |