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

Unified Diff: chrome/browser/favicon_service.cc

Issue 288005: First fix to minimize copying of image data. (Closed)
Patch Set: Modify gyp Created 11 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/favicon_service.cc
diff --git a/chrome/browser/favicon_service.cc b/chrome/browser/favicon_service.cc
index 937bc08204c43b49f06c044732b0928ed51c902a..4acf7dc8dd07c331c41c008d342ae65bad6baee8 100644
--- a/chrome/browser/favicon_service.cc
+++ b/chrome/browser/favicon_service.cc
@@ -50,12 +50,24 @@ FaviconService::Handle FaviconService::GetFaviconForURL(
AddRequest(request, consumer);
FaviconService::Handle handle = request->handle();
if (page_url.SchemeIs(chrome::kChromeUIScheme)) {
- std::vector<unsigned char> icon_bytes;
+ // TODO(erg): For now, we're cheating here. DOMUIFactory returns the new
+ // RefCountedMemory superclass, but consumers of favicon information are
+ // still all hardcoded to use RefCountedBytes. For now, just copy the
+ // favicon data in this case because the returned RefCountedMemory class is
+ // the statically allocated memory one; not the vector backed
+ // RefCountedBytes.
scoped_refptr<RefCountedBytes> icon_data = NULL;
- bool know_icon = DOMUIFactory::GetFaviconResourceBytes(page_url,
- &icon_bytes);
- if (know_icon)
- icon_data = new RefCountedBytes(icon_bytes);
+ scoped_refptr<RefCountedMemory> static_memory(
+ DOMUIFactory::GetFaviconResourceBytes(page_url));
+ bool know_icon = static_memory.get() != NULL;
+
+ if (know_icon) {
+ std::vector<unsigned char> bytes;
+ bytes.insert(bytes.begin(),
+ static_memory->front(),
+ static_memory->front() + static_memory->size());
+ icon_data = RefCountedBytes::TakeVector(&bytes);
+ }
request->ForwardResultAsync(FaviconDataCallback::TupleType(handle,
know_icon, icon_data, false, GURL()));

Powered by Google App Engine
This is Rietveld 408576698