OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/sequenced_task_runner_helpers.h" | 13 #include "base/sequenced_task_runner_helpers.h" |
14 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "content/public/browser/host_zoom_map.h" | 16 #include "content/public/browser/host_zoom_map.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 | 19 |
| 20 namespace content { |
| 21 |
20 // HostZoomMap needs to be deleted on the UI thread because it listens | 22 // HostZoomMap needs to be deleted on the UI thread because it listens |
21 // to notifications on there (and holds a NotificationRegistrar). | 23 // to notifications on there (and holds a NotificationRegistrar). |
22 class CONTENT_EXPORT HostZoomMapImpl | 24 class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap), |
23 : public NON_EXPORTED_BASE(content::HostZoomMap), | 25 public NotificationObserver, |
24 public content::NotificationObserver, | 26 public base::SupportsUserData::Data { |
25 public base::SupportsUserData::Data { | |
26 public: | 27 public: |
27 HostZoomMapImpl(); | 28 HostZoomMapImpl(); |
28 virtual ~HostZoomMapImpl(); | 29 virtual ~HostZoomMapImpl(); |
29 | 30 |
30 // HostZoomMap implementation: | 31 // HostZoomMap implementation: |
31 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; | 32 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; |
32 virtual double GetZoomLevel(const std::string& host) const OVERRIDE; | 33 virtual double GetZoomLevel(const std::string& host) const OVERRIDE; |
33 virtual void SetZoomLevel(const std::string& host, double level) OVERRIDE; | 34 virtual void SetZoomLevel(const std::string& host, double level) OVERRIDE; |
34 virtual double GetDefaultZoomLevel() const OVERRIDE; | 35 virtual double GetDefaultZoomLevel() const OVERRIDE; |
35 virtual void SetDefaultZoomLevel(double level) OVERRIDE; | 36 virtual void SetDefaultZoomLevel(double level) OVERRIDE; |
36 | 37 |
37 // Returns the temporary zoom level that's only valid for the lifetime of | 38 // Returns the temporary zoom level that's only valid for the lifetime of |
38 // the given WebContents (i.e. isn't saved and doesn't affect other | 39 // the given WebContents (i.e. isn't saved and doesn't affect other |
39 // WebContentses) if it exists, the default zoom level otherwise. | 40 // WebContentses) if it exists, the default zoom level otherwise. |
40 // | 41 // |
41 // This may be called on any thread. | 42 // This may be called on any thread. |
42 double GetTemporaryZoomLevel(int render_process_id, | 43 double GetTemporaryZoomLevel(int render_process_id, |
43 int render_view_id) const; | 44 int render_view_id) const; |
44 | 45 |
45 // Sets the temporary zoom level that's only valid for the lifetime of this | 46 // Sets the temporary zoom level that's only valid for the lifetime of this |
46 // WebContents. | 47 // WebContents. |
47 // | 48 // |
48 // This should only be called on the UI thread. | 49 // This should only be called on the UI thread. |
49 void SetTemporaryZoomLevel(int render_process_id, | 50 void SetTemporaryZoomLevel(int render_process_id, |
50 int render_view_id, | 51 int render_view_id, |
51 double level); | 52 double level); |
52 | 53 |
53 // content::NotificationObserver implementation. | 54 // NotificationObserver implementation. |
54 virtual void Observe(int type, | 55 virtual void Observe(int type, |
55 const content::NotificationSource& source, | 56 const NotificationSource& source, |
56 const content::NotificationDetails& details) OVERRIDE; | 57 const NotificationDetails& details) OVERRIDE; |
57 | 58 |
58 private: | 59 private: |
59 typedef std::map<std::string, double> HostZoomLevels; | 60 typedef std::map<std::string, double> HostZoomLevels; |
60 | 61 |
61 // Copy of the pref data, so that we can read it on the IO thread. | 62 // Copy of the pref data, so that we can read it on the IO thread. |
62 HostZoomLevels host_zoom_levels_; | 63 HostZoomLevels host_zoom_levels_; |
63 double default_zoom_level_; | 64 double default_zoom_level_; |
64 | 65 |
65 struct TemporaryZoomLevel { | 66 struct TemporaryZoomLevel { |
66 int render_process_id; | 67 int render_process_id; |
67 int render_view_id; | 68 int render_view_id; |
68 double zoom_level; | 69 double zoom_level; |
69 }; | 70 }; |
70 | 71 |
71 // Don't expect more than a couple of tabs that are using a temporary zoom | 72 // Don't expect more than a couple of tabs that are using a temporary zoom |
72 // level, so vector is fine for now. | 73 // level, so vector is fine for now. |
73 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; | 74 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; |
74 | 75 |
75 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and | 76 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and |
76 // |temporary_zoom_levels_| to guarantee thread safety. | 77 // |temporary_zoom_levels_| to guarantee thread safety. |
77 mutable base::Lock lock_; | 78 mutable base::Lock lock_; |
78 | 79 |
79 content::NotificationRegistrar registrar_; | 80 NotificationRegistrar registrar_; |
80 | 81 |
81 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); | 82 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); |
82 }; | 83 }; |
83 | 84 |
| 85 } // namespace content |
| 86 |
84 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 87 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
OLD | NEW |