| OLD | NEW |
| 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 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 favicon_url, | 215 favicon_url, |
| 216 history::FAVICON, | 216 history::FAVICON, |
| 217 &cancelable_consumer_, | 217 &cancelable_consumer_, |
| 218 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, | 218 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, |
| 219 base::Unretained(this))); | 219 base::Unretained(this))); |
| 220 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); | 220 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void ExtensionIconSource::OnFaviconDataAvailable( | 223 void ExtensionIconSource::OnFaviconDataAvailable( |
| 224 FaviconService::Handle request_handle, | 224 FaviconService::Handle request_handle, |
| 225 history::FaviconData favicon) { | 225 history::FaviconData favicon_data) { |
| 226 int request_id = cancelable_consumer_.GetClientData( | 226 int request_id = cancelable_consumer_.GetClientData( |
| 227 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), request_handle); | 227 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), request_handle); |
| 228 ExtensionIconRequest* request = GetData(request_id); | 228 ExtensionIconRequest* request = GetData(request_id); |
| 229 | 229 |
| 230 // Fallback to the default icon if there wasn't a favicon. | 230 // Fallback to the default icon if there wasn't a favicon. |
| 231 if (!favicon.is_valid()) { | 231 if (!favicon_data.is_valid()) { |
| 232 LoadDefaultImage(request_id); | 232 LoadDefaultImage(request_id); |
| 233 return; | 233 return; |
| 234 } | 234 } |
| 235 | 235 |
| 236 history::FaviconDataElement element = favicon_data.elements[0]; |
| 236 if (!request->grayscale) { | 237 if (!request->grayscale) { |
| 237 // If we don't need a grayscale image, then we can bypass FinalizeImage | 238 // If we don't need a grayscale image, then we can bypass FinalizeImage |
| 238 // to avoid unnecessary conversions. | 239 // to avoid unnecessary conversions. |
| 239 ClearData(request_id); | 240 ClearData(request_id); |
| 240 SendResponse(request_id, favicon.image_data); | 241 SendResponse(request_id, element.bitmap_data); |
| 241 } else { | 242 } else { |
| 242 FinalizeImage(ToBitmap(favicon.image_data->front(), | 243 FinalizeImage(ToBitmap(element.bitmap_data->front(), |
| 243 favicon.image_data->size()), request_id); | 244 element.bitmap_data->size()), request_id); |
| 244 } | 245 } |
| 245 } | 246 } |
| 246 | 247 |
| 247 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image, | 248 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image, |
| 248 const std::string& extension_id, | 249 const std::string& extension_id, |
| 249 int index) { | 250 int index) { |
| 250 int request_id = tracker_map_[index]; | 251 int request_id = tracker_map_[index]; |
| 251 tracker_map_.erase(tracker_map_.find(index)); | 252 tracker_map_.erase(tracker_map_.find(index)); |
| 252 | 253 |
| 253 if (image.IsEmpty()) | 254 if (image.IsEmpty()) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 339 |
| 339 void ExtensionIconSource::ClearData(int request_id) { | 340 void ExtensionIconSource::ClearData(int request_id) { |
| 340 std::map<int, ExtensionIconRequest*>::iterator i = | 341 std::map<int, ExtensionIconRequest*>::iterator i = |
| 341 request_map_.find(request_id); | 342 request_map_.find(request_id); |
| 342 if (i == request_map_.end()) | 343 if (i == request_map_.end()) |
| 343 return; | 344 return; |
| 344 | 345 |
| 345 delete i->second; | 346 delete i->second; |
| 346 request_map_.erase(i); | 347 request_map_.erase(i); |
| 347 } | 348 } |
| OLD | NEW |