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

Side by Side Diff: extensions/browser/extension_icon_image.cc

Issue 2424593002: Reduce FOR_EACH_OBSERVER usage in extensions (Closed)
Patch Set: script_observers_ Created 4 years, 2 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
« no previous file with comments | « extensions/browser/extension_host.cc ('k') | extensions/browser/extension_pref_value_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/extension_icon_image.h" 5 #include "extensions/browser/extension_icon_image.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 void IconImage::AddObserver(Observer* observer) { 157 void IconImage::AddObserver(Observer* observer) {
158 observers_.AddObserver(observer); 158 observers_.AddObserver(observer);
159 } 159 }
160 160
161 void IconImage::RemoveObserver(Observer* observer) { 161 void IconImage::RemoveObserver(Observer* observer) {
162 observers_.RemoveObserver(observer); 162 observers_.RemoveObserver(observer);
163 } 163 }
164 164
165 IconImage::~IconImage() { 165 IconImage::~IconImage() {
166 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageDestroyed(this)); 166 for (auto& observer : observers_)
167 observer.OnExtensionIconImageDestroyed(this);
167 source_->ResetHost(); 168 source_->ResetHost();
168 } 169 }
169 170
170 gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor( 171 gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor(
171 ui::ScaleFactor scale_factor) { 172 ui::ScaleFactor scale_factor) {
172 // Do nothing if extension is unloaded. 173 // Do nothing if extension is unloaded.
173 if (!extension_) 174 if (!extension_)
174 return gfx::ImageSkiaRep(); 175 return gfx::ImageSkiaRep();
175 176
176 const float scale = ui::GetScaleForScaleFactor(scale_factor); 177 const float scale = ui::GetScaleForScaleFactor(scale_factor);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 241
241 image_skia_.RemoveRepresentation(scale); 242 image_skia_.RemoveRepresentation(scale);
242 image_skia_.AddRepresentation(rep); 243 image_skia_.AddRepresentation(rep);
243 244
244 // Update the image to use the updated image skia. 245 // Update the image to use the updated image skia.
245 // It's a shame we have to do this because it means that all the other 246 // It's a shame we have to do this because it means that all the other
246 // representations stored on |image_| will be deleted, but unfortunately 247 // representations stored on |image_| will be deleted, but unfortunately
247 // there's no way to combine the storage of two images. 248 // there's no way to combine the storage of two images.
248 image_ = gfx::Image(image_skia_); 249 image_ = gfx::Image(image_skia_);
249 250
250 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); 251 for (auto& observer : observers_)
252 observer.OnExtensionIconImageChanged(this);
251 } 253 }
252 254
253 void IconImage::Observe(int type, 255 void IconImage::Observe(int type,
254 const content::NotificationSource& source, 256 const content::NotificationSource& source,
255 const content::NotificationDetails& details) { 257 const content::NotificationDetails& details) {
256 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); 258 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED);
257 259
258 const Extension* extension = content::Details<const Extension>(details).ptr(); 260 const Extension* extension = content::Details<const Extension>(details).ptr();
259 261
260 if (extension_.get() == extension) 262 if (extension_.get() == extension)
261 extension_ = nullptr; 263 extension_ = nullptr;
262 } 264 }
263 265
264 } // namespace extensions 266 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_host.cc ('k') | extensions/browser/extension_pref_value_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698