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 30 matching lines...) Expand all Loading... |
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/files/file_path.h" | 50 #include "base/files/file_path.h" |
| 51 #include "base/task/cancelable_task_tracker.h" |
51 #include "chrome/browser/icon_loader.h" | 52 #include "chrome/browser/icon_loader.h" |
52 #include "chrome/common/cancelable_task_tracker.h" | |
53 #include "ui/gfx/image/image.h" | 53 #include "ui/gfx/image/image.h" |
54 | 54 |
55 class IconManager : public IconLoader::Delegate { | 55 class IconManager : public IconLoader::Delegate { |
56 public: | 56 public: |
57 IconManager(); | 57 IconManager(); |
58 virtual ~IconManager(); | 58 virtual ~IconManager(); |
59 | 59 |
60 // 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 |
61 // 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 |
62 // 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 |
63 // 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 |
64 // must make a copy and modify the copy. | 64 // must make a copy and modify the copy. |
65 gfx::Image* LookupIconFromFilepath(const base::FilePath& file_name, | 65 gfx::Image* LookupIconFromFilepath(const base::FilePath& file_name, |
66 IconLoader::IconSize size); | 66 IconLoader::IconSize size); |
67 | 67 |
68 typedef base::Callback<void(gfx::Image*)> IconRequestCallback; | 68 typedef base::Callback<void(gfx::Image*)> IconRequestCallback; |
69 | 69 |
70 // Asynchronous call to lookup and return the icon associated with file. The | 70 // Asynchronous call to lookup and return the icon associated with file. The |
71 // work is done on the file thread, with the callbacks running on the thread | 71 // work is done on the file thread, with the callbacks running on the thread |
72 // this function is called. | 72 // this function is called. |
73 // | 73 // |
74 // Note: | 74 // Note: |
75 // 1. This does *not* check the cache. | 75 // 1. This does *not* check the cache. |
76 // 2. The returned bitmap pointer is *not* owned by callback. So callback | 76 // 2. The returned bitmap pointer is *not* owned by callback. So callback |
77 // should never keep it or delete it. | 77 // should never keep it or delete it. |
78 // 3. The gfx::Image pointer passed to the callback may be NULL if decoding | 78 // 3. The gfx::Image pointer passed to the callback may be NULL if decoding |
79 // failed. | 79 // failed. |
80 CancelableTaskTracker::TaskId LoadIcon(const base::FilePath& file_name, | 80 base::CancelableTaskTracker::TaskId LoadIcon( |
81 IconLoader::IconSize size, | 81 const base::FilePath& file_name, |
82 const IconRequestCallback& callback, | 82 IconLoader::IconSize size, |
83 CancelableTaskTracker* tracker); | 83 const IconRequestCallback& callback, |
| 84 base::CancelableTaskTracker* tracker); |
84 | 85 |
85 // IconLoader::Delegate interface. | 86 // IconLoader::Delegate interface. |
86 virtual bool OnGroupLoaded(IconLoader* loader, | 87 virtual bool OnGroupLoaded(IconLoader* loader, |
87 const IconGroupID& group) OVERRIDE; | 88 const IconGroupID& group) OVERRIDE; |
88 virtual bool OnImageLoaded(IconLoader* loader, | 89 virtual bool OnImageLoaded(IconLoader* loader, |
89 gfx::Image* result, | 90 gfx::Image* result, |
90 const IconGroupID& group) OVERRIDE; | 91 const IconGroupID& group) OVERRIDE; |
91 | 92 |
92 private: | 93 private: |
93 struct CacheKey { | 94 struct CacheKey { |
(...skipping 17 matching lines...) Expand all Loading... |
111 | 112 |
112 // Asynchronous requests that have not yet been completed. | 113 // Asynchronous requests that have not yet been completed. |
113 struct ClientRequest; | 114 struct ClientRequest; |
114 typedef std::map<IconLoader*, ClientRequest> ClientRequests; | 115 typedef std::map<IconLoader*, ClientRequest> ClientRequests; |
115 ClientRequests requests_; | 116 ClientRequests requests_; |
116 | 117 |
117 DISALLOW_COPY_AND_ASSIGN(IconManager); | 118 DISALLOW_COPY_AND_ASSIGN(IconManager); |
118 }; | 119 }; |
119 | 120 |
120 #endif // CHROME_BROWSER_ICON_MANAGER_H_ | 121 #endif // CHROME_BROWSER_ICON_MANAGER_H_ |
OLD | NEW |