Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / zoom / chrome_zoom_level_prefs.h
blob63a0c409924d973c1d3c4f5d87ff4dc9080a15d3
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.
5 #ifndef CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_
6 #define CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_
8 #include "base/callback.h"
9 #include "base/files/file_path.h"
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/prefs/json_pref_store.h"
15 #include "base/prefs/pref_change_registrar.h"
16 #include "base/prefs/pref_service.h"
17 #include "base/prefs/pref_store.h"
18 #include "content/public/browser/host_zoom_map.h"
19 #include "content/public/browser/zoom_level_delegate.h"
21 namespace base {
22 class DictionaryValue;
25 namespace ui_zoom {
26 class ZoomEventManager;
29 // A class to manage per-partition default and per-host zoom levels in Chrome's
30 // preference system. It implements an interface between the content/ zoom
31 // levels in HostZoomMap and Chrome's preference system. All changes
32 // to the per-partition default zoom levels from chrome/ flow through this
33 // class. Any changes to per-host levels are updated when HostZoomMap calls
34 // OnZoomLevelChanged.
35 class ChromeZoomLevelPrefs : public content::ZoomLevelDelegate {
36 public:
37 typedef base::CallbackList<void(void)>::Subscription
38 DefaultZoomLevelSubscription;
40 // Initialize the pref_service and the partition_key via the constructor,
41 // as these concepts won't be available in the content base class
42 // ZoomLevelDelegate, which will define the InitHostZoomMap interface.
43 // |pref_service_| must outlive this class.
44 ChromeZoomLevelPrefs(
45 PrefService* pref_service,
46 const base::FilePath& profile_path,
47 const base::FilePath& partition_path,
48 base::WeakPtr<ui_zoom::ZoomEventManager> zoom_event_manager);
49 ~ChromeZoomLevelPrefs() override;
51 static std::string GetHashForTesting(const base::FilePath& relative_path);
53 void SetDefaultZoomLevelPref(double level);
54 double GetDefaultZoomLevelPref() const;
55 scoped_ptr<DefaultZoomLevelSubscription> RegisterDefaultZoomLevelCallback(
56 const base::Closure& callback);
58 void ExtractPerHostZoomLevels(
59 const base::DictionaryValue* host_zoom_dictionary,
60 bool sanitize_partition_host_zoom_levels);
62 // content::ZoomLevelDelegate
63 void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override;
65 private:
66 // This is a callback function that receives notifications from HostZoomMap
67 // when per-host zoom levels change. It is used to update the per-host
68 // zoom levels (if any) managed by this class (for its associated partition).
69 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
71 PrefService* pref_service_;
72 base::WeakPtr<ui_zoom::ZoomEventManager> zoom_event_manager_;
73 content::HostZoomMap* host_zoom_map_;
74 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
75 std::string partition_key_;
76 base::CallbackList<void(void)> default_zoom_changed_callbacks_;
78 DISALLOW_COPY_AND_ASSIGN(ChromeZoomLevelPrefs);
81 #endif // CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_