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

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

Issue 6538111: Move the rest of the core files in chrome\browser to content\browser.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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/browser/gpu_process_host_ui_shim.cc ('k') | chrome/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
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
6 // any thread. One instance per profile.
7
8 #ifndef CHROME_BROWSER_HOST_ZOOM_MAP_H_ 5 #ifndef CHROME_BROWSER_HOST_ZOOM_MAP_H_
9 #define CHROME_BROWSER_HOST_ZOOM_MAP_H_ 6 #define CHROME_BROWSER_HOST_ZOOM_MAP_H_
10 #pragma once 7 #pragma once
11 8
12 #include <map> 9 // TODO(jam): remove this file when all files have been converted.
13 #include <string> 10 #include "content/browser/host_zoom_map.h"
14 #include <vector>
15
16 #include "base/basictypes.h"
17 #include "base/ref_counted.h"
18 #include "base/synchronization/lock.h"
19 #include "chrome/browser/browser_thread.h"
20 #include "chrome/browser/prefs/pref_change_registrar.h"
21 #include "chrome/common/notification_observer.h"
22 #include "chrome/common/notification_registrar.h"
23
24 class GURL;
25 class PrefService;
26 class Profile;
27
28 // HostZoomMap needs to be deleted on the UI thread because it listens
29 // to notifications on there (and holds a NotificationRegistrar).
30 class HostZoomMap :
31 public NotificationObserver,
32 public base::RefCountedThreadSafe<HostZoomMap,
33 BrowserThread::DeleteOnUIThread> {
34 public:
35 explicit HostZoomMap(Profile* profile);
36
37 static void RegisterUserPrefs(PrefService* prefs);
38
39 // Returns the zoom level for a given url. The zoom level is determined by
40 // the host portion of the URL, or (in the absence of a host) the complete
41 // spec of the URL. In most cases, there is no custom zoom level, and this
42 // returns the user's default zoom level. Otherwise, returns the saved zoom
43 // level, which may be positive (to zoom in) or negative (to zoom out).
44 //
45 // This may be called on any thread.
46 double GetZoomLevel(const GURL& url) const;
47
48 // Sets the zoom level for a given url to |level|. If the level matches the
49 // current default zoom level, the host is erased from the saved preferences;
50 // otherwise the new value is written out.
51 //
52 // This should only be called on the UI thread.
53 void SetZoomLevel(const GURL& url, 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 // Resets all zoom levels.
72 //
73 // This should only be called on the UI thread.
74 void ResetToDefaults();
75
76 // NotificationObserver implementation.
77 virtual void Observe(NotificationType type,
78 const NotificationSource& source,
79 const NotificationDetails& details);
80
81 private:
82 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
83 friend class DeleteTask<HostZoomMap>;
84
85 typedef std::map<std::string, double> HostZoomLevels;
86
87 ~HostZoomMap();
88
89 // Reads the zoom levels from the preferences service.
90 void Load();
91
92 // Removes dependencies on the profile so we can live longer than
93 // the profile without crashing.
94 void Shutdown();
95
96 // The profile we're associated with.
97 Profile* profile_;
98
99 // Copy of the pref data, so that we can read it on the IO thread.
100 HostZoomLevels host_zoom_levels_;
101 double default_zoom_level_;
102
103 struct TemporaryZoomLevel {
104 int render_process_id;
105 int render_view_id;
106 double zoom_level;
107 };
108
109 // Don't expect more than a couple of tabs that are using a temporary zoom
110 // level, so vector is fine for now.
111 std::vector<TemporaryZoomLevel> temporary_zoom_levels_;
112
113 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and
114 // |temporary_zoom_levels_| to guarantee thread safety.
115 mutable base::Lock lock_;
116
117 // Whether we are currently updating preferences, this is used to ignore
118 // notifications from the preference service that we triggered ourself.
119 bool updating_preferences_;
120
121 NotificationRegistrar registrar_;
122 PrefChangeRegistrar pref_change_registrar_;
123
124 DISALLOW_COPY_AND_ASSIGN(HostZoomMap);
125 };
126 11
127 #endif // CHROME_BROWSER_HOST_ZOOM_MAP_H_ 12 #endif // CHROME_BROWSER_HOST_ZOOM_MAP_H_
OLDNEW
« no previous file with comments | « chrome/browser/gpu_process_host_ui_shim.cc ('k') | chrome/browser/host_zoom_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698