| 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 <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "ui/gfx/icon_util.h" | 14 #include "ui/gfx/icon_util.h" |
| 15 #include "ui/gfx/image/image_skia.h" |
| 15 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 16 | 17 |
| 17 void IconLoader::ReadIcon() { | 18 void IconLoader::ReadIcon() { |
| 18 int size = 0; | 19 int size = 0; |
| 19 switch (icon_size_) { | 20 switch (icon_size_) { |
| 20 case IconLoader::SMALL: | 21 case IconLoader::SMALL: |
| 21 size = SHGFI_SMALLICON; | 22 size = SHGFI_SMALLICON; |
| 22 break; | 23 break; |
| 23 case IconLoader::NORMAL: | 24 case IconLoader::NORMAL: |
| 24 size = 0; | 25 size = 0; |
| 25 break; | 26 break; |
| 26 case IconLoader::LARGE: | 27 case IconLoader::LARGE: |
| 27 size = SHGFI_LARGEICON; | 28 size = SHGFI_LARGEICON; |
| 28 break; | 29 break; |
| 29 default: | 30 default: |
| 30 NOTREACHED(); | 31 NOTREACHED(); |
| 31 } | 32 } |
| 32 SHFILEINFO file_info = { 0 }; | 33 SHFILEINFO file_info = { 0 }; |
| 33 if (!SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, | 34 if (!SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, |
| 34 sizeof(SHFILEINFO), | 35 sizeof(SHFILEINFO), |
| 35 SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) | 36 SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) |
| 36 return; | 37 return; |
| 37 | 38 |
| 38 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON( | 39 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON( |
| 39 file_info.hIcon)); | 40 file_info.hIcon)); |
| 40 image_.reset(new gfx::Image(*bitmap)); | 41 gfx::ImageSkia image_skia(*bitmap); |
| 42 image_skia.MakeThreadSafe(); |
| 43 image_.reset(new gfx::Image(image_skia)); |
| 41 DestroyIcon(file_info.hIcon); | 44 DestroyIcon(file_info.hIcon); |
| 42 target_message_loop_->PostTask(FROM_HERE, | 45 target_message_loop_->PostTask(FROM_HERE, |
| 43 base::Bind(&IconLoader::NotifyDelegate, this)); | 46 base::Bind(&IconLoader::NotifyDelegate, this)); |
| 44 } | 47 } |
| OLD | NEW |