summaryrefslogtreecommitdiffstats
path: root/chrome/browser/host_zoom_map.h
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-04 23:49:51 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-04 23:49:51 +0000
commit40bd658fd9aeedc8f2f7cc17c835f41095df9189 (patch)
tree87e9562263a8a641f7d2da19f629a2737d67c041 /chrome/browser/host_zoom_map.h
parent1c42268bc05d715b59d1b535e432c0d9ef666113 (diff)
downloadchromium_src-40bd658fd9aeedc8f2f7cc17c835f41095df9189.zip
chromium_src-40bd658fd9aeedc8f2f7cc17c835f41095df9189.tar.gz
chromium_src-40bd658fd9aeedc8f2f7cc17c835f41095df9189.tar.bz2
Remember zoom on a per-host basis.
BUG=567 TEST=Visit a page, zoom in or out, then navigate to a different host. The new page should not be zoomed. Go back, or restart, or open a new tab and navigate to the old page, and it should be zoomed. Review URL: http://codereview.chromium.org/437077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33886 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/host_zoom_map.h')
-rw-r--r--chrome/browser/host_zoom_map.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/chrome/browser/host_zoom_map.h b/chrome/browser/host_zoom_map.h
new file mode 100644
index 0000000..1cf86be
--- /dev/null
+++ b/chrome/browser/host_zoom_map.h
@@ -0,0 +1,60 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Maps hostnames to custom zoom levels. Written on the UI thread and read on
+// the IO thread. One instance per profile.
+
+#ifndef CHROME_BROWSER_HOST_ZOOM_MAP_H_
+#define CHROME_BROWSER_HOST_ZOOM_MAP_H_
+
+#include <map>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/lock.h"
+#include "base/ref_counted.h"
+
+class PrefService;
+class Profile;
+
+class HostZoomMap : public base::RefCountedThreadSafe<HostZoomMap> {
+ public:
+ explicit HostZoomMap(Profile* profile);
+
+ static void RegisterUserPrefs(PrefService* prefs);
+
+ // Returns the zoom level for a given hostname. In most cases, there is no
+ // custom zoom level, and this returns 0. Otherwise, returns the saved zoom
+ // level, which may be positive (to zoom in) or negative (to zoom out).
+ //
+ // This may be called on any thread.
+ int GetZoomLevel(const std::string& host) const;
+
+ // Sets the zoom level for a given hostname to |level|. If the level is 0,
+ // the host is erased from the saved preferences; otherwise the new value is
+ // written out.
+ //
+ // This should only be called on the UI thread.
+ void SetZoomLevel(const std::string& host, int level);
+
+ private:
+ friend class base::RefCountedThreadSafe<HostZoomMap>;
+
+ typedef std::map<std::string, int> HostZoomLevels;
+
+ ~HostZoomMap();
+
+ // The profile we're associated with.
+ Profile* profile_;
+
+ // Copy of the pref data, so that we can read it on the IO thread.
+ HostZoomLevels host_zoom_levels_;
+
+ // Used around accesses to |host_zoom_levels_| to guarantee thread safety.
+ mutable Lock lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostZoomMap);
+};
+
+#endif // CHROME_BROWSER_HOST_ZOOM_MAP_H_