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

Side by Side Diff: chrome/browser/wake_lock/wake_lock_preference.cc

Issue 406483004: Initial implementation of API WakeLock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 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.
4
5 #include "chrome/browser/wake_lock/wake_lock_preference.h"
6
7 #include "base/prefs/scoped_user_pref_update.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/tab_contents/tab_util.h"
10 #include "components/pref_registry/pref_registry_syncable.h"
11 #include "content/public/browser/web_contents.h"
12
13 const char kWakeLockEnabled[] = "profile.wake_lock_enabled";
14
15 // static
16 scoped_ptr<WakeLockPreference> WakeLockPreference::createWakeLockPreference(
17 int render_process_id, int routed_id) {
18 return scoped_ptr<WakeLockPreference>(new WakeLockPreference(
19 render_process_id, routed_id));
20 }
21
22 // static
23 void WakeLockPreference::RegisterProfilePrefs(
24 user_prefs::PrefRegistrySyncable* registry) {
25 registry->RegisterDictionaryPref(kWakeLockEnabled,
26 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
27 }
28
29 WakeLockPreference::WakeLockPreference(int render_process_id, int routed_id) {
30 content::WebContents* web_contents =
31 tab_util::GetWebContentsByID(render_process_id, routed_id);
32 DCHECK(web_contents);
33 Profile* profile = Profile::FromBrowserContext(
34 web_contents->GetBrowserContext());
35 DCHECK(profile);
36 pref_service_ = profile->GetPrefs();
37 DCHECK(pref_service_);
38 }
39
40 bool WakeLockPreference::isSavedAllow(const std::string& key) {
41 return (getAllowed(key) != WakeLockPreferenceNotFound);
42 }
43
44 bool WakeLockPreference::isAllowed(const std::string& key) {
45 return (getAllowed(key) == WakeLockPreferenceYes);
46 }
47
48 void WakeLockPreference::setAllowed(const std::string& key, bool allowed) {
49 DictionaryPrefUpdate update(pref_service_, kWakeLockEnabled);
50 base::DictionaryValue* inspector_settings = update.Get();
51 inspector_settings->SetWithoutPathExpansion(
52 key, base::Value::CreateBooleanValue(allowed));
53 }
54
55 WakeLockPreference::WakeLockPreferenceStatus WakeLockPreference::getAllowed(
56 const std::string& key) {
57 const base::DictionaryValue* dict =
58 pref_service_->GetDictionary(kWakeLockEnabled);
59 bool result;
60 if (dict && dict->GetBooleanWithoutPathExpansion(key, &result))
61 return result ? WakeLockPreferenceYes : WakeLockPreferenceNo;
62 return WakeLockPreferenceNotFound;
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698