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, | |
Robert Sesek
2013/02/12 16:49:25
Does this need to be public?
shatch
2013/02/13 16:14:52
Doesn't need to be, but I made it public in case a
Robert Sesek
2013/02/13 17:33:05
I prefer a minimally exposed interface. But your c
shatch
2013/02/21 20:02:06
Done.
| |
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 OnImageLoaded(IconLoader* loader, |
89 gfx::Image* result, | |
90 const IconGroupID& group) OVERRIDE; | |
91 | |
Robert Sesek
2013/02/12 16:49:25
nit: no blank line needed
shatch
2013/02/13 16:14:52
Done.
| |
92 virtual bool OnGroupLoaded(IconLoader* loader, | |
93 const IconGroupID& group) OVERRIDE; | |
89 | 94 |
90 // Get the identifying string for the given file. The implementation | 95 // Get the identifying string for the given file. The implementation |
91 // is in icon_manager_[platform].cc. | 96 // is in icon_manager_[platform].cc. |
92 static IconGroupID GetGroupIDFromFilepath(const base::FilePath& path); | 97 static IconGroupID ReadGroupIDFromFilepath(const base::FilePath& path); |
93 | 98 |
94 private: | 99 private: |
95 struct CacheKey { | 100 struct CacheKey { |
96 CacheKey(const IconGroupID& group, IconLoader::IconSize size); | 101 CacheKey(const IconGroupID& group, IconLoader::IconSize size); |
97 | 102 |
98 // Used as a key in the map below, so we need this comparator. | 103 // Used as a key in the map below, so we need this comparator. |
99 bool operator<(const CacheKey &other) const; | 104 bool operator<(const CacheKey &other) const; |
100 | 105 |
101 IconGroupID group; | 106 IconGroupID group; |
102 IconLoader::IconSize size; | 107 IconLoader::IconSize size; |
103 }; | 108 }; |
104 | 109 |
105 typedef std::map<CacheKey, gfx::Image*> IconMap; | 110 typedef std::map<CacheKey, gfx::Image*> IconMap; |
106 IconMap icon_cache_; | 111 IconMap icon_cache_; |
107 | 112 |
113 typedef std::map<FilePath, IconGroupID> GroupMap; | |
Robert Sesek
2013/02/12 16:49:25
I'm not sure how much of a benefit this cache mapp
shatch
2013/02/13 16:14:52
From what I could see, it got used when you did th
Robert Sesek
2013/02/13 17:33:05
Ah, good point.
| |
114 GroupMap group_cache_; | |
115 | |
108 // Asynchronous requests that have not yet been completed. | 116 // Asynchronous requests that have not yet been completed. |
109 struct ClientRequest; | 117 struct ClientRequest; |
110 typedef std::map<IconLoader*, ClientRequest> ClientRequests; | 118 typedef std::map<IconLoader*, ClientRequest> ClientRequests; |
111 ClientRequests requests_; | 119 ClientRequests requests_; |
112 | 120 |
113 DISALLOW_COPY_AND_ASSIGN(IconManager); | 121 DISALLOW_COPY_AND_ASSIGN(IconManager); |
114 }; | 122 }; |
115 | 123 |
116 #endif // CHROME_BROWSER_ICON_MANAGER_H_ | 124 #endif // CHROME_BROWSER_ICON_MANAGER_H_ |
OLD | NEW |