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

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

Issue 113120: stub impl of linux,mac icon loader/manager (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: style fixes Created 11 years, 7 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 | Annotate | Revision Log
« 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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
11 // 11 //
12 // Windows files have icons associated with them that can be of two types: 12 // Windows files have icons associated with them that can be of two types:
13 // 1. "Per class": the icon used for this file is used for all files with the 13 // 1. "Per class": the icon used for this file is used for all files with the
14 // same file extension or class. Examples are PDF or MP3 files, which use 14 // same file extension or class. Examples are PDF or MP3 files, which use
15 // the same icon for all files of that type. 15 // the same icon for all files of that type.
16 // 2. "Per instance": the icon used for this file is embedded in the file 16 // 2. "Per instance": the icon used for this file is embedded in the file
17 // itself and is unique. Executable files are typically "per instance". 17 // itself and is unique. Executable files are typically "per instance".
18 // 18 //
19 // Files that end in the following extensions are considered "per instance": 19 // Files that end in the following extensions are considered "per instance":
20 // .exe 20 // .exe
21 // .dll 21 // .dll
22 // .ico 22 // .ico
23 // The IconManager will do explicit icon loads on the full path of these files 23 // The IconManager will do explicit icon loads on the full path of these files
24 // and cache the results per file. All other file types will be looked up by 24 // and cache the results per file. All other file types will be looked up by
25 // file extension and the results will be cached per extension. That way, all 25 // file extension and the results will be cached per extension. That way, all
26 // .mp3 files will share one icon, but all .exe files will have their own icon. 26 // .mp3 files will share one icon, but all .exe files will have their own icon.
27 // 27 //
28 // POSIX files don't have associated icons. We query the OS by the file's
29 // mime type.
30 //
28 // The IconManager can be queried in two ways: 31 // The IconManager can be queried in two ways:
29 // 1. A quick, synchronous check of its caches which does not touch the disk: 32 // 1. A quick, synchronous check of its caches which does not touch the disk:
30 // IconManager::LookupIcon() 33 // IconManager::LookupIcon()
31 // 2. An asynchronous icon load from a file on the file thread: 34 // 2. An asynchronous icon load from a file on the file thread:
32 // IconManager::LoadIcon() 35 // IconManager::LoadIcon()
33 // 36 //
34 // When using the second (asychronous) method, callers must supply a callback 37 // When using the second (asychronous) method, callers must supply a callback
35 // which will be run once the icon has been extracted. The icon manager will 38 // which will be run once the icon has been extracted. The icon manager will
36 // cache the results of the icon extraction so that subsequent lookups will be 39 // cache the results of the icon extraction so that subsequent lookups will be
37 // fast. 40 // fast.
38 // 41 //
39 // 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
40 // 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.
41 44
42 #ifndef CHROME_BROWSER_ICON_MANAGER_H_ 45 #ifndef CHROME_BROWSER_ICON_MANAGER_H_
43 #define CHROME_BROWSER_ICON_MANAGER_H_ 46 #define CHROME_BROWSER_ICON_MANAGER_H_
44 47
45 #include <map> 48 #include <map>
46 #include <set> 49 #include <set>
47 #include <string> 50 #include <string>
48 51
49 #include "base/hash_tables.h" 52 #include "base/hash_tables.h"
53 #include "chrome/browser/cancelable_request.h"
50 #include "chrome/browser/icon_loader.h" 54 #include "chrome/browser/icon_loader.h"
51 #include "chrome/browser/cancelable_request.h"
52 55
56 class FilePath;
53 class SkBitmap; 57 class SkBitmap;
54 58
55 class IconManager : public IconLoader::Delegate, 59 class IconManager : public IconLoader::Delegate,
56 public CancelableRequestProvider { 60 public CancelableRequestProvider {
57 public: 61 public:
58 IconManager(); 62 IconManager();
59 ~IconManager(); 63 ~IconManager();
60 64
61 // Synchronous call to examine the internal caches for the icon. Returns the 65 // Synchronous call to examine the internal caches for the icon. Returns the
62 // icon if we have already loaded it, NULL if we don't have it and must load 66 // icon if we have already loaded it, NULL if we don't have it and must load
63 // it via 'LoadIcon'. The returned bitmap is owned by the IconManager and must 67 // it via 'LoadIcon'. The returned bitmap is owned by the IconManager and must
64 // not be free'd by the caller. If the caller needs to modify the icon, it 68 // not be free'd by the caller. If the caller needs to modify the icon, it
65 // must make a copy and modify the copy. 69 // must make a copy and modify the copy.
66 SkBitmap* LookupIcon(const FilePath& file_name, 70 SkBitmap* LookupIcon(const FilePath& file_name,
67 IconLoader::IconSize size); 71 IconLoader::IconSize size);
68 72
69 // Asynchronous call to lookup and return the icon associated with file. The 73 // Asynchronous call to lookup and return the icon associated with file. The
70 // work is done on the file thread, with the callbacks running on the UI 74 // work is done on the file thread, with the callbacks running on the UI
71 // thread. The return value is the 'request_id' that will be passed to the 75 // thread. The return value is the 'request_id' that will be passed to the
72 // client in the callback. 76 // client in the callback.
73 // 77 //
74 // WATCH OUT: The returned bitmap pointer may be NULL if decoding failed. 78 // WATCH OUT: The returned bitmap pointer may be NULL if decoding failed.
75 typedef CancelableRequestProvider::Handle Handle; 79 typedef CancelableRequestProvider::Handle Handle;
76 typedef Callback2<Handle, SkBitmap*>::Type IconRequestCallback; 80 typedef Callback2<Handle, SkBitmap*>::Type IconRequestCallback;
77 81
78 Handle LoadIcon(const FilePath& file_name, 82 Handle LoadIcon(const FilePath& file_name,
79 IconLoader::IconSize size, 83 IconLoader::IconSize size,
80 CancelableRequestConsumerBase* consumer, 84 CancelableRequestConsumerBase* consumer,
81 IconRequestCallback* callback); 85 IconRequestCallback* callback);
82 86
83 // IconLoader::Delegate interface. 87 // IconLoader::Delegate interface.
84 virtual bool OnBitmapLoaded(IconLoader* source, SkBitmap* result); 88 virtual bool OnBitmapLoaded(IconLoader* source, SkBitmap* result);
85 89
86 private: 90 // Get the identifying string for the given file. The implementation
91 // is in icon_manager_[platform].cc.
92 static IconGroupID GetGroupIDFromFilepath(const FilePath& path);
93
94 private:
87 struct CacheKey { 95 struct CacheKey {
88 CacheKey(const FilePath& file_name, IconLoader::IconSize size); 96 CacheKey(const IconGroupID& group, IconLoader::IconSize size);
89 97
90 // Used as a key in the map below, so we need this comparator. 98 // Used as a key in the map below, so we need this comparator.
91 bool operator<(const CacheKey &other) const; 99 bool operator<(const CacheKey &other) const;
92 100
93 FilePath file_name; 101 IconGroupID group;
94 IconLoader::IconSize size; 102 IconLoader::IconSize size;
95 }; 103 };
96 104
97 typedef std::map<CacheKey, SkBitmap*> IconMap; 105 typedef std::map<CacheKey, SkBitmap*> IconMap;
98 IconMap icon_cache_; 106 IconMap icon_cache_;
99 107
100 typedef CancelableRequest<IconRequestCallback> IconRequest; 108 typedef CancelableRequest<IconRequestCallback> IconRequest;
101 typedef struct { 109 typedef struct {
102 scoped_refptr<IconRequest> request; 110 scoped_refptr<IconRequest> request;
103 FilePath file_name; 111 IconGroupID group;
104 IconLoader::IconSize size; 112 IconLoader::IconSize size;
105 } ClientRequest; 113 } ClientRequest;
106 114
107 // Asynchronous requests that have not yet been completed. 115 // Asynchronous requests that have not yet been completed.
108 typedef base::hash_map<IconLoader*, ClientRequest> ClientRequests; 116 typedef std::map<IconLoader*, ClientRequest> ClientRequests;
109 ClientRequests requests_; 117 ClientRequests requests_;
110 118
111 DISALLOW_COPY_AND_ASSIGN(IconManager); 119 DISALLOW_COPY_AND_ASSIGN(IconManager);
112 }; 120 };
113 121
114 #endif // #ifndef CHROME_BROWSER_ICON_MANAGER_H_ 122 #endif // #ifndef 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