Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: chrome/browser/extensions/api/preference/chrome_direct_setting.cc

Issue 18341016: Add types.private.ChromeDirectSetting and Connect it to preferencesPrivate.googleGeolocationAccessE… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR Feedback Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/preference/chrome_direct_setting.cc
diff --git a/chrome/browser/extensions/api/preference/chrome_direct_setting.cc b/chrome/browser/extensions/api/preference/chrome_direct_setting.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cdb7ac9ffb1d56eda993a7adfeee49f3925a2d9b
--- /dev/null
+++ b/chrome/browser/extensions/api/preference/chrome_direct_setting.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/preference/chrome_direct_setting.h"
+
+#include "base/prefs/pref_service.h"
+#include "base/values.h"
+#include "chrome/browser/extensions/api/preference/preference_api_constants.h"
+#include "chrome/browser/profiles/profile.h"
+
+namespace extensions {
+namespace chromedirectsetting {
+
+bool DirectSettingFunctionBase::IsCalledFromComponentExtension() {
+ return GetExtension()->location() == Manifest::COMPONENT;
+}
+
+PrefService* DirectSettingFunctionBase::GetPrefService() {
+ return profile()->GetPrefs();
+}
+
+bool GetDirectSettingFunction::RunImpl() {
+ EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension());
+
+ std::string pref_key;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
+
+ const PrefService::Preference* preference =
+ GetPrefService()->FindPreference(pref_key.c_str());
+ const base::Value* value = preference->GetValue();
+ EXTENSION_FUNCTION_VALIDATE(preference);
Bernhard Bauer 2013/07/09 18:45:41 Move this one line up please? Otherwise you'll cra
robliao 2013/07/09 18:53:38 Oops! Fixed. On 2013/07/09 18:45:41, Bernhard Baue
+
+ scoped_ptr<DictionaryValue> result(new DictionaryValue);
+ result->Set(preference_api_constants::kValue, value->DeepCopy());
+ SetResult(result.release());
+
+ return true;
+}
+
+bool SetDirectSettingFunction::RunImpl() {
+ EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension());
+
+ std::string pref_key;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
+
+ DictionaryValue* details = NULL;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details));
+
+ Value* value = NULL;
+ EXTENSION_FUNCTION_VALIDATE(
+ details->Get(preference_api_constants::kValue, &value));
+
+ PrefService* pref_service = GetPrefService();
+ const PrefService::Preference* preference =
+ pref_service->FindPreference(pref_key.c_str());
+ EXTENSION_FUNCTION_VALIDATE(preference);
+
+ EXTENSION_FUNCTION_VALIDATE(value->GetType() == preference->GetType());
+
+ pref_service->Set(pref_key.c_str(), *value);
+
+ return true;
+}
+
+bool ClearDirectSettingFunction::RunImpl() {
+ EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension());
+
+ std::string pref_key;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
+ GetPrefService()->ClearPref(pref_key.c_str());
+
+ return true;
+}
+
+} // namespace chromedirectsetting
+} // namespace extensions
+

Powered by Google App Engine
This is Rietveld 408576698