Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / zoom / chrome_zoom_level_prefs.h
blob45b911bd330424d2c85047a02dd448ea20e56a0a
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 namespace chrome {
31 // A class to manage per-partition default and per-host zoom levels in Chrome's
32 // preference system. It implements an interface between the content/ zoom
33 // levels in HostZoomMap and Chrome's preference system. All changes
34 // to the per-partition default zoom levels from chrome/ flow through this
35 // class. Any changes to per-host levels are updated when HostZoomMap calls
36 // OnZoomLevelChanged.
37 class ChromeZoomLevelPrefs : public content::ZoomLevelDelegate {
38 public:
39 typedef base::CallbackList<void(void)>::Subscription
40 DefaultZoomLevelSubscription;
42 // Initialize the pref_service and the partition_key via the constructor,
43 // as these concepts won't be available in the content base class
44 // ZoomLevelDelegate, which will define the InitHostZoomMap interface.
45 // |pref_service_| must outlive this class.
46 ChromeZoomLevelPrefs(
47 PrefService* pref_service,
48 const base::FilePath& profile_path,
49 const base::FilePath& partition_path,
50 base::WeakPtr<ui_zoom::ZoomEventManager> zoom_event_manager);
51 ~ChromeZoomLevelPrefs() override;
53 static std::string GetHashForTesting(const base::FilePath& relative_path);
55 void SetDefaultZoomLevelPref(double level);
56 double GetDefaultZoomLevelPref() const;
57 scoped_ptr<DefaultZoomLevelSubscription> RegisterDefaultZoomLevelCallback(
58 const base::Closure& callback);
60 void ExtractPerHostZoomLevels(
61 const base::DictionaryValue* host_zoom_dictionary,
62 bool sanitize_partition_host_zoom_levels);
64 // content::ZoomLevelDelegate
65 void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override;
67 private:
68 // This is a callback function that receives notifications from HostZoomMap
69 // when per-host zoom levels change. It is used to update the per-host
70 // zoom levels (if any) managed by this class (for its associated partition).
71 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
73 PrefService* pref_service_;
74 base::WeakPtr<ui_zoom::ZoomEventManager> zoom_event_manager_;
75 content::HostZoomMap* host_zoom_map_;
76 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
77 std::string partition_key_;
78 base::CallbackList<void(void)> default_zoom_changed_callbacks_;
80 DISALLOW_COPY_AND_ASSIGN(ChromeZoomLevelPrefs);
83 } // namespace chrome
85 #endif // CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_