[email protected] | 46728b1f | 2009-05-07 20:42:24 | [diff] [blame] | 1 | // Copyright (c) 2009 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 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include <string> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
[email protected] | 56d01f6 | 2009-03-12 22:41:54 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame] | 11 | #include "base/file_path.h" |
[email protected] | 46728b1f | 2009-05-07 20:42:24 | [diff] [blame] | 12 | #include "base/ref_counted.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 14 | #if defined(OS_WIN) |
| 15 | // On Windows, we group files by their extension, with several exceptions: |
| 16 | // .dll, .exe, .ico. See IconManager.h for explanation. |
| 17 | typedef std::wstring IconGroupID; |
| 18 | #elif defined(OS_POSIX) |
| 19 | // On POSIX, we group files by MIME type. |
| 20 | typedef std::string IconGroupID; |
| 21 | #endif |
| 22 | |
| 23 | class MessageLoop; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | class SkBitmap; |
| 25 | |
| 26 | //////////////////////////////////////////////////////////////////////////////// |
| 27 | // |
| 28 | // A facility to read a file containing an icon asynchronously in the IO |
[email protected] | 46728b1f | 2009-05-07 20:42:24 | [diff] [blame] | 29 | // thread. Returns the icon in the form of an SkBitmap. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | // |
| 31 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 46728b1f | 2009-05-07 20:42:24 | [diff] [blame] | 32 | class IconLoader : public base::RefCountedThreadSafe<IconLoader> { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 33 | public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | enum IconSize { |
| 35 | SMALL = 0, // 16x16 |
| 36 | NORMAL, // 32x32 |
| 37 | LARGE |
| 38 | }; |
| 39 | |
| 40 | class Delegate { |
| 41 | public: |
| 42 | // Invoked when an icon has been read. |source| is the IconLoader. If the |
| 43 | // icon has been successfully loaded, result is non-null. This method must |
| 44 | // return true if it is taking ownership of the returned bitmap. |
[email protected] | 46728b1f | 2009-05-07 20:42:24 | [diff] [blame] | 45 | virtual bool OnBitmapLoaded(IconLoader* source, SkBitmap* result) = 0; |
[email protected] | 135fd3b6 | 2009-12-16 01:07:08 | [diff] [blame^] | 46 | |
| 47 | protected: |
| 48 | virtual ~Delegate() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 49 | }; |
| 50 | |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 51 | IconLoader(const IconGroupID& group, IconSize size, Delegate* delegate); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 52 | |
[email protected] | 46728b1f | 2009-05-07 20:42:24 | [diff] [blame] | 53 | // Start reading the icon on the file thread. |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 54 | void Start(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 55 | |
| 56 | private: |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 57 | friend class base::RefCountedThreadSafe<IconLoader>; |
| 58 | |
| 59 | virtual ~IconLoader(); |
| 60 | |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 61 | void ReadIcon(); |
| 62 | |
| 63 | void NotifyDelegate(); |
| 64 | |
| 65 | // The message loop object of the thread in which we notify the delegate. |
| 66 | MessageLoop* target_message_loop_; |
| 67 | |
| 68 | IconGroupID group_; |
| 69 | |
| 70 | IconSize icon_size_; |
| 71 | |
| 72 | SkBitmap* bitmap_; |
| 73 | |
| 74 | Delegate* delegate_; |
| 75 | |
[email protected] | 937fe520 | 2009-07-16 20:06:47 | [diff] [blame] | 76 | #if defined(OS_LINUX) |
| 77 | // On Linux we use gdk's pixbuf loader, which has to execute on the UI |
| 78 | // thread, so we only read the file on the background thread and parse it |
| 79 | // on the main thread. |
| 80 | void ParseIcon(); |
| 81 | FilePath filename_; |
| 82 | std::string icon_data_; |
| 83 | #endif |
| 84 | |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(IconLoader); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 86 | }; |
| 87 | |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame] | 88 | #endif // CHROME_BROWSER_ICON_LOADER_H_ |