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

Unified 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: Minor changes to tests 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 side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/core/distilled_page_prefs.cc
diff --git a/components/dom_distiller/core/distilled_page_prefs.cc b/components/dom_distiller/core/distilled_page_prefs.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2c32cae882508627fc6e91c4df7e0f616b09885d
--- /dev/null
+++ b/components/dom_distiller/core/distilled_page_prefs.cc
@@ -0,0 +1,69 @@
+// Copyright 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 "components/dom_distiller/core/distilled_page_prefs.h"
+
+#include "base/bind.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "base/observer_list.h"
+#include "base/prefs/pref_service.h"
+#include "components/pref_registry/pref_registry_syncable.h"
+
+namespace {
+
+// Path to the integer corresponding to user's preference theme.
+const char kThemePref[] = "dom_distiller.theme";
+
+}
+
+namespace dom_distiller {
+
+DistilledPagePrefs::DistilledPagePrefs(PrefService* pref_service)
+ : pref_service_(pref_service),
+ weak_ptr_factory_(this) {
+}
+
+DistilledPagePrefs::~DistilledPagePrefs() {
+}
+
+// static
+void DistilledPagePrefs::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterIntegerPref(kThemePref,
+ Theme::kLight,
+ user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
+}
+
+void DistilledPagePrefs::SetTheme(Theme new_theme) {
+ if (new_theme >= Theme::kThemeCount) {
nyquist 2014/07/08 22:26:47 When a parameter is already an enum you don't have
smaslo 2014/07/09 19:42:25 Done.
+ new_theme = Theme::kLight;
+ }
+ pref_service_->SetInteger(kThemePref, new_theme);
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(&DistilledPagePrefs::NotifyOnChangeTheme,
+ weak_ptr_factory_.GetWeakPtr(), new_theme));
+}
+
+const DistilledPagePrefs::Theme DistilledPagePrefs::GetTheme() {
+ if (pref_service_->GetInteger(kThemePref) >= Theme::kThemeCount) {
nyquist 2014/07/08 22:26:48 You also need to check for negative values. How ab
smaslo 2014/07/09 19:42:25 Done.
+ SetTheme(Theme::kLight);
nyquist 2014/07/08 22:26:48 I think you could: 1) read to local variable 2) bo
smaslo 2014/07/09 19:42:25 Done.
+ }
+ return (Theme) pref_service_->GetInteger(kThemePref);
nyquist 2014/07/08 22:26:48 I don't think you want to read from disk again her
smaslo 2014/07/09 19:42:25 Done.
+}
+
+void DistilledPagePrefs::AddObserver(Observer* obs) {
+ observers_.AddObserver(obs);
+}
+
+void DistilledPagePrefs::RemoveObserver(Observer* obs) {
+ observers_.RemoveObserver(obs);
+}
+
+void DistilledPagePrefs::NotifyOnChangeTheme(Theme new_theme) {
+ FOR_EACH_OBSERVER(Observer, observers_, OnChangeTheme(new_theme));
+}
+
+} // namespace dom_distiller
+

Powered by Google App Engine
This is Rietveld 408576698