OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/extension_icon_source.h" | 5 #include "chrome/browser/ui/webui/extension_icon_source.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/ref_counted_memory.h" | 8 #include "base/ref_counted_memory.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 FaviconService* favicon_service = | 193 FaviconService* favicon_service = |
194 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 194 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
195 // Fall back to the default icons if the service isn't available. | 195 // Fall back to the default icons if the service isn't available. |
196 if (favicon_service == NULL) { | 196 if (favicon_service == NULL) { |
197 LoadDefaultImage(request_id); | 197 LoadDefaultImage(request_id); |
198 return; | 198 return; |
199 } | 199 } |
200 | 200 |
201 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); | 201 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); |
202 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 202 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
203 favicon_url, &cancelable_consumer_, | 203 favicon_url, |
204 history::FAV_ICON, | |
205 &cancelable_consumer_, | |
204 NewCallback(this, &ExtensionIconSource::OnFaviconDataAvailable)); | 206 NewCallback(this, &ExtensionIconSource::OnFaviconDataAvailable)); |
205 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); | 207 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); |
206 } | 208 } |
207 | 209 |
208 void ExtensionIconSource::OnFaviconDataAvailable( | 210 void ExtensionIconSource::OnFaviconDataAvailable( |
209 FaviconService::Handle request_handle, | 211 FaviconService::Handle request_handle, |
210 bool know_favicon, | 212 FaviconService::FaviconData favicon) { |
211 scoped_refptr<RefCountedMemory> data, | |
212 bool expired, | |
213 GURL icon_url) { | |
214 int request_id = cancelable_consumer_.GetClientData( | 213 int request_id = cancelable_consumer_.GetClientData( |
215 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), request_handle); | 214 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), request_handle); |
216 ExtensionIconRequest* request = GetData(request_id); | 215 ExtensionIconRequest* request = GetData(request_id); |
217 | 216 |
218 // Fallback to the default icon if there wasn't a favicon. | 217 // Fallback to the default icon if there wasn't a favicon. |
219 if (!know_favicon || !data.get() || !data->size()) { | 218 if (!favicon.known_icon || !favicon.image_data.get() || |
219 !favicon.image_data->size()) { | |
sky
2011/03/10 17:54:44
This code is in nearly every callback. Create a me
michaelbai
2011/03/11 01:11:28
Done.
| |
220 LoadDefaultImage(request_id); | 220 LoadDefaultImage(request_id); |
221 return; | 221 return; |
222 } | 222 } |
223 | 223 |
224 if (!request->grayscale) { | 224 if (!request->grayscale) { |
225 // If we don't need a grayscale image, then we can bypass FinalizeImage | 225 // If we don't need a grayscale image, then we can bypass FinalizeImage |
226 // to avoid unnecessary conversions. | 226 // to avoid unnecessary conversions. |
227 ClearData(request_id); | 227 ClearData(request_id); |
228 SendResponse(request_id, data); | 228 SendResponse(request_id, favicon.image_data); |
229 } else { | 229 } else { |
230 FinalizeImage(ToBitmap(data->front(), data->size()), request_id); | 230 FinalizeImage(ToBitmap(favicon.image_data->front(), |
231 favicon.image_data->size()), request_id); | |
231 } | 232 } |
232 } | 233 } |
233 | 234 |
234 void ExtensionIconSource::OnImageLoaded(SkBitmap* image, | 235 void ExtensionIconSource::OnImageLoaded(SkBitmap* image, |
235 ExtensionResource resource, | 236 ExtensionResource resource, |
236 int index) { | 237 int index) { |
237 int request_id = tracker_map_[index]; | 238 int request_id = tracker_map_[index]; |
238 tracker_map_.erase(tracker_map_.find(index)); | 239 tracker_map_.erase(tracker_map_.find(index)); |
239 FinalizeImage(image, request_id); | 240 FinalizeImage(image, request_id); |
240 } | 241 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 | 310 |
310 void ExtensionIconSource::ClearData(int request_id) { | 311 void ExtensionIconSource::ClearData(int request_id) { |
311 std::map<int, ExtensionIconRequest*>::iterator i = | 312 std::map<int, ExtensionIconRequest*>::iterator i = |
312 request_map_.find(request_id); | 313 request_map_.find(request_id); |
313 if (i == request_map_.end()) | 314 if (i == request_map_.end()) |
314 return; | 315 return; |
315 | 316 |
316 delete i->second; | 317 delete i->second; |
317 request_map_.erase(i); | 318 request_map_.erase(i); |
318 } | 319 } |
OLD | NEW |