Componentize AccountReconcilor.
[chromium-blink-merge.git] / chrome / browser / icon_loader_win.cc
blobd0d77dc261039a16047a5e3f7a82a5c5de7c30bc
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/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"
17 #include "ui/gfx/win/dpi.h"
19 // static
20 IconGroupID IconLoader::ReadGroupIDFromFilepath(
21 const base::FilePath& filepath) {
22 if (!IsIconMutableFromFilepath(filepath))
23 return filepath.Extension();
24 return filepath.value();
27 // static
28 bool IconLoader::IsIconMutableFromFilepath(const base::FilePath& filepath) {
29 return filepath.MatchesExtension(L".exe") ||
30 filepath.MatchesExtension(L".dll") ||
31 filepath.MatchesExtension(L".ico");
34 // static
35 content::BrowserThread::ID IconLoader::ReadIconThreadID() {
36 return content::BrowserThread::FILE;
39 void IconLoader::ReadIcon() {
40 int size = 0;
41 switch (icon_size_) {
42 case IconLoader::SMALL:
43 size = SHGFI_SMALLICON;
44 break;
45 case IconLoader::NORMAL:
46 size = 0;
47 break;
48 case IconLoader::LARGE:
49 size = SHGFI_LARGEICON;
50 break;
51 default:
52 NOTREACHED();
55 image_.reset();
57 SHFILEINFO file_info = { 0 };
58 if (SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info,
59 sizeof(SHFILEINFO),
60 SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) {
61 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(
62 file_info.hIcon));
63 if (bitmap.get()) {
64 gfx::ImageSkia image_skia(gfx::ImageSkiaRep(
65 *bitmap, gfx::win::GetDeviceScaleFactor()));
66 image_skia.MakeThreadSafe();
67 image_.reset(new gfx::Image(image_skia));
68 DestroyIcon(file_info.hIcon);
72 // Always notify the delegate, regardless of success.
73 target_message_loop_->PostTask(FROM_HERE,
74 base::Bind(&IconLoader::NotifyDelegate, this));