| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ | 5 #ifndef CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ |
| 6 #define CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ | 6 #define CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "components/prefs/json_pref_store.h" | 14 #include "components/prefs/json_pref_store.h" |
| 15 #include "components/prefs/pref_change_registrar.h" | 15 #include "components/prefs/pref_change_registrar.h" |
| 16 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
| 17 #include "components/prefs/pref_store.h" | 17 #include "components/prefs/pref_store.h" |
| 18 #include "content/public/browser/host_zoom_map.h" | 18 #include "content/public/browser/host_zoom_map.h" |
| 19 #include "content/public/browser/zoom_level_delegate.h" | 19 #include "content/public/browser/zoom_level_delegate.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class DictionaryValue; | 22 class DictionaryValue; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace ui_zoom { | 25 namespace zoom { |
| 26 class ZoomEventManager; | 26 class ZoomEventManager; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // A class to manage per-partition default and per-host zoom levels in Chrome's | 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 | 30 // preference system. It implements an interface between the content/ zoom |
| 31 // levels in HostZoomMap and Chrome's preference system. All changes | 31 // levels in HostZoomMap and Chrome's preference system. All changes |
| 32 // to the per-partition default zoom levels from chrome/ flow through this | 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 | 33 // class. Any changes to per-host levels are updated when HostZoomMap calls |
| 34 // OnZoomLevelChanged. | 34 // OnZoomLevelChanged. |
| 35 class ChromeZoomLevelPrefs : public content::ZoomLevelDelegate { | 35 class ChromeZoomLevelPrefs : public content::ZoomLevelDelegate { |
| 36 public: | 36 public: |
| 37 typedef base::CallbackList<void(void)>::Subscription | 37 typedef base::CallbackList<void(void)>::Subscription |
| 38 DefaultZoomLevelSubscription; | 38 DefaultZoomLevelSubscription; |
| 39 | 39 |
| 40 // Initialize the pref_service and the partition_key via the constructor, | 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 | 41 // as these concepts won't be available in the content base class |
| 42 // ZoomLevelDelegate, which will define the InitHostZoomMap interface. | 42 // ZoomLevelDelegate, which will define the InitHostZoomMap interface. |
| 43 // |pref_service_| must outlive this class. | 43 // |pref_service_| must outlive this class. |
| 44 ChromeZoomLevelPrefs( | 44 ChromeZoomLevelPrefs( |
| 45 PrefService* pref_service, | 45 PrefService* pref_service, |
| 46 const base::FilePath& profile_path, | 46 const base::FilePath& profile_path, |
| 47 const base::FilePath& partition_path, | 47 const base::FilePath& partition_path, |
| 48 base::WeakPtr<ui_zoom::ZoomEventManager> zoom_event_manager); | 48 base::WeakPtr<zoom::ZoomEventManager> zoom_event_manager); |
| 49 ~ChromeZoomLevelPrefs() override; | 49 ~ChromeZoomLevelPrefs() override; |
| 50 | 50 |
| 51 static std::string GetHashForTesting(const base::FilePath& relative_path); | 51 static std::string GetHashForTesting(const base::FilePath& relative_path); |
| 52 | 52 |
| 53 void SetDefaultZoomLevelPref(double level); | 53 void SetDefaultZoomLevelPref(double level); |
| 54 double GetDefaultZoomLevelPref() const; | 54 double GetDefaultZoomLevelPref() const; |
| 55 std::unique_ptr<DefaultZoomLevelSubscription> | 55 std::unique_ptr<DefaultZoomLevelSubscription> |
| 56 RegisterDefaultZoomLevelCallback(const base::Closure& callback); | 56 RegisterDefaultZoomLevelCallback(const base::Closure& callback); |
| 57 | 57 |
| 58 void ExtractPerHostZoomLevels( | 58 void ExtractPerHostZoomLevels( |
| 59 const base::DictionaryValue* host_zoom_dictionary, | 59 const base::DictionaryValue* host_zoom_dictionary, |
| 60 bool sanitize_partition_host_zoom_levels); | 60 bool sanitize_partition_host_zoom_levels); |
| 61 | 61 |
| 62 // content::ZoomLevelDelegate | 62 // content::ZoomLevelDelegate |
| 63 void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override; | 63 void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override; |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 // This is a callback function that receives notifications from HostZoomMap | 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 | 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). | 68 // zoom levels (if any) managed by this class (for its associated partition). |
| 69 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); | 69 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); |
| 70 | 70 |
| 71 PrefService* pref_service_; | 71 PrefService* pref_service_; |
| 72 base::WeakPtr<ui_zoom::ZoomEventManager> zoom_event_manager_; | 72 base::WeakPtr<zoom::ZoomEventManager> zoom_event_manager_; |
| 73 content::HostZoomMap* host_zoom_map_; | 73 content::HostZoomMap* host_zoom_map_; |
| 74 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; | 74 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; |
| 75 std::string partition_key_; | 75 std::string partition_key_; |
| 76 base::CallbackList<void(void)> default_zoom_changed_callbacks_; | 76 base::CallbackList<void(void)> default_zoom_changed_callbacks_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(ChromeZoomLevelPrefs); | 78 DISALLOW_COPY_AND_ASSIGN(ChromeZoomLevelPrefs); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 #endif // CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ | 81 #endif // CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ |
| OLD | NEW |