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#ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLED_PAGE_PREFS_H_
6#define COMPONENTS_DOM_DISTILLER_CORE_DISTILLED_PAGE_PREFS_H_
7
8#include "base/macros.h"
9#include "base/memory/weak_ptr.h"
10#include "base/observer_list.h"
11
12class PrefService;
13
14namespace user_prefs {
15class PrefRegistrySyncable;
16}
17
18namespace dom_distiller {
19
20// Interface for preferences used for distilled page.
21class DistilledPagePrefs {
22 public:
23  // Possible font families for distilled page.
24  enum FontFamily {
25#define DEFINE_FONT_FAMILY(name, value) name = value,
26#include "components/dom_distiller/core/font_family_list.h"
27#undef DEFINE_FONT_FAMILY
28  };
29
30  // Possible themes for distilled page.
31  enum Theme {
32#define DEFINE_THEME(name, value) name = value,
33#include "components/dom_distiller/core/theme_list.h"
34#undef DEFINE_THEME
35  };
36
37  class Observer {
38   public:
39    virtual void OnChangeFontFamily(FontFamily font) = 0;
40    virtual void OnChangeTheme(Theme theme) = 0;
41  };
42
43  explicit DistilledPagePrefs(PrefService* pref_service);
44  ~DistilledPagePrefs();
45
46  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
47
48  // Sets the user's preference for the font family of distilled pages.
49  void SetFontFamily(FontFamily new_font);
50  // Returns the user's preference for the font family of distilled pages.
51  FontFamily GetFontFamily();
52
53  // Sets the user's preference for the theme of distilled pages.
54  void SetTheme(Theme new_theme);
55  // Returns the user's preference for the theme of distilled pages.
56  Theme GetTheme();
57
58  void AddObserver(Observer* obs);
59  void RemoveObserver(Observer* obs);
60
61 private:
62  // Notifies all Observers of new font family.
63  void NotifyOnChangeFontFamily(FontFamily font_family);
64  // Notifies all Observers of new theme.
65  void NotifyOnChangeTheme(Theme theme);
66
67  PrefService* pref_service_;
68  ObserverList<Observer> observers_;
69
70  base::WeakPtrFactory<DistilledPagePrefs> weak_ptr_factory_;
71
72  DISALLOW_COPY_AND_ASSIGN(DistilledPagePrefs);
73};
74
75}  // namespace dom_distiller
76
77#endif  // COMPONENTS_DOM_DISTILLER_CORE_DISTILLED_PAGE_PREFS_H_
78