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

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: fixes Created 7 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
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 (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++)
94 NOTIFICATION_ZOOM_LEVEL_CHANGED, 94 zoom_level_changed_callbacks_[i].Run(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
105 void HostZoomMapImpl::AddZoomLevelChangedCallback(
106 const ZoomLevelChangedCallback& callback) {
107 zoom_level_changed_callbacks_.push_back(callback);
108 }
109
110 void HostZoomMapImpl::RemoveZoomLevelChangedCallback(
111 const ZoomLevelChangedCallback& callback) {
112 for (std::vector<ZoomLevelChangedCallback>::iterator i =
113 zoom_level_changed_callbacks_.begin();
114 i != zoom_level_changed_callbacks_.end();
115 ++i) {
116 if ((*i).Equals(callback)) {
117 i = zoom_level_changed_callbacks_.erase(i);
118 }
119 }
120 }
121
107 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, 122 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id,
108 int render_view_id) const { 123 int render_view_id) const {
109 base::AutoLock auto_lock(lock_); 124 base::AutoLock auto_lock(lock_);
110 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { 125 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) {
111 if (temporary_zoom_levels_[i].render_process_id == render_process_id && 126 if (temporary_zoom_levels_[i].render_process_id == render_process_id &&
112 temporary_zoom_levels_[i].render_view_id == render_view_id) { 127 temporary_zoom_levels_[i].render_view_id == render_view_id) {
113 return temporary_zoom_levels_[i].zoom_level; 128 return temporary_zoom_levels_[i].zoom_level;
114 } 129 }
115 } 130 }
116 return 0; 131 return 0;
(...skipping 21 matching lines...) Expand all
138 153
139 if (level && i == temporary_zoom_levels_.size()) { 154 if (level && i == temporary_zoom_levels_.size()) {
140 TemporaryZoomLevel temp; 155 TemporaryZoomLevel temp;
141 temp.render_process_id = render_process_id; 156 temp.render_process_id = render_process_id;
142 temp.render_view_id = render_view_id; 157 temp.render_view_id = render_view_id;
143 temp.zoom_level = level; 158 temp.zoom_level = level;
144 temporary_zoom_levels_.push_back(temp); 159 temporary_zoom_levels_.push_back(temp);
145 } 160 }
146 } 161 }
147 162
148 std::string host; 163 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++)
149 NotificationService::current()->Notify( 164 zoom_level_changed_callbacks_[i].Run(std::string());
150 NOTIFICATION_ZOOM_LEVEL_CHANGED,
151 Source<HostZoomMap>(this),
152 Details<const std::string>(&host));
153 } 165 }
154 166
155 void HostZoomMapImpl::Observe(int type, 167 void HostZoomMapImpl::Observe(int type,
156 const NotificationSource& source, 168 const NotificationSource& source,
157 const NotificationDetails& details) { 169 const NotificationDetails& details) {
158 switch (type) { 170 switch (type) {
159 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { 171 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: {
160 base::AutoLock auto_lock(lock_); 172 base::AutoLock auto_lock(lock_);
161 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); 173 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID();
162 int render_process_id = 174 int render_process_id =
(...skipping 10 matching lines...) Expand all
173 } 185 }
174 default: 186 default:
175 NOTREACHED() << "Unexpected preference observed."; 187 NOTREACHED() << "Unexpected preference observed.";
176 } 188 }
177 } 189 }
178 190
179 HostZoomMapImpl::~HostZoomMapImpl() { 191 HostZoomMapImpl::~HostZoomMapImpl() {
180 } 192 }
181 193
182 } // namespace content 194 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698