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

Side by Side Diff: content/browser/host_zoom_map_impl.cc

Issue 11866004: Add scheme to HostZoomMap (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix Nikita's comments Created 7 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <cmath> 5 #include <cmath>
6 6
7 #include "content/browser/host_zoom_map_impl.h" 7 #include "content/browser/host_zoom_map_impl.h"
8 8
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 27 matching lines...) Expand all
38 return rv; 38 return rv;
39 } 39 }
40 40
41 HostZoomMapImpl::HostZoomMapImpl() 41 HostZoomMapImpl::HostZoomMapImpl()
42 : default_zoom_level_(0.0) { 42 : default_zoom_level_(0.0) {
43 registrar_.Add( 43 registrar_.Add(
44 this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, 44 this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
45 NotificationService::AllSources()); 45 NotificationService::AllSources());
46 } 46 }
47 47
48 void HostZoomMapImpl::CopyHostZoomLevels(const HostZoomLevels &source,
49 HostZoomLevels &dest) {
50 for (HostZoomLevels::const_iterator i(source.begin());
sky 2013/01/11 20:33:32 dest->insert(source.begin(), source.end()) , at wh
Denis Kuznetsov (DE-MUC) 2013/01/17 13:23:47 Done.
51 i != source.end(); ++i) {
52 dest[i->first] = i->second;
53 }
54 }
55
48 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { 56 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) {
49 // This can only be called on the UI thread to avoid deadlocks, otherwise 57 // This can only be called on the UI thread to avoid deadlocks, otherwise
50 // UI: a.CopyFrom(b); 58 // UI: a.CopyFrom(b);
51 // IO: b.CopyFrom(a); 59 // IO: b.CopyFrom(a);
52 // can deadlock. 60 // can deadlock.
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
54 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); 62 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface);
55 base::AutoLock auto_lock(lock_); 63 base::AutoLock auto_lock(lock_);
56 base::AutoLock copy_auto_lock(copy->lock_); 64 base::AutoLock copy_auto_lock(copy->lock_);
57 for (HostZoomLevels::const_iterator i(copy->host_zoom_levels_.begin()); 65 CopyHostZoomLevels(copy->host_zoom_levels_, host_zoom_levels_);
58 i != copy->host_zoom_levels_.end(); ++i) { 66 for (SchemeHostZoomLevels::const_iterator i(copy->
59 host_zoom_levels_[i->first] = i->second; 67 scheme_host_zoom_levels_.begin());
68 i != copy->scheme_host_zoom_levels_.end(); ++i) {
69 scheme_host_zoom_levels_[i->first] = HostZoomLevels();
70 CopyHostZoomLevels(i->second, scheme_host_zoom_levels_[i->first]);
60 } 71 }
61 } 72 }
62 73
63 double HostZoomMapImpl::GetZoomLevel(const std::string& host) const { 74 double HostZoomMapImpl::GetZoomLevel(const std::string& host) const {
64 base::AutoLock auto_lock(lock_); 75 base::AutoLock auto_lock(lock_);
65 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); 76 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host));
66 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; 77 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second;
67 } 78 }
68 79
80 double HostZoomMapImpl::GetZoomLevel(const std::string& scheme,
81 const std::string& host) const {
82 {
83 base::AutoLock auto_lock(lock_);
84 SchemeHostZoomLevels::const_iterator scheme_iterator(
85 scheme_host_zoom_levels_.find(scheme));
86 if (scheme_iterator != scheme_host_zoom_levels_.end()) {
87 HostZoomLevels::const_iterator i(scheme_iterator->second.find(host));
88 if (i != scheme_iterator->second.end())
89 return i->second;
90 }
91 }
92 return GetZoomLevel(host);
93 }
94
69 void HostZoomMapImpl::SetZoomLevel(const std::string& host, double level) { 95 void HostZoomMapImpl::SetZoomLevel(const std::string& host, double level) {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
71 97
72 { 98 {
73 base::AutoLock auto_lock(lock_); 99 base::AutoLock auto_lock(lock_);
74 100
75 if (ZoomValuesEqual(level, default_zoom_level_)) 101 if (ZoomValuesEqual(level, default_zoom_level_))
76 host_zoom_levels_.erase(host); 102 host_zoom_levels_.erase(host);
77 else 103 else
78 host_zoom_levels_[host] = level; 104 host_zoom_levels_[host] = level;
79 } 105 }
80 106
81 // Notify renderers from this browser context. 107 // Notify renderers from this browser context.
82 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); 108 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
83 !i.IsAtEnd(); i.Advance()) { 109 !i.IsAtEnd(); i.Advance()) {
84 RenderProcessHost* render_process_host = i.GetCurrentValue(); 110 RenderProcessHost* render_process_host = i.GetCurrentValue();
85 if (HostZoomMap::GetForBrowserContext( 111 if (HostZoomMap::GetForBrowserContext(
86 render_process_host->GetBrowserContext()) == this) { 112 render_process_host->GetBrowserContext()) == this) {
87 render_process_host->Send( 113 render_process_host->Send(
88 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); 114 new ViewMsg_SetZoomLevelForCurrentURL(std::string(), host, level));
89 } 115 }
90 } 116 }
91 117
92 NotificationService::current()->Notify( 118 NotificationService::current()->Notify(
93 NOTIFICATION_ZOOM_LEVEL_CHANGED, 119 NOTIFICATION_ZOOM_LEVEL_CHANGED,
94 Source<HostZoomMap>(this), 120 Source<HostZoomMap>(this),
95 Details<const std::string>(&host)); 121 Details<const std::string>(&host));
96 } 122 }
97 123
124 void HostZoomMapImpl::SetZoomLevel(const std::string& scheme,
125 const std::string& host,
126 double level) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128 {
129 base::AutoLock auto_lock(lock_);
130 scheme_host_zoom_levels_[scheme][host] = level;
131 }
132
133 // Notify renderers from this browser context.
134 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
135 !i.IsAtEnd(); i.Advance()) {
136 RenderProcessHost* render_process_host = i.GetCurrentValue();
137 if (HostZoomMap::GetForBrowserContext(
138 render_process_host->GetBrowserContext()) == this) {
139 render_process_host->Send(
140 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level));
141 }
142 }
143
144 NotificationService::current()->Notify(
145 NOTIFICATION_ZOOM_LEVEL_CHANGED,
146 Source<HostZoomMap>(this),
147 Details<const std::string>(&host));
148 }
149
150
sky 2013/01/11 20:33:32 remove one newline.
Denis Kuznetsov (DE-MUC) 2013/01/17 13:23:47 Done.
Denis Kuznetsov (DE-MUC) 2013/01/17 13:23:47 Done.
98 double HostZoomMapImpl::GetDefaultZoomLevel() const { 151 double HostZoomMapImpl::GetDefaultZoomLevel() const {
99 return default_zoom_level_; 152 return default_zoom_level_;
100 } 153 }
101 154
102 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { 155 void HostZoomMapImpl::SetDefaultZoomLevel(double level) {
103 default_zoom_level_ = level; 156 default_zoom_level_ = level;
104 } 157 }
105 158
106 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, 159 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id,
107 int render_view_id) const { 160 int render_view_id) const {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 225 }
173 default: 226 default:
174 NOTREACHED() << "Unexpected preference observed."; 227 NOTREACHED() << "Unexpected preference observed.";
175 } 228 }
176 } 229 }
177 230
178 HostZoomMapImpl::~HostZoomMapImpl() { 231 HostZoomMapImpl::~HostZoomMapImpl() {
179 } 232 }
180 233
181 } // namespace content 234 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698