OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_ICON_LOADER_H_ | 5 #ifndef CHROME_BROWSER_ICON_LOADER_H_ |
6 #define CHROME_BROWSER_ICON_LOADER_H_ | 6 #define CHROME_BROWSER_ICON_LOADER_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop_proxy.h" | 15 #include "base/message_loop_proxy.h" |
16 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
17 | 17 |
18 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
19 // On Windows, we group files by their extension, with several exceptions: | 19 // On Windows, we group files by their extension, with several exceptions: |
20 // .dll, .exe, .ico. See IconManager.h for explanation. | 20 // .dll, .exe, .ico. See IconManager.h for explanation. |
21 typedef std::wstring IconGroupID; | 21 typedef std::wstring IconGroupID; |
22 #elif defined(OS_POSIX) | 22 #elif defined(OS_POSIX) |
23 // On POSIX, we group files by MIME type. | 23 // On POSIX, we group files by MIME type. |
24 typedef std::string IconGroupID; | 24 typedef std::string IconGroupID; |
25 #endif | 25 #endif |
26 | 26 |
27 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
28 // | 28 // |
29 // A facility to read a file containing an icon asynchronously in the IO | 29 // A facility to read a file containing an icon asynchronously in the IO |
30 // thread. Returns the icon in the form of an SkBitmap. | 30 // thread. Returns the icon in the form of an ImageSkia. |
31 // | 31 // |
32 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
33 class IconLoader : public base::RefCountedThreadSafe<IconLoader> { | 33 class IconLoader : public base::RefCountedThreadSafe<IconLoader> { |
34 public: | 34 public: |
35 enum IconSize { | 35 enum IconSize { |
36 SMALL = 0, // 16x16 | 36 SMALL = 0, // 16x16 |
37 NORMAL, // 32x32 | 37 NORMAL, // 32x32 |
38 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported | 38 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported |
39 ALL, // All sizes available | 39 ALL, // All sizes available |
40 }; | 40 }; |
41 | 41 |
42 class Delegate { | 42 class Delegate { |
43 public: | 43 public: |
44 // Invoked when an icon has been read. |source| is the IconLoader. If the | 44 // Invoked when an icon has been read. |source| is the IconLoader. If the |
45 // icon has been successfully loaded, result is non-null. This method must | 45 // icon has been successfully loaded, result is non-null. This method must |
46 // return true if it is taking ownership of the returned bitmap. | 46 // return true if it is taking ownership of the returned image. |
47 virtual bool OnImageLoaded(IconLoader* source, gfx::Image* result) = 0; | 47 virtual bool OnImageLoaded(IconLoader* source, gfx::Image* result) = 0; |
48 | 48 |
49 protected: | 49 protected: |
50 virtual ~Delegate() {} | 50 virtual ~Delegate() {} |
51 }; | 51 }; |
52 | 52 |
53 IconLoader(const IconGroupID& group, IconSize size, Delegate* delegate); | 53 IconLoader(const IconGroupID& group, IconSize size, Delegate* delegate); |
54 | 54 |
55 // Start reading the icon on the file thread. | 55 // Start reading the icon on the file thread. |
56 void Start(); | 56 void Start(); |
(...skipping 15 matching lines...) Expand all Loading... |
72 IconSize icon_size_; | 72 IconSize icon_size_; |
73 | 73 |
74 scoped_ptr<gfx::Image> image_; | 74 scoped_ptr<gfx::Image> image_; |
75 | 75 |
76 Delegate* delegate_; | 76 Delegate* delegate_; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(IconLoader); | 78 DISALLOW_COPY_AND_ASSIGN(IconLoader); |
79 }; | 79 }; |
80 | 80 |
81 #endif // CHROME_BROWSER_ICON_LOADER_H_ | 81 #endif // CHROME_BROWSER_ICON_LOADER_H_ |
OLD | NEW |