Fix build break
[chromium-blink-merge.git] / chrome / browser / icon_loader_win.cc
blob62cb6f08ee258973afcc70c8e20af3d8219f9dc9
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
3 // found in the LICENSE file.
5 #include "chrome/browser/icon_loader.h"
7 #include <windows.h>
8 #include <shellapi.h>
10 #include "base/bind.h"
11 #include "base/message_loop.h"
12 #include "base/threading/thread.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/icon_util.h"
15 #include "ui/gfx/image/image_skia.h"
16 #include "ui/gfx/size.h"
18 // static
19 IconGroupID IconLoader::ReadGroupIDFromFilepath(
20 const base::FilePath& filepath) {
21 if (!IsIconMutableFromFilepath(filepath))
22 return filepath.Extension();
23 return filepath.value();
26 bool IconLoader::IsIconMutableFromFilepath(const base::FilePath& filepath) {
27 base::FilePath::StringType extension = filepath.Extension();
28 return extension == L".exe" || extension == L".dll" || extension == L".ico";
31 void IconLoader::ReadIcon() {
32 int size = 0;
33 switch (icon_size_) {
34 case IconLoader::SMALL:
35 size = SHGFI_SMALLICON;
36 break;
37 case IconLoader::NORMAL:
38 size = 0;
39 break;
40 case IconLoader::LARGE:
41 size = SHGFI_LARGEICON;
42 break;
43 default:
44 NOTREACHED();
47 image_.reset();
49 SHFILEINFO file_info = { 0 };
50 if (SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info,
51 sizeof(SHFILEINFO),
52 SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) {
53 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(
54 file_info.hIcon));
55 if (bitmap.get()) {
56 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(*bitmap);
57 image_skia.MakeThreadSafe();
58 image_.reset(new gfx::Image(image_skia));
59 DestroyIcon(file_info.hIcon);
63 // Always notify the delegate, regardless of success.
64 target_message_loop_->PostTask(FROM_HERE,
65 base::Bind(&IconLoader::NotifyDelegate, this));