OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_HOST_ZOOM_MAP_H_ | 8 #ifndef CHROME_BROWSER_HOST_ZOOM_MAP_H_ |
9 #define CHROME_BROWSER_HOST_ZOOM_MAP_H_ | 9 #define CHROME_BROWSER_HOST_ZOOM_MAP_H_ |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/lock.h" | 15 #include "base/lock.h" |
16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
17 #include "chrome/common/notification_observer.h" | 17 #include "chrome/common/notification_observer.h" |
18 #include "chrome/common/notification_registrar.h" | 18 #include "chrome/common/notification_registrar.h" |
19 | 19 |
| 20 class GURL; |
20 class PrefService; | 21 class PrefService; |
21 class Profile; | 22 class Profile; |
22 | 23 |
23 class HostZoomMap : public NotificationObserver, | 24 class HostZoomMap : public NotificationObserver, |
24 public base::RefCountedThreadSafe<HostZoomMap> { | 25 public base::RefCountedThreadSafe<HostZoomMap> { |
25 public: | 26 public: |
26 explicit HostZoomMap(Profile* profile); | 27 explicit HostZoomMap(Profile* profile); |
27 | 28 |
28 static void RegisterUserPrefs(PrefService* prefs); | 29 static void RegisterUserPrefs(PrefService* prefs); |
29 | 30 |
30 // Returns the zoom level for a given hostname. In most cases, there is no | 31 // Returns the zoom level for a given url. The zoom level is determined by |
31 // custom zoom level, and this returns 0. Otherwise, returns the saved zoom | 32 // the host portion of the URL, or (in the absence of a host) the complete |
32 // level, which may be positive (to zoom in) or negative (to zoom out). | 33 // spec of the URL. In most cases, there is no custom zoom level, and this |
| 34 // returns 0. Otherwise, returns the saved zoom level, which may be positive |
| 35 // (to zoom in) or negative (to zoom out). |
33 // | 36 // |
34 // This may be called on any thread. | 37 // This may be called on any thread. |
35 int GetZoomLevel(const std::string& host) const; | 38 int GetZoomLevel(const GURL& url) const; |
36 | 39 |
37 // Sets the zoom level for a given hostname to |level|. If the level is 0, | 40 // Sets the zoom level for a given url to |level|. If the level is 0, |
38 // the host is erased from the saved preferences; otherwise the new value is | 41 // the host is erased from the saved preferences; otherwise the new value is |
39 // written out. | 42 // written out. |
40 // | 43 // |
41 // This should only be called on the UI thread. | 44 // This should only be called on the UI thread. |
42 void SetZoomLevel(const std::string& host, int level); | 45 void SetZoomLevel(const GURL& url, int level); |
43 | 46 |
44 // Resets all zoom levels. | 47 // Resets all zoom levels. |
45 // | 48 // |
46 // This should only be called on the UI thread. | 49 // This should only be called on the UI thread. |
47 void ResetToDefaults(); | 50 void ResetToDefaults(); |
48 | 51 |
49 // NotificationObserver implementation. | 52 // NotificationObserver implementation. |
50 virtual void Observe(NotificationType type, | 53 virtual void Observe(NotificationType type, |
51 const NotificationSource& source, | 54 const NotificationSource& source, |
52 const NotificationDetails& details); | 55 const NotificationDetails& details); |
(...skipping 24 matching lines...) Expand all Loading... |
77 // Whether we are currently updating preferences, this is used to ignore | 80 // Whether we are currently updating preferences, this is used to ignore |
78 // notifications from the preference service that we triggered ourself. | 81 // notifications from the preference service that we triggered ourself. |
79 bool updating_preferences_; | 82 bool updating_preferences_; |
80 | 83 |
81 NotificationRegistrar registrar_; | 84 NotificationRegistrar registrar_; |
82 | 85 |
83 DISALLOW_COPY_AND_ASSIGN(HostZoomMap); | 86 DISALLOW_COPY_AND_ASSIGN(HostZoomMap); |
84 }; | 87 }; |
85 | 88 |
86 #endif // CHROME_BROWSER_HOST_ZOOM_MAP_H_ | 89 #endif // CHROME_BROWSER_HOST_ZOOM_MAP_H_ |
OLD | NEW |