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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/favicon_service.h" 5 #include "chrome/browser/favicon_service.h"
6 6
7 #include "chrome/browser/dom_ui/dom_ui_factory.h" 7 #include "chrome/browser/dom_ui/dom_ui_factory.h"
8 #include "chrome/browser/history/history.h" 8 #include "chrome/browser/history/history.h"
9 #include "chrome/browser/history/history_backend.h" 9 #include "chrome/browser/history/history_backend.h"
10 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } 43 }
44 44
45 FaviconService::Handle FaviconService::GetFaviconForURL( 45 FaviconService::Handle FaviconService::GetFaviconForURL(
46 const GURL& page_url, 46 const GURL& page_url,
47 CancelableRequestConsumerBase* consumer, 47 CancelableRequestConsumerBase* consumer,
48 FaviconDataCallback* callback) { 48 FaviconDataCallback* callback) {
49 GetFaviconRequest* request = new GetFaviconRequest(callback); 49 GetFaviconRequest* request = new GetFaviconRequest(callback);
50 AddRequest(request, consumer); 50 AddRequest(request, consumer);
51 FaviconService::Handle handle = request->handle(); 51 FaviconService::Handle handle = request->handle();
52 if (page_url.SchemeIs(chrome::kChromeUIScheme)) { 52 if (page_url.SchemeIs(chrome::kChromeUIScheme)) {
53 std::vector<unsigned char> icon_bytes; 53 // TODO(erg): For now, we're cheating here. DOMUIFactory returns the new
54 // RefCountedMemory superclass, but consumers of favicon information are
55 // still all hardcoded to use RefCountedBytes. For now, just copy the
56 // favicon data in this case because the returned RefCountedMemory class is
57 // the statically allocated memory one; not the vector backed
58 // RefCountedBytes.
54 scoped_refptr<RefCountedBytes> icon_data = NULL; 59 scoped_refptr<RefCountedBytes> icon_data = NULL;
55 bool know_icon = DOMUIFactory::GetFaviconResourceBytes(page_url, 60 scoped_refptr<RefCountedMemory> static_memory(
56 &icon_bytes); 61 DOMUIFactory::GetFaviconResourceBytes(page_url));
57 if (know_icon) 62 bool know_icon = static_memory.get() != NULL;
58 icon_data = new RefCountedBytes(icon_bytes); 63
64 if (know_icon) {
65 std::vector<unsigned char> bytes;
66 bytes.insert(bytes.begin(),
67 static_memory->front(),
68 static_memory->front() + static_memory->size());
69 icon_data = RefCountedBytes::TakeVector(&bytes);
70 }
59 71
60 request->ForwardResultAsync(FaviconDataCallback::TupleType(handle, 72 request->ForwardResultAsync(FaviconDataCallback::TupleType(handle,
61 know_icon, icon_data, false, GURL())); 73 know_icon, icon_data, false, GURL()));
62 } else { 74 } else {
63 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 75 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
64 if (hs) 76 if (hs)
65 hs->GetFaviconForURL(request, page_url); 77 hs->GetFaviconForURL(request, page_url);
66 else 78 else
67 ForwardEmptyResultAsync(request); 79 ForwardEmptyResultAsync(request);
68 } 80 }
(...skipping 18 matching lines...) Expand all
87 const std::vector<unsigned char>& image_data) { 99 const std::vector<unsigned char>& image_data) {
88 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 100 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
89 if (hs) 101 if (hs)
90 hs->SetFavicon(page_url, icon_url, image_data); 102 hs->SetFavicon(page_url, icon_url, image_data);
91 } 103 }
92 104
93 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { 105 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) {
94 request->ForwardResultAsync(FaviconDataCallback::TupleType(request->handle(), 106 request->ForwardResultAsync(FaviconDataCallback::TupleType(request->handle(),
95 false, NULL, false, GURL())); 107 false, NULL, false, GURL()));
96 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698