Index: chrome/browser/wake_lock/wake_lock_preference.cc |
diff --git a/chrome/browser/wake_lock/wake_lock_preference.cc b/chrome/browser/wake_lock/wake_lock_preference.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f7bd4d0239956b1f5bcf3cf59af899330de77511 |
--- /dev/null |
+++ b/chrome/browser/wake_lock/wake_lock_preference.cc |
@@ -0,0 +1,63 @@ |
+// Copyright (c) 2014 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/wake_lock/wake_lock_preference.h" |
+ |
+#include "base/prefs/scoped_user_pref_update.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/tab_contents/tab_util.h" |
+#include "components/pref_registry/pref_registry_syncable.h" |
+#include "content/public/browser/web_contents.h" |
+ |
+const char kWakeLockEnabled[] = "profile.wake_lock_enabled"; |
+ |
+// static |
+scoped_ptr<WakeLockPreference> WakeLockPreference::createWakeLockPreference( |
+ int render_process_id, int routed_id) { |
+ return scoped_ptr<WakeLockPreference>(new WakeLockPreference( |
+ render_process_id, routed_id)); |
+} |
+ |
+// static |
+void WakeLockPreference::RegisterProfilePrefs( |
+ user_prefs::PrefRegistrySyncable* registry) { |
+ registry->RegisterDictionaryPref(kWakeLockEnabled, |
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
+} |
+ |
+WakeLockPreference::WakeLockPreference(int render_process_id, int routed_id) { |
+ content::WebContents* web_contents = |
+ tab_util::GetWebContentsByID(render_process_id, routed_id); |
+ DCHECK(web_contents); |
+ Profile* profile = Profile::FromBrowserContext( |
+ web_contents->GetBrowserContext()); |
+ DCHECK(profile); |
+ pref_service_ = profile->GetPrefs(); |
+ DCHECK(pref_service_); |
+} |
+ |
+bool WakeLockPreference::isSavedAllow(const std::string& key) { |
+ return (getAllowed(key) != WakeLockPreferenceNotFound); |
+} |
+ |
+bool WakeLockPreference::isAllowed(const std::string& key) { |
+ return (getAllowed(key) == WakeLockPreferenceYes); |
+} |
+ |
+void WakeLockPreference::setAllowed(const std::string& key, bool allowed) { |
+ DictionaryPrefUpdate update(pref_service_, kWakeLockEnabled); |
+ base::DictionaryValue* inspector_settings = update.Get(); |
+ inspector_settings->SetWithoutPathExpansion( |
+ key, base::Value::CreateBooleanValue(allowed)); |
+} |
+ |
+WakeLockPreference::WakeLockPreferenceStatus WakeLockPreference::getAllowed( |
+ const std::string& key) { |
+ const base::DictionaryValue* dict = |
+ pref_service_->GetDictionary(kWakeLockEnabled); |
+ bool result; |
+ if (dict && dict->GetBooleanWithoutPathExpansion(key, &result)) |
+ return result ? WakeLockPreferenceYes : WakeLockPreferenceNo; |
+ return WakeLockPreferenceNotFound; |
+} |