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

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

Issue 12039058: content: convert zoom notifications to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_EACH_OBSERVER(HostZoomMap::Observer, observers_,
94 NOTIFICATION_ZOOM_LEVEL_CHANGED, 94 OnZoomLevelChanged(host));
95 Source<HostZoomMap>(this),
96 Details<const std::string>(&host));
97 } 95 }
98 96
99 double HostZoomMapImpl::GetDefaultZoomLevel() const { 97 double HostZoomMapImpl::GetDefaultZoomLevel() const {
100 return default_zoom_level_; 98 return default_zoom_level_;
101 } 99 }
102 100
103 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { 101 void HostZoomMapImpl::SetDefaultZoomLevel(double level) {
104 default_zoom_level_ = level; 102 default_zoom_level_ = level;
105 } 103 }
106 104
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 136
139 if (level && i == temporary_zoom_levels_.size()) { 137 if (level && i == temporary_zoom_levels_.size()) {
140 TemporaryZoomLevel temp; 138 TemporaryZoomLevel temp;
141 temp.render_process_id = render_process_id; 139 temp.render_process_id = render_process_id;
142 temp.render_view_id = render_view_id; 140 temp.render_view_id = render_view_id;
143 temp.zoom_level = level; 141 temp.zoom_level = level;
144 temporary_zoom_levels_.push_back(temp); 142 temporary_zoom_levels_.push_back(temp);
145 } 143 }
146 } 144 }
147 145
148 std::string host; 146 FOR_EACH_OBSERVER(HostZoomMap::Observer, observers_,
149 NotificationService::current()->Notify( 147 OnZoomLevelChanged(""));
150 NOTIFICATION_ZOOM_LEVEL_CHANGED,
151 Source<HostZoomMap>(this),
152 Details<const std::string>(&host));
153 } 148 }
154 149
155 void HostZoomMapImpl::Observe(int type, 150 void HostZoomMapImpl::Observe(int type,
156 const NotificationSource& source, 151 const NotificationSource& source,
157 const NotificationDetails& details) { 152 const NotificationDetails& details) {
158 switch (type) { 153 switch (type) {
159 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { 154 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: {
160 base::AutoLock auto_lock(lock_); 155 base::AutoLock auto_lock(lock_);
161 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); 156 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID();
162 int render_process_id = 157 int render_process_id =
163 Source<RenderViewHost>(source)->GetProcess()->GetID(); 158 Source<RenderViewHost>(source)->GetProcess()->GetID();
164 159
165 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { 160 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) {
166 if (temporary_zoom_levels_[i].render_process_id == render_process_id && 161 if (temporary_zoom_levels_[i].render_process_id == render_process_id &&
167 temporary_zoom_levels_[i].render_view_id == render_view_id) { 162 temporary_zoom_levels_[i].render_view_id == render_view_id) {
168 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); 163 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i);
169 break; 164 break;
170 } 165 }
171 } 166 }
172 break; 167 break;
173 } 168 }
174 default: 169 default:
175 NOTREACHED() << "Unexpected preference observed."; 170 NOTREACHED() << "Unexpected preference observed.";
176 } 171 }
177 } 172 }
178 173
174 void HostZoomMapImpl::AddObserver(HostZoomMap::Observer* observer) {
175 observers_.AddObserver(observer);
176 }
177
178 void HostZoomMapImpl::RemoveObserver(HostZoomMap::Observer* observer) {
179 observers_.RemoveObserver(observer);
180 }
181
179 HostZoomMapImpl::~HostZoomMapImpl() { 182 HostZoomMapImpl::~HostZoomMapImpl() {
180 } 183 }
181 184
182 } // namespace content 185 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698