| 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 history::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.is_valid()) { |
| 220 LoadDefaultImage(request_id); | 219 LoadDefaultImage(request_id); |
| 221 return; | 220 return; |
| 222 } | 221 } |
| 223 | 222 |
| 224 if (!request->grayscale) { | 223 if (!request->grayscale) { |
| 225 // If we don't need a grayscale image, then we can bypass FinalizeImage | 224 // If we don't need a grayscale image, then we can bypass FinalizeImage |
| 226 // to avoid unnecessary conversions. | 225 // to avoid unnecessary conversions. |
| 227 ClearData(request_id); | 226 ClearData(request_id); |
| 228 SendResponse(request_id, data); | 227 SendResponse(request_id, favicon.image_data); |
| 229 } else { | 228 } else { |
| 230 FinalizeImage(ToBitmap(data->front(), data->size()), request_id); | 229 FinalizeImage(ToBitmap(favicon.image_data->front(), |
| 230 favicon.image_data->size()), request_id); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 void ExtensionIconSource::OnImageLoaded(SkBitmap* image, | 234 void ExtensionIconSource::OnImageLoaded(SkBitmap* image, |
| 235 ExtensionResource resource, | 235 ExtensionResource resource, |
| 236 int index) { | 236 int index) { |
| 237 int request_id = tracker_map_[index]; | 237 int request_id = tracker_map_[index]; |
| 238 tracker_map_.erase(tracker_map_.find(index)); | 238 tracker_map_.erase(tracker_map_.find(index)); |
| 239 FinalizeImage(image, request_id); | 239 FinalizeImage(image, request_id); |
| 240 } | 240 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 309 |
| 310 void ExtensionIconSource::ClearData(int request_id) { | 310 void ExtensionIconSource::ClearData(int request_id) { |
| 311 std::map<int, ExtensionIconRequest*>::iterator i = | 311 std::map<int, ExtensionIconRequest*>::iterator i = |
| 312 request_map_.find(request_id); | 312 request_map_.find(request_id); |
| 313 if (i == request_map_.end()) | 313 if (i == request_map_.end()) |
| 314 return; | 314 return; |
| 315 | 315 |
| 316 delete i->second; | 316 delete i->second; |
| 317 request_map_.erase(i); | 317 request_map_.erase(i); |
| 318 } | 318 } |
| OLD | NEW |