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 // Class for finding and caching Windows explorer icons. The IconManager | 5 // Class for finding and caching Windows explorer icons. The IconManager |
6 // lives on the UI thread but performs icon extraction work on the file thread | 6 // lives on the UI thread but performs icon extraction work on the file thread |
7 // to avoid blocking the UI thread with potentially expensive COM and disk | 7 // to avoid blocking the UI thread with potentially expensive COM and disk |
8 // operations. | 8 // operations. |
9 // | 9 // |
10 // Terminology | 10 // Terminology |
(...skipping 29 matching lines...) Expand all Loading... |
40 // fast. | 40 // fast. |
41 // | 41 // |
42 // Icon bitmaps returned should be treated as const since they may be referenced | 42 // Icon bitmaps returned should be treated as const since they may be referenced |
43 // by other clients. Make a copy of the icon if you need to modify it. | 43 // by other clients. Make a copy of the icon if you need to modify it. |
44 | 44 |
45 #ifndef CHROME_BROWSER_ICON_MANAGER_H_ | 45 #ifndef CHROME_BROWSER_ICON_MANAGER_H_ |
46 #define CHROME_BROWSER_ICON_MANAGER_H_ | 46 #define CHROME_BROWSER_ICON_MANAGER_H_ |
47 | 47 |
48 #include <map> | 48 #include <map> |
49 | 49 |
| 50 #include "base/file_path.h" |
50 #include "chrome/browser/icon_loader.h" | 51 #include "chrome/browser/icon_loader.h" |
51 #include "chrome/common/cancelable_task_tracker.h" | 52 #include "chrome/common/cancelable_task_tracker.h" |
52 #include "ui/gfx/image/image.h" | 53 #include "ui/gfx/image/image.h" |
53 | 54 |
54 namespace base { | |
55 class FilePath; | |
56 } | |
57 | |
58 class IconManager : public IconLoader::Delegate { | 55 class IconManager : public IconLoader::Delegate { |
59 public: | 56 public: |
60 IconManager(); | 57 IconManager(); |
61 virtual ~IconManager(); | 58 virtual ~IconManager(); |
62 | 59 |
63 // Synchronous call to examine the internal caches for the icon. Returns the | 60 // Synchronous call to examine the internal caches for the icon. Returns the |
64 // icon if we have already loaded it, NULL if we don't have it and must load | 61 // icon if we have already loaded it, NULL if we don't have it and must load |
65 // it via 'LoadIcon'. The returned bitmap is owned by the IconManager and must | 62 // it via 'LoadIcon'. The returned bitmap is owned by the IconManager and must |
66 // not be free'd by the caller. If the caller needs to modify the icon, it | 63 // not be free'd by the caller. If the caller needs to modify the icon, it |
67 // must make a copy and modify the copy. | 64 // must make a copy and modify the copy. |
68 gfx::Image* LookupIcon(const base::FilePath& file_name, IconLoader::IconSize s
ize); | 65 gfx::Image* LookupIconFromFilepath(const base::FilePath& file_name, |
| 66 IconLoader::IconSize size); |
| 67 gfx::Image* LookupIconFromGroup(const IconGroupID& group, |
| 68 IconLoader::IconSize size); |
69 | 69 |
70 typedef base::Callback<void(gfx::Image*)> IconRequestCallback; | 70 typedef base::Callback<void(gfx::Image*)> IconRequestCallback; |
71 | 71 |
72 // Asynchronous call to lookup and return the icon associated with file. The | 72 // Asynchronous call to lookup and return the icon associated with file. The |
73 // work is done on the file thread, with the callbacks running on the thread | 73 // work is done on the file thread, with the callbacks running on the thread |
74 // this function is called. | 74 // this function is called. |
75 // | 75 // |
76 // Note: | 76 // Note: |
77 // 1. This does *not* check the cache. | 77 // 1. This does *not* check the cache. |
78 // 2. The returned bitmap pointer is *not* owned by callback. So callback | 78 // 2. The returned bitmap pointer is *not* owned by callback. So callback |
79 // should never keep it or delete it. | 79 // should never keep it or delete it. |
80 // 3. The gfx::Image pointer passed to the callback may be NULL if decoding | 80 // 3. The gfx::Image pointer passed to the callback may be NULL if decoding |
81 // failed. | 81 // failed. |
82 CancelableTaskTracker::TaskId LoadIcon(const base::FilePath& file_name, | 82 CancelableTaskTracker::TaskId LoadIcon(const base::FilePath& file_name, |
83 IconLoader::IconSize size, | 83 IconLoader::IconSize size, |
84 const IconRequestCallback& callback, | 84 const IconRequestCallback& callback, |
85 CancelableTaskTracker* tracker); | 85 CancelableTaskTracker* tracker); |
86 | 86 |
87 // IconLoader::Delegate interface. | 87 // IconLoader::Delegate interface. |
88 virtual bool OnImageLoaded(IconLoader* loader, gfx::Image* result) OVERRIDE; | 88 virtual bool OnGroupLoaded(IconLoader* loader, |
| 89 const IconGroupID& group) OVERRIDE; |
| 90 virtual bool OnImageLoaded(IconLoader* loader, |
| 91 gfx::Image* result, |
| 92 const IconGroupID& group) OVERRIDE; |
89 | 93 |
90 // Get the identifying string for the given file. The implementation | 94 // Get the identifying string for the given file. The implementation |
91 // is in icon_manager_[platform].cc. | 95 // is in icon_manager_[platform].cc. |
92 static IconGroupID GetGroupIDFromFilepath(const base::FilePath& path); | 96 static IconGroupID ReadGroupIDFromFilepath(const base::FilePath& path); |
93 | 97 |
94 private: | 98 private: |
95 struct CacheKey { | 99 struct CacheKey { |
96 CacheKey(const IconGroupID& group, IconLoader::IconSize size); | 100 CacheKey(const IconGroupID& group, IconLoader::IconSize size); |
97 | 101 |
98 // Used as a key in the map below, so we need this comparator. | 102 // Used as a key in the map below, so we need this comparator. |
99 bool operator<(const CacheKey &other) const; | 103 bool operator<(const CacheKey &other) const; |
100 | 104 |
101 IconGroupID group; | 105 IconGroupID group; |
102 IconLoader::IconSize size; | 106 IconLoader::IconSize size; |
103 }; | 107 }; |
104 | 108 |
105 typedef std::map<CacheKey, gfx::Image*> IconMap; | 109 typedef std::map<CacheKey, gfx::Image*> IconMap; |
106 IconMap icon_cache_; | 110 IconMap icon_cache_; |
107 | 111 |
| 112 typedef std::map<FilePath, IconGroupID> GroupMap; |
| 113 GroupMap group_cache_; |
| 114 |
108 // Asynchronous requests that have not yet been completed. | 115 // Asynchronous requests that have not yet been completed. |
109 struct ClientRequest; | 116 struct ClientRequest; |
110 typedef std::map<IconLoader*, ClientRequest> ClientRequests; | 117 typedef std::map<IconLoader*, ClientRequest> ClientRequests; |
111 ClientRequests requests_; | 118 ClientRequests requests_; |
112 | 119 |
113 DISALLOW_COPY_AND_ASSIGN(IconManager); | 120 DISALLOW_COPY_AND_ASSIGN(IconManager); |
114 }; | 121 }; |
115 | 122 |
116 #endif // CHROME_BROWSER_ICON_MANAGER_H_ | 123 #endif // CHROME_BROWSER_ICON_MANAGER_H_ |
OLD | NEW |