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

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

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_manager.h ('k') | chrome/browser/icon_manager_linux.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 #include "chrome/browser/icon_manager.h" 5 #include "chrome/browser/icon_manager.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 12
13 IconManager::IconManager() { 13 IconManager::IconManager() {
14 } 14 }
15 15
16 IconManager::~IconManager() { 16 IconManager::~IconManager() {
17 STLDeleteValues(&icon_cache_); 17 STLDeleteValues(&icon_cache_);
18 } 18 }
19 19
20 SkBitmap* IconManager::LookupIcon(const FilePath& file_name, 20 SkBitmap* IconManager::LookupIcon(const FilePath& file_name,
21 IconLoader::IconSize size) { 21 IconLoader::IconSize size) {
22 FilePath path = file_name; 22 IconGroupID group = GetGroupIDFromFilepath(file_name);
23 FilePath::StringType extension = file_util::GetFileExtensionFromPath(path); 23 IconMap::iterator it = icon_cache_.find(CacheKey(group, size));
24 #if defined(OS_WIN)
25 if (extension != L"exe" && extension != L"dll" && extension != L"ico")
26 path = FilePath(L'.' + extension);
27 #endif
28
29 IconMap::iterator it = icon_cache_.find(CacheKey(path, size));
30 if (it != icon_cache_.end()) 24 if (it != icon_cache_.end())
31 return it->second; 25 return it->second;
32 26
33 return NULL; 27 return NULL;
34 } 28 }
35 29
36 IconManager::Handle IconManager::LoadIcon( 30 IconManager::Handle IconManager::LoadIcon(
37 const FilePath& file_name, 31 const FilePath& file_name,
38 IconLoader::IconSize size, 32 IconLoader::IconSize size,
39 CancelableRequestConsumerBase* consumer, 33 CancelableRequestConsumerBase* consumer,
40 IconRequestCallback* callback) { 34 IconRequestCallback* callback) {
41 FilePath path = file_name; 35 IconGroupID group = GetGroupIDFromFilepath(file_name);
42 FilePath::StringType extension = file_util::GetFileExtensionFromPath(path);
43 #if defined(OS_WIN)
44 if (extension != L"exe" && extension != L"dll" && extension != L"ico")
45 path = FilePath(L'.' + extension);
46 #endif
47
48 IconRequest* request = new IconRequest(callback); 36 IconRequest* request = new IconRequest(callback);
49 AddRequest(request, consumer); 37 AddRequest(request, consumer);
50 38
51 IconLoader* loader = IconLoader::Create(path, size, this); 39 IconLoader* loader = new IconLoader(group, size, this);
52 loader->AddRef(); 40 loader->AddRef();
53 loader->Start(); 41 loader->Start();
54 ClientRequest client_request = { request, path, size }; 42 ClientRequest client_request = { request, group, size };
55 requests_[loader] = client_request; 43 requests_[loader] = client_request;
56 return request->handle(); 44 return request->handle();
57 } 45 }
58 46
59 // IconLoader::Delegate implementation ----------------------------------------- 47 // IconLoader::Delegate implementation -----------------------------------------
60 48
61 bool IconManager::OnBitmapLoaded(IconLoader* source, SkBitmap* result) { 49 bool IconManager::OnBitmapLoaded(IconLoader* source, SkBitmap* result) {
62 ClientRequests::iterator rit = requests_.find(source); 50 ClientRequests::iterator rit = requests_.find(source);
63 // Balances the AddRef() in LoadIcon(). 51 // Balances the AddRef() in LoadIcon().
64 source->Release(); 52 source->Release();
65 53
66 // Look up our client state. 54 // Look up our client state.
67 if (rit == requests_.end()) { 55 if (rit == requests_.end()) {
68 NOTREACHED(); 56 NOTREACHED();
69 return false; // Return false to indicate result should be deleted. 57 return false; // Return false to indicate result should be deleted.
70 } 58 }
71 59
72 ClientRequest client_request = rit->second; 60 ClientRequest client_request = rit->second;
73 if (client_request.request->canceled()) { 61 if (client_request.request->canceled()) {
74 requests_.erase(rit); 62 requests_.erase(rit);
75 return false; // Return false to indicate result should be deleted. 63 return false; // Return false to indicate result should be deleted.
76 } 64 }
77 65
78 // Cache the bitmap. Watch out: |result| or the cached bitmap may be NULL to 66 // Cache the bitmap. Watch out: |result| or the cached bitmap may be NULL to
79 // indicate a current or past failure. 67 // indicate a current or past failure.
80 CacheKey key(client_request.file_name, client_request.size); 68 CacheKey key(client_request.group, client_request.size);
81 IconMap::iterator it = icon_cache_.find(key); 69 IconMap::iterator it = icon_cache_.find(key);
82 if (it != icon_cache_.end() && result && it->second) { 70 if (it != icon_cache_.end() && result && it->second) {
83 it->second->swap(*result); 71 it->second->swap(*result);
84 delete result; 72 delete result;
85 result = it->second; 73 result = it->second;
86 } else { 74 } else {
87 icon_cache_[key] = result; 75 icon_cache_[key] = result;
88 } 76 }
89 77
90 // Inform our client that the request has completed. 78 // Inform our client that the request has completed.
91 IconRequest* icon_request = client_request.request; 79 IconRequest* icon_request = client_request.request;
92 icon_request->ForwardResult(IconRequest::TupleType(icon_request->handle(), 80 icon_request->ForwardResult(IconRequest::TupleType(icon_request->handle(),
93 result)); 81 result));
94 requests_.erase(rit); 82 requests_.erase(rit);
95 83
96 return true; // Indicates we took ownership of result. 84 return true; // Indicates we took ownership of result.
97 } 85 }
98 86
99 IconManager::CacheKey::CacheKey(const FilePath& file_name, 87 IconManager::CacheKey::CacheKey(const IconGroupID& group,
100 IconLoader::IconSize size) 88 IconLoader::IconSize size)
101 : file_name(file_name), 89 : group(group),
102 size(size) { 90 size(size) {
103 } 91 }
104 92
105 bool IconManager::CacheKey::operator<(const CacheKey &other) const { 93 bool IconManager::CacheKey::operator<(const CacheKey &other) const {
106 if (file_name != other.file_name) 94 if (group != other.group)
107 return file_name < other.file_name; 95 return group < other.group;
108 return size < other.size; 96 return size < other.size;
109 } 97 }
OLDNEW
« no previous file with comments | « chrome/browser/icon_manager.h ('k') | chrome/browser/icon_manager_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698