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 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
14 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
15 #include "ui/gfx/image/image_skia_util_mac.h" | 16 #include "ui/gfx/image/image_skia_util_mac.h" |
16 | 17 |
17 // static | 18 // static |
18 IconLoader::IconGroup IconLoader::GroupForFilepath( | 19 IconLoader::IconGroup IconLoader::GroupForFilepath( |
19 const base::FilePath& file_path) { | 20 const base::FilePath& file_path) { |
20 return file_path.Extension(); | 21 return file_path.Extension(); |
21 } | 22 } |
22 | 23 |
23 // static | 24 // static |
24 content::BrowserThread::ID IconLoader::ReadIconThreadID() { | 25 content::BrowserThread::ID IconLoader::ReadIconThreadID() { |
25 return content::BrowserThread::FILE; | 26 return content::BrowserThread::FILE; |
26 } | 27 } |
27 | 28 |
28 void IconLoader::ReadIcon() { | 29 void IconLoader::ReadIcon() { |
29 NSString* group = base::SysUTF8ToNSString(group_); | 30 NSString* group = base::SysUTF8ToNSString(group_); |
30 NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; | 31 NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; |
31 NSImage* icon = [workspace iconForFileType:group]; | 32 NSImage* icon = [workspace iconForFileType:group]; |
32 | 33 |
| 34 std::unique_ptr<gfx::Image> image; |
| 35 |
33 if (icon_size_ == ALL) { | 36 if (icon_size_ == ALL) { |
34 // The NSImage already has all sizes. | 37 // The NSImage already has all sizes. |
35 image_.reset(new gfx::Image([icon retain])); | 38 image = base::MakeUnique<gfx::Image>([icon retain]); |
36 } else { | 39 } else { |
37 NSSize size = NSZeroSize; | 40 NSSize size = NSZeroSize; |
38 switch (icon_size_) { | 41 switch (icon_size_) { |
39 case IconLoader::SMALL: | 42 case IconLoader::SMALL: |
40 size = NSMakeSize(16, 16); | 43 size = NSMakeSize(16, 16); |
41 break; | 44 break; |
42 case IconLoader::NORMAL: | 45 case IconLoader::NORMAL: |
43 size = NSMakeSize(32, 32); | 46 size = NSMakeSize(32, 32); |
44 break; | 47 break; |
45 default: | 48 default: |
46 NOTREACHED(); | 49 NOTREACHED(); |
47 } | 50 } |
48 gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size)); | 51 gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size)); |
49 if (!image_skia.isNull()) { | 52 if (!image_skia.isNull()) { |
50 image_skia.MakeThreadSafe(); | 53 image_skia.MakeThreadSafe(); |
51 image_.reset(new gfx::Image(image_skia)); | 54 image = base::MakeUnique<gfx::Image>(image_skia); |
52 } | 55 } |
53 } | 56 } |
54 | 57 |
55 target_task_runner_->PostTask( | 58 target_task_runner_->PostTask( |
56 FROM_HERE, base::Bind(callback_, base::Passed(&image_), group_)); | 59 FROM_HERE, base::Bind(callback_, base::Passed(&image), group_)); |
57 delete this; | 60 delete this; |
58 } | 61 } |
OLD | NEW |