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 "chrome/browser/extensions/extension_icon_manager.h" | 5 #include "chrome/browser/extensions/extension_icon_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "extensions/browser/image_loader.h" | 10 #include "extensions/browser/image_loader.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), | 72 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), |
73 base::Bind( | 73 base::Bind( |
74 &ExtensionIconManager::OnImageLoaded, | 74 &ExtensionIconManager::OnImageLoaded, |
75 weak_ptr_factory_.GetWeakPtr(), | 75 weak_ptr_factory_.GetWeakPtr(), |
76 extension->id())); | 76 extension->id())); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 const SkBitmap& ExtensionIconManager::GetIcon(const std::string& extension_id) { | 80 const SkBitmap& ExtensionIconManager::GetIcon(const std::string& extension_id) { |
81 const SkBitmap* result = NULL; | 81 const SkBitmap* result = NULL; |
82 if (ContainsKey(icons_, extension_id)) { | 82 if (base::ContainsKey(icons_, extension_id)) { |
83 result = &icons_[extension_id]; | 83 result = &icons_[extension_id]; |
84 } else { | 84 } else { |
85 EnsureDefaultIcon(); | 85 EnsureDefaultIcon(); |
86 result = &default_icon_; | 86 result = &default_icon_; |
87 } | 87 } |
88 DCHECK(result); | 88 DCHECK(result); |
89 DCHECK_EQ(gfx::kFaviconSize + padding_.width(), result->width()); | 89 DCHECK_EQ(gfx::kFaviconSize + padding_.width(), result->width()); |
90 DCHECK_EQ(gfx::kFaviconSize + padding_.height(), result->height()); | 90 DCHECK_EQ(gfx::kFaviconSize + padding_.height(), result->height()); |
91 return *result; | 91 return *result; |
92 } | 92 } |
93 | 93 |
94 void ExtensionIconManager::RemoveIcon(const std::string& extension_id) { | 94 void ExtensionIconManager::RemoveIcon(const std::string& extension_id) { |
95 icons_.erase(extension_id); | 95 icons_.erase(extension_id); |
96 pending_icons_.erase(extension_id); | 96 pending_icons_.erase(extension_id); |
97 } | 97 } |
98 | 98 |
99 void ExtensionIconManager::OnImageLoaded(const std::string& extension_id, | 99 void ExtensionIconManager::OnImageLoaded(const std::string& extension_id, |
100 const gfx::Image& image) { | 100 const gfx::Image& image) { |
101 if (image.IsEmpty()) | 101 if (image.IsEmpty()) |
102 return; | 102 return; |
103 | 103 |
104 // We may have removed the icon while waiting for it to load. In that case, | 104 // We may have removed the icon while waiting for it to load. In that case, |
105 // do nothing. | 105 // do nothing. |
106 if (!ContainsKey(pending_icons_, extension_id)) | 106 if (!base::ContainsKey(pending_icons_, extension_id)) |
107 return; | 107 return; |
108 | 108 |
109 pending_icons_.erase(extension_id); | 109 pending_icons_.erase(extension_id); |
110 icons_[extension_id] = ApplyTransforms(*image.ToSkBitmap()); | 110 icons_[extension_id] = ApplyTransforms(*image.ToSkBitmap()); |
111 } | 111 } |
112 | 112 |
113 void ExtensionIconManager::EnsureDefaultIcon() { | 113 void ExtensionIconManager::EnsureDefaultIcon() { |
114 if (default_icon_.empty()) { | 114 if (default_icon_.empty()) { |
115 // TODO(estade): use correct scale factor instead of 1x. | 115 // TODO(estade): use correct scale factor instead of 1x. |
116 default_icon_ = ApplyPadding( | 116 default_icon_ = ApplyPadding( |
(...skipping 17 matching lines...) Expand all Loading... |
134 if (monochrome_) { | 134 if (monochrome_) { |
135 color_utils::HSL shift = {-1, 0, 0.6}; | 135 color_utils::HSL shift = {-1, 0, 0.6}; |
136 result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift); | 136 result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift); |
137 } | 137 } |
138 | 138 |
139 if (!padding_.IsEmpty()) | 139 if (!padding_.IsEmpty()) |
140 result = ApplyPadding(result, padding_); | 140 result = ApplyPadding(result, padding_); |
141 | 141 |
142 return result; | 142 return result; |
143 } | 143 } |
OLD | NEW |