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/icon_loader.h" | 5 #include "chrome/browser/icon_loader.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/string_util.h" |
15 #include "chrome/browser/icon_loader.h" | 17 #include "chrome/browser/icon_loader.h" |
16 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
18 #include "ui/base/layout.h" | 20 #include "ui/base/layout.h" |
19 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/codec/png_codec.h" | 23 #include "ui/gfx/codec/png_codec.h" |
22 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
23 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
24 #include "ui/gfx/image/image_skia_operations.h" | 26 #include "ui/gfx/image/image_skia_operations.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // Since we have already chosen the largest applicable image resource, we | 172 // Since we have already chosen the largest applicable image resource, we |
171 // return the image as-is. | 173 // return the image as-is. |
172 case IconLoader::ALL: // fallthrough | 174 case IconLoader::ALL: // fallthrough |
173 default: | 175 default: |
174 return kDoNotResize; | 176 return kDoNotResize; |
175 } | 177 } |
176 } | 178 } |
177 | 179 |
178 } // namespace | 180 } // namespace |
179 | 181 |
| 182 // static |
| 183 IconGroupID IconLoader::ReadGroupIDFromFilepath( |
| 184 const base::FilePath& filepath) { |
| 185 return StringToLowerASCII(filepath.Extension()); |
| 186 } |
| 187 |
180 void IconLoader::ReadIcon() { | 188 void IconLoader::ReadIcon() { |
181 static base::LazyInstance<IconMapper>::Leaky icon_mapper = | 189 static base::LazyInstance<IconMapper>::Leaky icon_mapper = |
182 LAZY_INSTANCE_INITIALIZER; | 190 LAZY_INSTANCE_INITIALIZER; |
183 int idr = icon_mapper.Get().Lookup(group_, icon_size_); | 191 int idr = icon_mapper.Get().Lookup(group_, icon_size_); |
184 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 192 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
185 gfx::ImageSkia image_skia(ResizeImage(*(rb.GetImageNamed(idr)).ToImageSkia(), | 193 gfx::ImageSkia image_skia(ResizeImage(*(rb.GetImageNamed(idr)).ToImageSkia(), |
186 IconSizeToDIPSize(icon_size_))); | 194 IconSizeToDIPSize(icon_size_))); |
187 image_skia.MakeThreadSafe(); | 195 image_skia.MakeThreadSafe(); |
188 image_.reset(new gfx::Image(image_skia)); | 196 image_.reset(new gfx::Image(image_skia)); |
189 target_message_loop_->PostTask( | 197 target_message_loop_->PostTask( |
190 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); | 198 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); |
191 } | 199 } |
OLD | NEW |