OLD | NEW |
---|---|
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 83 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
84 !i.IsAtEnd(); i.Advance()) { | 84 !i.IsAtEnd(); i.Advance()) { |
85 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 85 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
86 if (HostZoomMap::GetForBrowserContext( | 86 if (HostZoomMap::GetForBrowserContext( |
87 render_process_host->GetBrowserContext()) == this) { | 87 render_process_host->GetBrowserContext()) == this) { |
88 render_process_host->Send( | 88 render_process_host->Send( |
89 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); | 89 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 NotificationService::current()->Notify( | 93 for (std::vector<ZoomLevelChangedCallback>::iterator i = |
jam
2013/01/30 17:50:44
nit: here and below, using
for (size_t i = 0; i
Paweł Hajdan Jr.
2013/01/31 16:02:15
Done. For deletion I'm still using iterators - I c
jam
2013/01/31 17:59:15
not sure why you'd use a temporary std::vector? a
| |
94 NOTIFICATION_ZOOM_LEVEL_CHANGED, | 94 zoom_level_changed_callbacks_.begin(); |
95 Source<HostZoomMap>(this), | 95 i != zoom_level_changed_callbacks_.end(); |
96 Details<const std::string>(&host)); | 96 ++i) { |
97 (*i).Run(host); | |
98 } | |
97 } | 99 } |
98 | 100 |
99 double HostZoomMapImpl::GetDefaultZoomLevel() const { | 101 double HostZoomMapImpl::GetDefaultZoomLevel() const { |
100 return default_zoom_level_; | 102 return default_zoom_level_; |
101 } | 103 } |
102 | 104 |
103 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { | 105 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { |
104 default_zoom_level_ = level; | 106 default_zoom_level_ = level; |
105 } | 107 } |
106 | 108 |
109 void HostZoomMapImpl::AddZoomLevelChangedCallback( | |
110 ZoomLevelChangedCallback callback) { | |
111 zoom_level_changed_callbacks_.push_back(callback); | |
112 } | |
113 | |
114 void HostZoomMapImpl::RemoveZoomLevelChangedCallback( | |
115 ZoomLevelChangedCallback callback) { | |
116 for (std::vector<ZoomLevelChangedCallback>::iterator i = | |
117 zoom_level_changed_callbacks_.begin(); | |
118 i != zoom_level_changed_callbacks_.end(); | |
119 ++i) { | |
120 if ((*i).Equals(callback)) { | |
121 i = zoom_level_changed_callbacks_.erase(i); | |
122 } | |
123 } | |
124 } | |
125 | |
107 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, | 126 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, |
108 int render_view_id) const { | 127 int render_view_id) const { |
109 base::AutoLock auto_lock(lock_); | 128 base::AutoLock auto_lock(lock_); |
110 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { | 129 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { |
111 if (temporary_zoom_levels_[i].render_process_id == render_process_id && | 130 if (temporary_zoom_levels_[i].render_process_id == render_process_id && |
112 temporary_zoom_levels_[i].render_view_id == render_view_id) { | 131 temporary_zoom_levels_[i].render_view_id == render_view_id) { |
113 return temporary_zoom_levels_[i].zoom_level; | 132 return temporary_zoom_levels_[i].zoom_level; |
114 } | 133 } |
115 } | 134 } |
116 return 0; | 135 return 0; |
(...skipping 21 matching lines...) Expand all Loading... | |
138 | 157 |
139 if (level && i == temporary_zoom_levels_.size()) { | 158 if (level && i == temporary_zoom_levels_.size()) { |
140 TemporaryZoomLevel temp; | 159 TemporaryZoomLevel temp; |
141 temp.render_process_id = render_process_id; | 160 temp.render_process_id = render_process_id; |
142 temp.render_view_id = render_view_id; | 161 temp.render_view_id = render_view_id; |
143 temp.zoom_level = level; | 162 temp.zoom_level = level; |
144 temporary_zoom_levels_.push_back(temp); | 163 temporary_zoom_levels_.push_back(temp); |
145 } | 164 } |
146 } | 165 } |
147 | 166 |
148 std::string host; | 167 for (std::vector<ZoomLevelChangedCallback>::iterator i = |
149 NotificationService::current()->Notify( | 168 zoom_level_changed_callbacks_.begin(); |
150 NOTIFICATION_ZOOM_LEVEL_CHANGED, | 169 i != zoom_level_changed_callbacks_.end(); |
151 Source<HostZoomMap>(this), | 170 ++i) { |
152 Details<const std::string>(&host)); | 171 (*i).Run(std::string()); |
172 } | |
153 } | 173 } |
154 | 174 |
155 void HostZoomMapImpl::Observe(int type, | 175 void HostZoomMapImpl::Observe(int type, |
156 const NotificationSource& source, | 176 const NotificationSource& source, |
157 const NotificationDetails& details) { | 177 const NotificationDetails& details) { |
158 switch (type) { | 178 switch (type) { |
159 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { | 179 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { |
160 base::AutoLock auto_lock(lock_); | 180 base::AutoLock auto_lock(lock_); |
161 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); | 181 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); |
162 int render_process_id = | 182 int render_process_id = |
(...skipping 10 matching lines...) Expand all Loading... | |
173 } | 193 } |
174 default: | 194 default: |
175 NOTREACHED() << "Unexpected preference observed."; | 195 NOTREACHED() << "Unexpected preference observed."; |
176 } | 196 } |
177 } | 197 } |
178 | 198 |
179 HostZoomMapImpl::~HostZoomMapImpl() { | 199 HostZoomMapImpl::~HostZoomMapImpl() { |
180 } | 200 } |
181 | 201 |
182 } // namespace content | 202 } // namespace content |
OLD | NEW |