OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Maps hostnames to custom zoom levels. Written on the UI thread and read on | 5 // Maps hostnames to custom zoom levels. Written on the UI thread and read on |
6 // any thread. One instance per profile. | 6 // any thread. One instance per profile. |
7 | 7 |
8 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_H_ | 8 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_H_ |
9 #define CONTENT_BROWSER_HOST_ZOOM_MAP_H_ | 9 #define CONTENT_BROWSER_HOST_ZOOM_MAP_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
20 #include "content/common/notification_observer.h" | 20 #include "content/common/notification_observer.h" |
21 #include "content/common/notification_registrar.h" | 21 #include "content/common/notification_registrar.h" |
22 | 22 |
23 class GURL; | 23 class GURL; |
24 class Profile; | |
25 | 24 |
26 // HostZoomMap needs to be deleted on the UI thread because it listens | 25 // HostZoomMap needs to be deleted on the UI thread because it listens |
27 // to notifications on there (and holds a NotificationRegistrar). | 26 // to notifications on there (and holds a NotificationRegistrar). |
28 class HostZoomMap : | 27 class HostZoomMap : |
29 public NotificationObserver, | 28 public NotificationObserver, |
30 public base::RefCountedThreadSafe<HostZoomMap, | 29 public base::RefCountedThreadSafe<HostZoomMap, |
31 BrowserThread::DeleteOnUIThread> { | 30 BrowserThread::DeleteOnUIThread> { |
32 public: | 31 public: |
33 explicit HostZoomMap(Profile* profile); | 32 HostZoomMap(); |
34 | 33 |
35 // Returns the zoom level for a given url. The zoom level is determined by | 34 // Returns the zoom level for a given url. The zoom level is determined by |
36 // the host portion of the URL, or (in the absence of a host) the complete | 35 // the host portion of the URL, or (in the absence of a host) the complete |
37 // spec of the URL. In most cases, there is no custom zoom level, and this | 36 // spec of the URL. In most cases, there is no custom zoom level, and this |
38 // returns the user's default zoom level. Otherwise, returns the saved zoom | 37 // returns the user's default zoom level. Otherwise, returns the saved zoom |
39 // level, which may be positive (to zoom in) or negative (to zoom out). | 38 // level, which may be positive (to zoom in) or negative (to zoom out). |
40 // | 39 // |
41 // This may be called on any thread. | 40 // This may be called on any thread. |
42 double GetZoomLevel(const GURL& url) const; | 41 double GetZoomLevel(const GURL& url) const; |
43 | 42 |
(...skipping 18 matching lines...) Expand all Loading... |
62 // This should only be called on the UI thread. | 61 // This should only be called on the UI thread. |
63 void SetTemporaryZoomLevel(int render_process_id, | 62 void SetTemporaryZoomLevel(int render_process_id, |
64 int render_view_id, | 63 int render_view_id, |
65 double level); | 64 double level); |
66 | 65 |
67 // NotificationObserver implementation. | 66 // NotificationObserver implementation. |
68 virtual void Observe(NotificationType type, | 67 virtual void Observe(NotificationType type, |
69 const NotificationSource& source, | 68 const NotificationSource& source, |
70 const NotificationDetails& details); | 69 const NotificationDetails& details); |
71 | 70 |
| 71 double default_zoom_level() const { return default_zoom_level_; } |
72 void set_default_zoom_level(double level) { default_zoom_level_ = level; } | 72 void set_default_zoom_level(double level) { default_zoom_level_ = level; } |
73 | 73 |
74 private: | 74 private: |
75 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 75 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
76 friend class DeleteTask<HostZoomMap>; | 76 friend class DeleteTask<HostZoomMap>; |
77 | 77 |
78 typedef std::map<std::string, double> HostZoomLevels; | 78 typedef std::map<std::string, double> HostZoomLevels; |
79 | 79 |
80 ~HostZoomMap(); | 80 ~HostZoomMap(); |
81 | 81 |
82 // The profile we're associated with. | |
83 Profile* profile_; | |
84 | |
85 // Copy of the pref data, so that we can read it on the IO thread. | 82 // Copy of the pref data, so that we can read it on the IO thread. |
86 HostZoomLevels host_zoom_levels_; | 83 HostZoomLevels host_zoom_levels_; |
87 double default_zoom_level_; | 84 double default_zoom_level_; |
88 | 85 |
89 struct TemporaryZoomLevel { | 86 struct TemporaryZoomLevel { |
90 int render_process_id; | 87 int render_process_id; |
91 int render_view_id; | 88 int render_view_id; |
92 double zoom_level; | 89 double zoom_level; |
93 }; | 90 }; |
94 | 91 |
95 // Don't expect more than a couple of tabs that are using a temporary zoom | 92 // Don't expect more than a couple of tabs that are using a temporary zoom |
96 // level, so vector is fine for now. | 93 // level, so vector is fine for now. |
97 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; | 94 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; |
98 | 95 |
99 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and | 96 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and |
100 // |temporary_zoom_levels_| to guarantee thread safety. | 97 // |temporary_zoom_levels_| to guarantee thread safety. |
101 mutable base::Lock lock_; | 98 mutable base::Lock lock_; |
102 | 99 |
103 NotificationRegistrar registrar_; | 100 NotificationRegistrar registrar_; |
104 | 101 |
105 DISALLOW_COPY_AND_ASSIGN(HostZoomMap); | 102 DISALLOW_COPY_AND_ASSIGN(HostZoomMap); |
106 }; | 103 }; |
107 | 104 |
108 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_H_ | 105 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_H_ |
OLD | NEW |