Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 // True if user prefers high-contrast (dark) appearance for distilled page. | |
|
nyquist
2014/07/07 19:12:48
This comment needs to be updated.
smaslo
2014/07/08 19:58:10
Done.
| |
| 17 const char kThemePref[] = "dom_distiller.theme"; | |
| 18 | |
| 19 } | |
| 20 | |
| 21 namespace dom_distiller { | |
| 22 | |
| 23 DistilledPagePrefs::DistilledPagePrefs(PrefService* pref_service) | |
| 24 : pref_service_(pref_service), | |
| 25 weak_ptr_factory_(this) { | |
| 26 } | |
| 27 | |
| 28 DistilledPagePrefs::~DistilledPagePrefs() { | |
| 29 } | |
| 30 | |
| 31 void DistilledPagePrefs::AddObserver(Observer* obs) { | |
| 32 observers_.AddObserver(obs); | |
| 33 } | |
| 34 | |
| 35 void DistilledPagePrefs::RemoveObserver(Observer* obs) { | |
| 36 observers_.RemoveObserver(obs); | |
| 37 } | |
| 38 | |
| 39 // static | |
| 40 void DistilledPagePrefs::RegisterProfilePrefs( | |
| 41 user_prefs::PrefRegistrySyncable* registry) { | |
| 42 registry->RegisterIntegerPref(kThemePref, | |
| 43 Theme::kLight, | |
| 44 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | |
| 45 } | |
| 46 | |
| 47 void DistilledPagePrefs::SetTheme(Theme new_theme) { | |
| 48 pref_service_->SetInteger(kThemePref, new_theme); | |
| 49 base::MessageLoop::current()->PostTask(FROM_HERE, | |
| 50 base::Bind(&DistilledPagePrefs::NotifyOnChangeTheme, | |
| 51 weak_ptr_factory_.GetWeakPtr(), new_theme)); | |
| 52 } | |
| 53 | |
| 54 void DistilledPagePrefs::NotifyOnChangeTheme(Theme new_theme) { | |
| 55 FOR_EACH_OBSERVER(Observer, observers_, OnChangeTheme(new_theme)); | |
| 56 } | |
| 57 | |
| 58 const DistilledPagePrefs::Theme DistilledPagePrefs::GetTheme() const { | |
| 59 return (Theme) pref_service_->GetInteger(kThemePref); | |
|
nyquist
2014/07/07 19:12:48
This is an unsafe cast, since the values on disk c
smaslo
2014/07/08 19:58:10
Done. I also added a check to SetTheme() to preve
| |
| 60 } | |
| 61 | |
| 62 } // namespace dom_distiller | |
| 63 | |
| OLD | NEW |