OLD | NEW |
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 "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 IconImage::Source::Source(IconImage* host, const gfx::Size& size_in_dip) | 98 IconImage::Source::Source(IconImage* host, const gfx::Size& size_in_dip) |
99 : host_(host), | 99 : host_(host), |
100 blank_image_(new BlankImageSource(size_in_dip), size_in_dip) { | 100 blank_image_(new BlankImageSource(size_in_dip), size_in_dip) { |
101 } | 101 } |
102 | 102 |
103 IconImage::Source::~Source() { | 103 IconImage::Source::~Source() { |
104 } | 104 } |
105 | 105 |
106 void IconImage::Source::ResetHost() { | 106 void IconImage::Source::ResetHost() { |
107 host_ = NULL; | 107 host_ = nullptr; |
108 } | 108 } |
109 | 109 |
110 gfx::ImageSkiaRep IconImage::Source::GetImageForScale(float scale) { | 110 gfx::ImageSkiaRep IconImage::Source::GetImageForScale(float scale) { |
111 gfx::ImageSkiaRep representation; | 111 gfx::ImageSkiaRep representation; |
112 if (host_) { | 112 if (host_) { |
113 representation = | 113 representation = |
114 host_->LoadImageForScaleFactor(ui::GetSupportedScaleFactor(scale)); | 114 host_->LoadImageForScaleFactor(ui::GetSupportedScaleFactor(scale)); |
115 } | 115 } |
116 | 116 |
117 if (!representation.is_null()) | 117 if (!representation.is_null()) |
118 return representation; | 118 return representation; |
119 | 119 |
120 return blank_image_.GetRepresentation(scale); | 120 return blank_image_.GetRepresentation(scale); |
121 } | 121 } |
122 | 122 |
123 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
124 // IconImage | 124 // IconImage |
125 | 125 |
126 IconImage::IconImage( | 126 IconImage::IconImage(content::BrowserContext* context, |
127 content::BrowserContext* context, | 127 const Extension* extension, |
128 const Extension* extension, | 128 const ExtensionIconSet& icon_set, |
129 const ExtensionIconSet& icon_set, | 129 int resource_size_in_dip, |
130 int resource_size_in_dip, | 130 const gfx::ImageSkia& default_icon, |
131 const gfx::ImageSkia& default_icon, | 131 Observer* observer) |
132 Observer* observer) | |
133 : browser_context_(context), | 132 : browser_context_(context), |
134 extension_(extension), | 133 extension_(extension), |
135 icon_set_(icon_set), | 134 icon_set_(icon_set), |
136 resource_size_in_dip_(resource_size_in_dip), | 135 resource_size_in_dip_(resource_size_in_dip), |
137 observer_(observer), | 136 observer_(observer), |
138 source_(NULL), | 137 source_(nullptr), |
139 default_icon_(gfx::ImageSkiaOperations::CreateResizedImage( | 138 default_icon_(gfx::ImageSkiaOperations::CreateResizedImage( |
140 default_icon, | 139 default_icon, |
141 skia::ImageOperations::RESIZE_BEST, | 140 skia::ImageOperations::RESIZE_BEST, |
142 gfx::Size(resource_size_in_dip, resource_size_in_dip))), | 141 gfx::Size(resource_size_in_dip, resource_size_in_dip))), |
143 weak_ptr_factory_(this) { | 142 weak_ptr_factory_(this) { |
144 gfx::Size resource_size(resource_size_in_dip, resource_size_in_dip); | 143 gfx::Size resource_size(resource_size_in_dip, resource_size_in_dip); |
145 source_ = new Source(this, resource_size); | 144 source_ = new Source(this, resource_size); |
146 image_skia_ = gfx::ImageSkia(source_, resource_size); | 145 image_skia_ = gfx::ImageSkia(source_, resource_size); |
147 | 146 |
148 registrar_.Add(this, | 147 registrar_.Add(this, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 220 } |
222 | 221 |
223 void IconImage::Observe(int type, | 222 void IconImage::Observe(int type, |
224 const content::NotificationSource& source, | 223 const content::NotificationSource& source, |
225 const content::NotificationDetails& details) { | 224 const content::NotificationDetails& details) { |
226 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); | 225 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); |
227 | 226 |
228 const Extension* extension = content::Details<const Extension>(details).ptr(); | 227 const Extension* extension = content::Details<const Extension>(details).ptr(); |
229 | 228 |
230 if (extension_ == extension) | 229 if (extension_ == extension) |
231 extension_ = NULL; | 230 extension_ = nullptr; |
232 } | 231 } |
233 | 232 |
234 } // namespace extensions | 233 } // namespace extensions |
OLD | NEW |