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

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

Issue 12211049: Removing base::ThreadRestrictions::ScopedAllowIO from icon_manager_linux.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix presubmit. Created 7 years, 8 months 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
« no previous file with comments | « chrome/browser/icon_loader_win.cc ('k') | chrome/browser/icon_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/files/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);
69 67
70 typedef base::Callback<void(gfx::Image*)> IconRequestCallback; 68 typedef base::Callback<void(gfx::Image*)> IconRequestCallback;
71 69
72 // 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
73 // 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
74 // this function is called. 72 // this function is called.
75 // 73 //
76 // Note: 74 // Note:
77 // 1. This does *not* check the cache. 75 // 1. This does *not* check the cache.
78 // 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
79 // should never keep it or delete it. 77 // should never keep it or delete it.
80 // 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
81 // failed. 79 // failed.
82 CancelableTaskTracker::TaskId LoadIcon(const base::FilePath& file_name, 80 CancelableTaskTracker::TaskId LoadIcon(const base::FilePath& file_name,
83 IconLoader::IconSize size, 81 IconLoader::IconSize size,
84 const IconRequestCallback& callback, 82 const IconRequestCallback& callback,
85 CancelableTaskTracker* tracker); 83 CancelableTaskTracker* tracker);
86 84
87 // IconLoader::Delegate interface. 85 // IconLoader::Delegate interface.
88 virtual bool OnImageLoaded(IconLoader* loader, gfx::Image* result) OVERRIDE; 86 virtual bool OnGroupLoaded(IconLoader* loader,
89 87 const IconGroupID& group) OVERRIDE;
90 // Get the identifying string for the given file. The implementation 88 virtual bool OnImageLoaded(IconLoader* loader,
91 // is in icon_manager_[platform].cc. 89 gfx::Image* result,
92 static IconGroupID GetGroupIDFromFilepath(const base::FilePath& path); 90 const IconGroupID& group) OVERRIDE;
93 91
94 private: 92 private:
95 struct CacheKey { 93 struct CacheKey {
96 CacheKey(const IconGroupID& group, IconLoader::IconSize size); 94 CacheKey(const IconGroupID& group, IconLoader::IconSize size);
97 95
98 // 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.
99 bool operator<(const CacheKey &other) const; 97 bool operator<(const CacheKey &other) const;
100 98
101 IconGroupID group; 99 IconGroupID group;
102 IconLoader::IconSize size; 100 IconLoader::IconSize size;
103 }; 101 };
104 102
103 gfx::Image* LookupIconFromGroup(const IconGroupID& group,
104 IconLoader::IconSize size);
105
105 typedef std::map<CacheKey, gfx::Image*> IconMap; 106 typedef std::map<CacheKey, gfx::Image*> IconMap;
106 IconMap icon_cache_; 107 IconMap icon_cache_;
107 108
109 typedef std::map<base::FilePath, IconGroupID> GroupMap;
110 GroupMap group_cache_;
111
108 // Asynchronous requests that have not yet been completed. 112 // Asynchronous requests that have not yet been completed.
109 struct ClientRequest; 113 struct ClientRequest;
110 typedef std::map<IconLoader*, ClientRequest> ClientRequests; 114 typedef std::map<IconLoader*, ClientRequest> ClientRequests;
111 ClientRequests requests_; 115 ClientRequests requests_;
112 116
113 DISALLOW_COPY_AND_ASSIGN(IconManager); 117 DISALLOW_COPY_AND_ASSIGN(IconManager);
114 }; 118 };
115 119
116 #endif // CHROME_BROWSER_ICON_MANAGER_H_ 120 #endif // CHROME_BROWSER_ICON_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/icon_loader_win.cc ('k') | chrome/browser/icon_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698