Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: content/browser/host_zoom_map.h

Issue 9296041: Create Content API around HostZoomMap. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/base/testing_profile.cc ('k') | content/browser/host_zoom_map.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // Maps hostnames to custom zoom levels. Written on the UI thread and read on
6 // any thread. One instance per browser context.
7
8 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_H_
9 #define CONTENT_BROWSER_HOST_ZOOM_MAP_H_
10 #pragma once
11
12 #include <map>
13 #include <string>
14 #include <vector>
15
16 #include "base/basictypes.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/message_loop_helpers.h"
19 #include "base/synchronization/lock.h"
20 #include "content/common/content_export.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h"
24
25 // HostZoomMap needs to be deleted on the UI thread because it listens
26 // to notifications on there (and holds a NotificationRegistrar).
27 class CONTENT_EXPORT HostZoomMap
28 : public content::NotificationObserver,
29 public base::RefCountedThreadSafe<
30 HostZoomMap, content::BrowserThread::DeleteOnUIThread> {
31 public:
32 HostZoomMap();
33
34 // Copy the zoom levels from the given map. Can only be called on the UI
35 // thread.
36 void CopyFrom(HostZoomMap* copy);
37
38 // Returns the zoom level for the host or spec for a given url. The zoom
39 // level is determined by the host portion of the URL, or (in the absence of
40 // a host) the complete spec of the URL. In most cases, there is no custom
41 // zoom level, and this returns the user's default zoom level. Otherwise,
42 // returns the saved zoom level, which may be positive (to zoom in) or
43 // negative (to zoom out).
44 //
45 // This may be called on any thread.
46 double GetZoomLevel(const std::string& host) const;
47
48 // Sets the zoom level for the host or spec for a given url to |level|. If
49 // the level matches the current default zoom level, the host is erased
50 // from the saved preferences; otherwise the new value is written out.
51 //
52 // This should only be called on the UI thread.
53 void SetZoomLevel(std::string host, double level);
54
55 // Returns the temporary zoom level that's only valid for the lifetime of
56 // the given tab (i.e. isn't saved and doesn't affect other tabs) if it
57 // exists, the default zoom level otherwise.
58 //
59 // This may be called on any thread.
60 double GetTemporaryZoomLevel(int render_process_id,
61 int render_view_id) const;
62
63 // Sets the temporary zoom level that's only valid for the lifetime of this
64 // tab.
65 //
66 // This should only be called on the UI thread.
67 void SetTemporaryZoomLevel(int render_process_id,
68 int render_view_id,
69 double level);
70
71 // content::NotificationObserver implementation.
72 virtual void Observe(int type,
73 const content::NotificationSource& source,
74 const content::NotificationDetails& details) OVERRIDE;
75
76 double default_zoom_level() const { return default_zoom_level_; }
77 void set_default_zoom_level(double level) { default_zoom_level_ = level; }
78
79 private:
80 friend class base::RefCountedThreadSafe<
81 HostZoomMap, content::BrowserThread::DeleteOnUIThread>;
82 friend struct content::BrowserThread::DeleteOnThread<
83 content::BrowserThread::UI>;
84 friend class base::DeleteHelper<HostZoomMap>;
85
86 typedef std::map<std::string, double> HostZoomLevels;
87
88 virtual ~HostZoomMap();
89
90 // Copy of the pref data, so that we can read it on the IO thread.
91 HostZoomLevels host_zoom_levels_;
92 double default_zoom_level_;
93
94 struct TemporaryZoomLevel {
95 int render_process_id;
96 int render_view_id;
97 double zoom_level;
98 };
99
100 // Don't expect more than a couple of tabs that are using a temporary zoom
101 // level, so vector is fine for now.
102 std::vector<TemporaryZoomLevel> temporary_zoom_levels_;
103
104 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and
105 // |temporary_zoom_levels_| to guarantee thread safety.
106 mutable base::Lock lock_;
107
108 content::NotificationRegistrar registrar_;
109
110 DISALLOW_COPY_AND_ASSIGN(HostZoomMap);
111 };
112
113 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_H_
OLDNEW
« no previous file with comments | « chrome/test/base/testing_profile.cc ('k') | content/browser/host_zoom_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698