Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / settings_private / prefs_util.h
blobfae5ba56e39a8a04daf9858f30fc0b6340d575eb
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_
8 #include <map>
9 #include <string>
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/common/extensions/api/settings_private.h"
15 class PrefService;
16 class Profile;
18 namespace extensions {
20 class PrefsUtil {
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
32 using TypedPrefMap = std::map<std::string, api::settings_private::PrefType>;
34 explicit PrefsUtil(Profile* profile);
35 virtual ~PrefsUtil();
37 // Gets the list of whitelisted pref keys -- that is, those which correspond
38 // to prefs that clients of the settingsPrivate API may retrieve and
39 // manipulate.
40 const TypedPrefMap& GetWhitelistedKeys();
42 // Gets the value of the pref with the given |name|. Returns a pointer to an
43 // empty PrefObject if no pref is found for |name|.
44 virtual scoped_ptr<api::settings_private::PrefObject> GetPref(
45 const std::string& name);
47 // Sets the pref with the given name and value in the proper PrefService.
48 virtual SetPrefResult SetPref(const std::string& name,
49 const base::Value* value);
51 // Appends the given |value| to the list setting specified by the path in
52 // |pref_name|.
53 virtual bool AppendToListCrosSetting(const std::string& pref_name,
54 const base::Value& value);
56 // Removes the given |value| from the list setting specified by the path in
57 // |pref_name|.
58 virtual bool RemoveFromListCrosSetting(const std::string& pref_name,
59 const base::Value& value);
61 // Returns a pointer to the appropriate PrefService instance for the given
62 // |pref_name|.
63 virtual PrefService* FindServiceForPref(const std::string& pref_name);
65 // Returns whether or not the given pref is a CrOS-specific setting.
66 virtual bool IsCrosSetting(const std::string& pref_name);
68 protected:
69 // Returns whether |pref_name| corresponds to a pref whose type is URL.
70 bool IsPrefTypeURL(const std::string& pref_name);
72 #if defined(OS_CHROMEOS)
73 // Returns whether |pref_name| corresponds to a pref that is enterprise
74 // managed.
75 bool IsPrefEnterpriseManaged(const std::string& pref_name);
77 // Returns whether |pref_name| corresponds to a pref that is controlled by
78 // the owner, and |profile_| is not the owner profile.
79 bool IsPrefOwnerControlled(const std::string& pref_name);
81 // Returns whether |pref_name| corresponds to a pref that is controlled by
82 // the primary user, and |profile_| is not the primary profile.
83 bool IsPrefPrimaryUserControlled(const std::string& pref_name);
84 #endif
86 // Returns whether |pref_name| corresponds to a pref that is controlled by
87 // a supervisor, and |profile_| is supervised.
88 bool IsPrefSupervisorControlled(const std::string& pref_name);
90 // Returns whether |pref_name| corresponds to a pref that is user modifiable
91 // (i.e., not made restricted by a user or device policy).
92 bool IsPrefUserModifiable(const std::string& pref_name);
94 api::settings_private::PrefType GetType(const std::string& name,
95 base::Value::Type type);
97 scoped_ptr<api::settings_private::PrefObject> GetCrosSettingsPref(
98 const std::string& name);
100 SetPrefResult SetCrosSettingsPref(const std::string& name,
101 const base::Value* value);
103 Profile* profile_; // weak
106 } // namespace extensions
108 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_PREFS_UTIL_H_