[email protected] | 679facce | 2012-07-25 16:13:12 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_ICON_LOADER_H_ |
| 6 | #define CHROME_BROWSER_ICON_LOADER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | 864b136 | 2010-08-19 03:49:38 | [diff] [blame] | 8 | #include "build/build_config.h" |
| 9 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | #include <string> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | |
[email protected] | 56d01f6 | 2009-03-12 22:41:54 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/ref_counted.h" |
| 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | 982735c2 | 2010-10-29 13:58:57 | [diff] [blame] | 15 | #include "base/message_loop_proxy.h" |
[email protected] | f08e051 | 2011-06-13 18:10:44 | [diff] [blame] | 16 | #include "ui/gfx/image/image.h" |
[email protected] | 982735c2 | 2010-10-29 13:58:57 | [diff] [blame] | 17 | |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 18 | #if defined(OS_WIN) |
| 19 | // On Windows, we group files by their extension, with several exceptions: |
| 20 | // .dll, .exe, .ico. See IconManager.h for explanation. |
| 21 | typedef std::wstring IconGroupID; |
| 22 | #elif defined(OS_POSIX) |
| 23 | // On POSIX, we group files by MIME type. |
| 24 | typedef std::string IconGroupID; |
| 25 | #endif |
| 26 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | //////////////////////////////////////////////////////////////////////////////// |
| 28 | // |
| 29 | // A facility to read a file containing an icon asynchronously in the IO |
[email protected] | 679facce | 2012-07-25 16:13:12 | [diff] [blame^] | 30 | // thread. Returns the icon in the form of an ImageSkia. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | // |
| 32 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 46728b1f | 2009-05-07 20:42:24 | [diff] [blame] | 33 | class IconLoader : public base::RefCountedThreadSafe<IconLoader> { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 35 | enum IconSize { |
| 36 | SMALL = 0, // 16x16 |
| 37 | NORMAL, // 32x32 |
[email protected] | 955c37b | 2011-06-08 21:26:30 | [diff] [blame] | 38 | LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported |
| 39 | ALL, // All sizes available |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | class Delegate { |
| 43 | public: |
| 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 |
[email protected] | 679facce | 2012-07-25 16:13:12 | [diff] [blame^] | 46 | // return true if it is taking ownership of the returned image. |
[email protected] | 66171ab | 2011-03-03 15:50:07 | [diff] [blame] | 47 | virtual bool OnImageLoaded(IconLoader* source, gfx::Image* result) = 0; |
[email protected] | 135fd3b6 | 2009-12-16 01:07:08 | [diff] [blame] | 48 | |
| 49 | protected: |
| 50 | virtual ~Delegate() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 51 | }; |
| 52 | |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 53 | IconLoader(const IconGroupID& group, IconSize size, Delegate* delegate); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 54 | |
[email protected] | 46728b1f | 2009-05-07 20:42:24 | [diff] [blame] | 55 | // Start reading the icon on the file thread. |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 56 | void Start(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 57 | |
| 58 | private: |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 59 | friend class base::RefCountedThreadSafe<IconLoader>; |
| 60 | |
| 61 | virtual ~IconLoader(); |
| 62 | |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 63 | void ReadIcon(); |
| 64 | |
| 65 | void NotifyDelegate(); |
| 66 | |
| 67 | // The message loop object of the thread in which we notify the delegate. |
[email protected] | 982735c2 | 2010-10-29 13:58:57 | [diff] [blame] | 68 | scoped_refptr<base::MessageLoopProxy> target_message_loop_; |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 69 | |
| 70 | IconGroupID group_; |
| 71 | |
| 72 | IconSize icon_size_; |
| 73 | |
[email protected] | 66171ab | 2011-03-03 15:50:07 | [diff] [blame] | 74 | scoped_ptr<gfx::Image> image_; |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 75 | |
| 76 | Delegate* delegate_; |
| 77 | |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(IconLoader); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 79 | }; |
| 80 | |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame] | 81 | #endif // CHROME_BROWSER_ICON_LOADER_H_ |