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_
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/common/extensions/api/settings_private.h"
18 namespace extensions
{
23 // Success or error statuses from calling SetPref.
32 using TypedPrefMap
= std::map
<std::string
, api::settings_private::PrefType
>;
34 explicit PrefsUtil(Profile
* profile
);
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
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
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
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
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
);
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
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
);
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_