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

Side by Side Diff: content/browser/host_zoom_map_impl.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 | « content/browser/host_zoom_map.cc ('k') | content/browser/host_zoom_map_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
6 // any thread. One instance per browser context. 6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
7
8 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_H_
9 #define CONTENT_BROWSER_HOST_ZOOM_MAP_H_
10 #pragma once 7 #pragma once
11 8
12 #include <map> 9 #include <map>
13 #include <string> 10 #include <string>
14 #include <vector> 11 #include <vector>
15 12
16 #include "base/basictypes.h" 13 #include "base/compiler_specific.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/message_loop_helpers.h" 14 #include "base/message_loop_helpers.h"
19 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
20 #include "content/common/content_export.h" 16 #include "content/public/browser/host_zoom_map.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
24 19
25 // HostZoomMap needs to be deleted on the UI thread because it listens 20 // HostZoomMap needs to be deleted on the UI thread because it listens
26 // to notifications on there (and holds a NotificationRegistrar). 21 // to notifications on there (and holds a NotificationRegistrar).
27 class CONTENT_EXPORT HostZoomMap 22 class CONTENT_EXPORT HostZoomMapImpl
28 : public content::NotificationObserver, 23 : public NON_EXPORTED_BASE(content::HostZoomMap),
29 public base::RefCountedThreadSafe< 24 public content::NotificationObserver {
30 HostZoomMap, content::BrowserThread::DeleteOnUIThread> {
31 public: 25 public:
32 HostZoomMap(); 26 HostZoomMapImpl();
33 27
34 // Copy the zoom levels from the given map. Can only be called on the UI 28 // HostZoomMap implementation:
35 // thread. 29 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE;
36 void CopyFrom(HostZoomMap* copy); 30 virtual double GetZoomLevel(const std::string& host) const OVERRIDE;
37 31 virtual void SetZoomLevel(std::string host, double level) OVERRIDE;
38 // Returns the zoom level for the host or spec for a given url. The zoom 32 virtual double GetDefaultZoomLevel() const OVERRIDE;
39 // level is determined by the host portion of the URL, or (in the absence of 33 virtual void SetDefaultZoomLevel(double level) OVERRIDE;
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 34
55 // Returns the temporary zoom level that's only valid for the lifetime of 35 // 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 36 // the given tab (i.e. isn't saved and doesn't affect other tabs) if it
57 // exists, the default zoom level otherwise. 37 // exists, the default zoom level otherwise.
58 // 38 //
59 // This may be called on any thread. 39 // This may be called on any thread.
60 double GetTemporaryZoomLevel(int render_process_id, 40 double GetTemporaryZoomLevel(int render_process_id,
61 int render_view_id) const; 41 int render_view_id) const;
62 42
63 // Sets the temporary zoom level that's only valid for the lifetime of this 43 // Sets the temporary zoom level that's only valid for the lifetime of this
64 // tab. 44 // tab.
65 // 45 //
66 // This should only be called on the UI thread. 46 // This should only be called on the UI thread.
67 void SetTemporaryZoomLevel(int render_process_id, 47 void SetTemporaryZoomLevel(int render_process_id,
68 int render_view_id, 48 int render_view_id,
69 double level); 49 double level);
70 50
71 // content::NotificationObserver implementation. 51 // content::NotificationObserver implementation.
72 virtual void Observe(int type, 52 virtual void Observe(int type,
73 const content::NotificationSource& source, 53 const content::NotificationSource& source,
74 const content::NotificationDetails& details) OVERRIDE; 54 const content::NotificationDetails& details) OVERRIDE;
75 55
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: 56 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; 57 typedef std::map<std::string, double> HostZoomLevels;
87 58
88 virtual ~HostZoomMap(); 59 virtual ~HostZoomMapImpl();
89 60
90 // Copy of the pref data, so that we can read it on the IO thread. 61 // Copy of the pref data, so that we can read it on the IO thread.
91 HostZoomLevels host_zoom_levels_; 62 HostZoomLevels host_zoom_levels_;
92 double default_zoom_level_; 63 double default_zoom_level_;
93 64
94 struct TemporaryZoomLevel { 65 struct TemporaryZoomLevel {
95 int render_process_id; 66 int render_process_id;
96 int render_view_id; 67 int render_view_id;
97 double zoom_level; 68 double zoom_level;
98 }; 69 };
99 70
100 // Don't expect more than a couple of tabs that are using a temporary zoom 71 // Don't expect more than a couple of tabs that are using a temporary zoom
101 // level, so vector is fine for now. 72 // level, so vector is fine for now.
102 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; 73 std::vector<TemporaryZoomLevel> temporary_zoom_levels_;
103 74
104 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and 75 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and
105 // |temporary_zoom_levels_| to guarantee thread safety. 76 // |temporary_zoom_levels_| to guarantee thread safety.
106 mutable base::Lock lock_; 77 mutable base::Lock lock_;
107 78
108 content::NotificationRegistrar registrar_; 79 content::NotificationRegistrar registrar_;
109 80
110 DISALLOW_COPY_AND_ASSIGN(HostZoomMap); 81 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl);
111 }; 82 };
112 83
113 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_H_ 84 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/host_zoom_map.cc ('k') | content/browser/host_zoom_map_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698