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

Side by Side Diff: chrome/browser/favicon/favicon_service.cc

Issue 10802066: Adds support for saving favicon size into history database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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/favicon/favicon_service.h" 5 #include "chrome/browser/favicon/favicon_service.h"
6 6
7 #include "chrome/browser/history/history.h" 7 #include "chrome/browser/history/history.h"
8 #include "chrome/browser/history/history_backend.h" 8 #include "chrome/browser/history/history_backend.h"
9 #include "chrome/browser/history/history_service_factory.h" 9 #include "chrome/browser/history/history_service_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 11 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
12 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
13 13
14 FaviconService::FaviconService(Profile* profile) : profile_(profile) { 14 FaviconService::FaviconService(Profile* profile) : profile_(profile) {
15 } 15 }
16 16
17 FaviconService::Handle FaviconService::GetFavicon( 17 FaviconService::Handle FaviconService::GetFavicon(
18 const GURL& icon_url, 18 const GURL& icon_url,
19 history::IconType icon_type, 19 history::IconType icon_type,
20 CancelableRequestConsumerBase* consumer, 20 CancelableRequestConsumerBase* consumer,
21 const FaviconDataCallback& callback) { 21 const FaviconDataCallback& callback) {
22 GetFaviconRequest* request = new GetFaviconRequest(callback); 22 GetFaviconRequest* request = new GetFaviconRequest(callback);
23 AddRequest(request, consumer); 23 AddRequest(request, consumer);
24 HistoryService* hs = 24 HistoryService* hs =
25 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 25 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
26 if (hs) 26 // There should only ever be a single favicon per page URL and
27 hs->GetFavicon(request, icon_url, icon_type); 27 // history::IconType so the returned FaviconData should only have a single
28 else 28 // element.
29 if (hs) {
30 std::vector<GURL> icon_urls;
31 icon_urls.push_back(icon_url);
32 hs->GetFavicons(request, icon_urls, icon_type);
33 } else {
29 ForwardEmptyResultAsync(request); 34 ForwardEmptyResultAsync(request);
35 }
30 return request->handle(); 36 return request->handle();
31 } 37 }
32 38
33 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( 39 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch(
34 const GURL& page_url, 40 const GURL& page_url,
35 const GURL& icon_url, 41 const GURL& icon_url,
36 history::IconType icon_type, 42 history::IconType icon_type,
37 CancelableRequestConsumerBase* consumer, 43 CancelableRequestConsumerBase* consumer,
38 const FaviconDataCallback& callback) { 44 const FaviconDataCallback& callback) {
39 GetFaviconRequest* request = new GetFaviconRequest(callback); 45 GetFaviconRequest* request = new GetFaviconRequest(callback);
40 AddRequest(request, consumer); 46 AddRequest(request, consumer);
41 HistoryService* hs = 47 HistoryService* hs =
42 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 48 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
43 if (hs) 49 if (hs) {
44 hs->UpdateFaviconMappingAndFetch(request, page_url, icon_url, icon_type); 50 std::vector<GURL> icon_urls;
45 else 51 icon_urls.push_back(icon_url);
52 hs->UpdateFaviconMappingsAndFetch(request, page_url, icon_urls, icon_type);
53 } else {
46 ForwardEmptyResultAsync(request); 54 ForwardEmptyResultAsync(request);
55 }
47 return request->handle(); 56 return request->handle();
48 } 57 }
49 58
50 FaviconService::Handle FaviconService::GetFaviconForURL( 59 FaviconService::Handle FaviconService::GetFaviconForURL(
51 const GURL& page_url, 60 const GURL& page_url,
52 int icon_types, 61 int icon_types,
53 CancelableRequestConsumerBase* consumer, 62 CancelableRequestConsumerBase* consumer,
54 const FaviconDataCallback& callback) { 63 const FaviconDataCallback& callback) {
55 GetFaviconRequest* request = new GetFaviconRequest(callback); 64 GetFaviconRequest* request = new GetFaviconRequest(callback);
56 AddRequest(request, consumer); 65 AddRequest(request, consumer);
57 FaviconService::Handle handle = request->handle(); 66 FaviconService::Handle handle = request->handle();
58 if (page_url.SchemeIs(chrome::kChromeUIScheme) || 67 if (page_url.SchemeIs(chrome::kChromeUIScheme) ||
59 page_url.SchemeIs(chrome::kExtensionScheme)) { 68 page_url.SchemeIs(chrome::kExtensionScheme)) {
60 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL( 69 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL(
61 profile_, request, page_url); 70 profile_, request, page_url);
62 } else { 71 } else {
63 HistoryService* hs = HistoryServiceFactory::GetForProfile( 72 HistoryService* hs = HistoryServiceFactory::GetForProfile(
64 profile_, Profile::EXPLICIT_ACCESS); 73 profile_, Profile::EXPLICIT_ACCESS);
65 if (hs) 74 if (hs) {
66 hs->GetFaviconForURL(request, page_url, icon_types); 75 // There should only ever be a single favicon per page URL for icon type
67 else 76 // FAVICON so the returned FaviconData should have a single element.
77 hs->GetFaviconsForURL(request, page_url, icon_types);
78 } else {
68 ForwardEmptyResultAsync(request); 79 ForwardEmptyResultAsync(request);
80 }
69 } 81 }
70 return handle; 82 return handle;
71 } 83 }
72 84
73 // Requests the favicon for |favicon_id|. The |consumer| is notified when the
74 // bits have been fetched.
75 FaviconService::Handle FaviconService::GetFaviconForID(
76 history::FaviconID favicon_id,
77 CancelableRequestConsumerBase* consumer,
78 const FaviconDataCallback& callback) {
79 GetFaviconRequest* request = new GetFaviconRequest(callback);
80 AddRequest(request, consumer);
81 FaviconService::Handle handle = request->handle();
82 HistoryService* hs =
83 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
84 if (hs)
85 hs->GetFaviconForID(request, favicon_id);
86 else
87 ForwardEmptyResultAsync(request);
88
89 return handle;
90 }
91
92
93 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { 85 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) {
94 HistoryService* hs = 86 HistoryService* hs =
95 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 87 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
96 if (hs) 88 if (hs)
97 hs->SetFaviconOutOfDateForPage(page_url); 89 hs->SetFaviconsOutOfDateForPage(page_url);
98 } 90 }
99 91
100 void FaviconService::CloneFavicon(const GURL& old_page_url, 92 void FaviconService::CloneFavicon(const GURL& old_page_url,
101 const GURL& new_page_url) { 93 const GURL& new_page_url) {
102 HistoryService* hs = 94 HistoryService* hs =
103 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 95 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
104 if (hs) 96 if (hs)
105 hs->CloneFavicon(old_page_url, new_page_url); 97 hs->CloneFavicons(old_page_url, new_page_url);
106 } 98 }
107 99
108 void FaviconService::SetImportedFavicons( 100 void FaviconService::SetImportedFavicons(
109 const std::vector<history::ImportedFaviconUsage>& favicon_usage) { 101 const std::vector<history::ImportedFaviconUsage>& favicon_usage) {
110 HistoryService* hs = 102 HistoryService* hs =
111 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 103 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
112 if (hs) 104 if (hs)
113 hs->SetImportedFavicons(favicon_usage); 105 hs->SetImportedFavicons(favicon_usage);
114 } 106 }
115 107
116 void FaviconService::SetFavicon(const GURL& page_url, 108 void FaviconService::SetFavicon(const GURL& page_url,
117 const GURL& icon_url, 109 const GURL& icon_url,
118 const std::vector<unsigned char>& image_data, 110 const std::vector<unsigned char>& image_data,
119 history::IconType icon_type) { 111 history::IconType icon_type) {
120 HistoryService* hs = 112 HistoryService* hs =
121 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 113 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
122 if (hs) 114 if (hs) {
123 hs->SetFavicon(page_url, icon_url, image_data, icon_type); 115 // TODO(pkotwicz): Pass in real pixel size to SetFavicons.
116 history::FaviconDataElement element;
117 element.bitmap_data = scoped_refptr<base::RefCountedMemory>(
118 new base::RefCountedBytes(image_data));
119 element.pixel_size = gfx::Size();
120 element.icon_url = icon_url;
121 std::vector<history::FaviconDataElement> elements;
122 elements.push_back(element);
123 history::IconURLSizesMap icon_url_sizes;
124 icon_url_sizes[icon_url].InsertSize(gfx::Size());
125 hs->SetFavicons(page_url, icon_type, elements, icon_url_sizes);
126 }
124 } 127 }
125 128
126 FaviconService::~FaviconService() { 129 FaviconService::~FaviconService() {
127 } 130 }
128 131
129 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { 132 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) {
130 request->ForwardResultAsync(request->handle(), history::FaviconData()); 133 request->ForwardResultAsync(request->handle(), history::FaviconData());
131 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698