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 #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/files/file_path.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop_proxy.h" | 16 #include "base/message_loop_proxy.h" |
16 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
17 | 18 |
18 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
19 // On Windows, we group files by their extension, with several exceptions: | 20 // On Windows, we group files by their extension, with several exceptions: |
20 // .dll, .exe, .ico. See IconManager.h for explanation. | 21 // .dll, .exe, .ico. See IconManager.h for explanation. |
21 typedef std::wstring IconGroupID; | 22 typedef std::wstring IconGroupID; |
22 #elif defined(OS_POSIX) | 23 #elif defined(OS_POSIX) |
(...skipping 11 matching lines...) Expand all Loading... |
34 public: | 35 public: |
35 enum IconSize { | 36 enum IconSize { |
36 SMALL = 0, // 16x16 | 37 SMALL = 0, // 16x16 |
37 NORMAL, // 32x32 | 38 NORMAL, // 32x32 |
38 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported | 39 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported |
39 ALL, // All sizes available | 40 ALL, // All sizes available |
40 }; | 41 }; |
41 | 42 |
42 class Delegate { | 43 class Delegate { |
43 public: | 44 public: |
| 45 // Invoked when an icon group has been read, but before the icon data |
| 46 // is read. If the icon is already cached, this method should call and |
| 47 // return the results of OnImageLoaded with the cached image. |
| 48 virtual bool OnGroupLoaded(IconLoader* source, |
| 49 const IconGroupID& group) = 0; |
44 // Invoked when an icon has been read. |source| is the IconLoader. If the | 50 // 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 | 51 // icon has been successfully loaded, result is non-null. This method must |
46 // return true if it is taking ownership of the returned image. | 52 // return true if it is taking ownership of the returned image. |
47 virtual bool OnImageLoaded(IconLoader* source, gfx::Image* result) = 0; | 53 virtual bool OnImageLoaded(IconLoader* source, |
| 54 gfx::Image* result, |
| 55 const IconGroupID& group) = 0; |
48 | 56 |
49 protected: | 57 protected: |
50 virtual ~Delegate() {} | 58 virtual ~Delegate() {} |
51 }; | 59 }; |
52 | 60 |
53 IconLoader(const IconGroupID& group, IconSize size, Delegate* delegate); | 61 IconLoader(const base::FilePath& file_path, |
| 62 IconSize size, |
| 63 Delegate* delegate); |
54 | 64 |
55 // Start reading the icon on the file thread. | 65 // Start reading the icon on the file thread. |
56 void Start(); | 66 void Start(); |
57 | 67 |
58 private: | 68 private: |
59 friend class base::RefCountedThreadSafe<IconLoader>; | 69 friend class base::RefCountedThreadSafe<IconLoader>; |
60 | 70 |
61 virtual ~IconLoader(); | 71 virtual ~IconLoader(); |
62 | 72 |
| 73 // Get the identifying string for the given file. The implementation |
| 74 // is in icon_loader_[platform].cc. |
| 75 static IconGroupID ReadGroupIDFromFilepath(const base::FilePath& path); |
| 76 |
| 77 void ReadGroup(); |
| 78 void OnReadGroup(); |
63 void ReadIcon(); | 79 void ReadIcon(); |
64 | 80 |
65 void NotifyDelegate(); | 81 void NotifyDelegate(); |
66 | 82 |
67 // The message loop object of the thread in which we notify the delegate. | 83 // The message loop object of the thread in which we notify the delegate. |
68 scoped_refptr<base::MessageLoopProxy> target_message_loop_; | 84 scoped_refptr<base::MessageLoopProxy> target_message_loop_; |
69 | 85 |
| 86 base::FilePath file_path_; |
| 87 |
70 IconGroupID group_; | 88 IconGroupID group_; |
71 | 89 |
72 IconSize icon_size_; | 90 IconSize icon_size_; |
73 | 91 |
74 scoped_ptr<gfx::Image> image_; | 92 scoped_ptr<gfx::Image> image_; |
75 | 93 |
76 Delegate* delegate_; | 94 Delegate* delegate_; |
77 | 95 |
78 DISALLOW_COPY_AND_ASSIGN(IconLoader); | 96 DISALLOW_COPY_AND_ASSIGN(IconLoader); |
79 }; | 97 }; |
80 | 98 |
81 #endif // CHROME_BROWSER_ICON_LOADER_H_ | 99 #endif // CHROME_BROWSER_ICON_LOADER_H_ |
OLD | NEW |