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 #include "chrome/browser/extensions/api/settings_private/settings_private_delegate.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/values.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/settings/cros_settings.h"
11 #include "chrome/browser/extensions/api/settings_private/prefs_util.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/pref_names.h"
14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/common/extension.h"
18 namespace extensions
{
20 namespace settings_private
= api::settings_private
;
22 SettingsPrivateDelegate::SettingsPrivateDelegate(Profile
* profile
)
24 prefs_util_
.reset(new PrefsUtil(profile
));
27 SettingsPrivateDelegate::~SettingsPrivateDelegate() {
30 scoped_ptr
<base::Value
> SettingsPrivateDelegate::GetPref(
31 const std::string
& name
) {
32 scoped_ptr
<api::settings_private::PrefObject
> pref
=
33 prefs_util_
->GetPref(name
);
35 return base::Value::CreateNullValue();
36 return pref
->ToValue();
39 scoped_ptr
<base::Value
> SettingsPrivateDelegate::GetAllPrefs() {
40 scoped_ptr
<base::ListValue
> prefs(new base::ListValue());
42 const TypedPrefMap
& keys
= prefs_util_
->GetWhitelistedKeys();
43 for (const auto& it
: keys
) {
44 scoped_ptr
<base::Value
> pref
= GetPref(it
.first
);
45 if (!pref
->IsType(base::Value::TYPE_NULL
))
46 prefs
->Append(pref
.release());
52 PrefsUtil::SetPrefResult
SettingsPrivateDelegate::SetPref(
53 const std::string
& pref_name
, const base::Value
* value
) {
54 return prefs_util_
->SetPref(pref_name
, value
);
57 } // namespace extensions