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 browser context. | 6 // any thread. One instance per browser context. |
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/content_export.h" |
20 #include "content/common/notification_observer.h" | 21 #include "content/common/notification_observer.h" |
21 #include "content/common/notification_registrar.h" | 22 #include "content/common/notification_registrar.h" |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 class DictionaryValue; | 25 class DictionaryValue; |
25 } | 26 } |
26 | 27 |
27 class GURL; | 28 class GURL; |
28 | 29 |
29 // HostZoomMap needs to be deleted on the UI thread because it listens | 30 // HostZoomMap needs to be deleted on the UI thread because it listens |
30 // to notifications on there (and holds a NotificationRegistrar). | 31 // to notifications on there (and holds a NotificationRegistrar). |
31 class HostZoomMap | 32 class CONTENT_EXPORT HostZoomMap |
32 : public NotificationObserver, | 33 : public NotificationObserver, |
33 public base::RefCountedThreadSafe<HostZoomMap, | 34 public base::RefCountedThreadSafe<HostZoomMap, |
34 BrowserThread::DeleteOnUIThread> { | 35 BrowserThread::DeleteOnUIThread> { |
35 public: | 36 public: |
36 explicit HostZoomMap(); | 37 explicit HostZoomMap(); |
37 explicit HostZoomMap(HostZoomMap* original); | 38 explicit HostZoomMap(HostZoomMap* original); |
38 | 39 |
39 // Returns the zoom level for the host or spec for a given url. The zoom | 40 // Returns the zoom level for the host or spec for a given url. The zoom |
40 // level is determined by the host portion of the URL, or (in the absence of | 41 // level is determined by the host portion of the URL, or (in the absence of |
41 // a host) the complete spec of the URL. In most cases, there is no custom | 42 // a host) the complete spec of the URL. In most cases, there is no custom |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 virtual void Observe(int type, | 74 virtual void Observe(int type, |
74 const NotificationSource& source, | 75 const NotificationSource& source, |
75 const NotificationDetails& details); | 76 const NotificationDetails& details); |
76 | 77 |
77 double default_zoom_level() const { return default_zoom_level_; } | 78 double default_zoom_level() const { return default_zoom_level_; } |
78 void set_default_zoom_level(double level) { default_zoom_level_ = level; } | 79 void set_default_zoom_level(double level) { default_zoom_level_ = level; } |
79 | 80 |
80 HostZoomMap* GetOriginal() const { return original_; } | 81 HostZoomMap* GetOriginal() const { return original_; } |
81 | 82 |
82 private: | 83 private: |
| 84 friend class base::RefCountedThreadSafe<HostZoomMap, |
| 85 BrowserThread::DeleteOnUIThread>; |
83 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 86 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
84 friend class DeleteTask<HostZoomMap>; | 87 friend class DeleteTask<HostZoomMap>; |
85 | 88 |
86 typedef std::map<std::string, double> HostZoomLevels; | 89 typedef std::map<std::string, double> HostZoomLevels; |
87 | 90 |
88 virtual ~HostZoomMap(); | 91 virtual ~HostZoomMap(); |
89 void Init(); | 92 void Init(); |
90 | 93 |
91 // Copy of the pref data, so that we can read it on the IO thread. | 94 // Copy of the pref data, so that we can read it on the IO thread. |
92 HostZoomLevels host_zoom_levels_; | 95 HostZoomLevels host_zoom_levels_; |
(...skipping 15 matching lines...) Expand all Loading... |
108 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and | 111 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and |
109 // |temporary_zoom_levels_| to guarantee thread safety. | 112 // |temporary_zoom_levels_| to guarantee thread safety. |
110 mutable base::Lock lock_; | 113 mutable base::Lock lock_; |
111 | 114 |
112 NotificationRegistrar registrar_; | 115 NotificationRegistrar registrar_; |
113 | 116 |
114 DISALLOW_COPY_AND_ASSIGN(HostZoomMap); | 117 DISALLOW_COPY_AND_ASSIGN(HostZoomMap); |
115 }; | 118 }; |
116 | 119 |
117 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_H_ | 120 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_H_ |
OLD | NEW |