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

Side by Side Diff: components/dom_distiller/core/distilled_page_prefs.cc

Issue 341563002: Theme Preferences for Distilled Pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed how accessed enum to agree with gcc 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 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 "components/dom_distiller/core/distilled_page_prefs.h"
6
7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/observer_list.h"
11 #include "base/prefs/pref_service.h"
12 #include "components/pref_registry/pref_registry_syncable.h"
13
14 namespace {
15
16 // Path to the integer corresponding to user's preference theme.
17 const char kThemePref[] = "dom_distiller.theme";
18 }
19
20 namespace dom_distiller {
21
22 DistilledPagePrefs::DistilledPagePrefs(PrefService* pref_service)
23 : pref_service_(pref_service), weak_ptr_factory_(this) {
24 }
25
26 DistilledPagePrefs::~DistilledPagePrefs() {
27 }
28
29 // static
30 void DistilledPagePrefs::RegisterProfilePrefs(
31 user_prefs::PrefRegistrySyncable* registry) {
32 registry->RegisterIntegerPref(
33 kThemePref,
34 DistilledPagePrefs::LIGHT,
35 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
36 }
37
38 void DistilledPagePrefs::SetTheme(DistilledPagePrefs::Theme new_theme) {
39 pref_service_->SetInteger(kThemePref, new_theme);
40 base::MessageLoop::current()->PostTask(
41 FROM_HERE,
42 base::Bind(&DistilledPagePrefs::NotifyOnChangeTheme,
43 weak_ptr_factory_.GetWeakPtr(),
44 new_theme));
45 }
46
47 DistilledPagePrefs::Theme DistilledPagePrefs::GetTheme() {
48 int theme = pref_service_->GetInteger(kThemePref);
49 if (theme < 0 || theme >= DistilledPagePrefs::THEME_COUNT) {
50 // Persisted data was incorrect, trying to clean it up by storing the
51 // default.
52 SetTheme(DistilledPagePrefs::LIGHT);
53 return DistilledPagePrefs::LIGHT;
54 }
55 return (Theme) theme;
56 }
57
58 void DistilledPagePrefs::AddObserver(Observer* obs) {
59 observers_.AddObserver(obs);
60 }
61
62 void DistilledPagePrefs::RemoveObserver(Observer* obs) {
63 observers_.RemoveObserver(obs);
64 }
65
66 void DistilledPagePrefs::NotifyOnChangeTheme(
67 DistilledPagePrefs::Theme new_theme) {
68 FOR_EACH_OBSERVER(Observer, observers_, OnChangeTheme(new_theme));
69 }
70
71 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698