Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: chrome/browser/icon_manager.h

Issue 11441006: Convert IconManager to use new CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and fix mac compiling Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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/hash_tables.h"
51 #include "chrome/browser/common/cancelable_request.h"
52 #include "chrome/browser/icon_loader.h" 50 #include "chrome/browser/icon_loader.h"
51 #include "chrome/common/cancelable_task_tracker.h"
53 #include "ui/gfx/image/image.h" 52 #include "ui/gfx/image/image.h"
54 53
55 class FilePath; 54 class FilePath;
56 55
57 class IconManager : public IconLoader::Delegate, 56 class IconManager : public IconLoader::Delegate {
58 public CancelableRequestProvider {
59 public: 57 public:
60 IconManager(); 58 IconManager();
61 virtual ~IconManager(); 59 virtual ~IconManager();
62 60
63 // Synchronous call to examine the internal caches for the icon. Returns the 61 // 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 62 // 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 63 // 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 64 // 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. 65 // must make a copy and modify the copy.
68 gfx::Image* LookupIcon(const FilePath& file_name, 66 gfx::Image* LookupIcon(const FilePath& file_name, IconLoader::IconSize size);
69 IconLoader::IconSize size);
70 67
71 typedef CancelableRequestProvider::Handle Handle; 68 typedef base::Callback<void(gfx::Image*)> IconRequestCallback;
72 typedef base::Callback<void(Handle, gfx::Image*)> IconRequestCallback;
73 69
74 // 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
75 // work is done on the file thread, with the callbacks running on the UI 71 // work is done on the file thread, with the callbacks running on the thread
76 // thread. The return value is the 'request_id' that will be passed to the 72 // this function is called.
77 // client in the callback. Note: this does *not* check the cache.
78 // 73 //
79 // WATCH OUT: The returned bitmap pointer may be NULL if decoding failed. 74 // Note:
80 Handle LoadIcon(const FilePath& file_name, 75 // 1. This does *not* check the cache.
81 IconLoader::IconSize size, 76 // 2. The returned bitmap pointer is *not* owned by callback. So callback
82 CancelableRequestConsumerBase* consumer, 77 // should never keep it or delete it.
83 const IconRequestCallback& callback); 78 // 3. The gfx::Image pointer passed to the callback may be NULL if decoding
79 // failed.
80 CancelableTaskTracker::TaskId LoadIcon(const FilePath& file_name,
81 IconLoader::IconSize size,
82 const IconRequestCallback& callback,
83 CancelableTaskTracker* tracker);
84 84
85 // IconLoader::Delegate interface. 85 // IconLoader::Delegate interface.
86 virtual bool OnImageLoaded(IconLoader* source, gfx::Image* result) OVERRIDE; 86 virtual bool OnImageLoaded(IconLoader* loader, gfx::Image* result) OVERRIDE;
87 87
88 // Get the identifying string for the given file. The implementation 88 // Get the identifying string for the given file. The implementation
89 // is in icon_manager_[platform].cc. 89 // is in icon_manager_[platform].cc.
90 static IconGroupID GetGroupIDFromFilepath(const FilePath& path); 90 static IconGroupID GetGroupIDFromFilepath(const FilePath& path);
91 91
92 private: 92 private:
93 struct CacheKey { 93 struct CacheKey {
94 CacheKey(const IconGroupID& group, IconLoader::IconSize size); 94 CacheKey(const IconGroupID& group, IconLoader::IconSize size);
95 95
96 // Used as a key in the map below, so we need this comparator. 96 // Used as a key in the map below, so we need this comparator.
97 bool operator<(const CacheKey &other) const; 97 bool operator<(const CacheKey &other) const;
98 98
99 IconGroupID group; 99 IconGroupID group;
100 IconLoader::IconSize size; 100 IconLoader::IconSize size;
101 }; 101 };
102 102
103 typedef std::map<CacheKey, gfx::Image*> IconMap; 103 typedef std::map<CacheKey, gfx::Image*> IconMap;
104 IconMap icon_cache_; 104 IconMap icon_cache_;
105 105
106 typedef CancelableRequest<IconRequestCallback> IconRequest;
107
108 // Asynchronous requests that have not yet been completed. 106 // Asynchronous requests that have not yet been completed.
109 struct ClientRequest; 107 struct ClientRequest;
110 typedef std::map<IconLoader*, ClientRequest> ClientRequests; 108 typedef std::map<IconLoader*, ClientRequest> ClientRequests;
111 ClientRequests requests_; 109 ClientRequests requests_;
112 110
113 DISALLOW_COPY_AND_ASSIGN(IconManager); 111 DISALLOW_COPY_AND_ASSIGN(IconManager);
114 }; 112 };
115 113
116 #endif // CHROME_BROWSER_ICON_MANAGER_H_ 114 #endif // CHROME_BROWSER_ICON_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | chrome/browser/icon_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698