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/favicon_service.h" | 5 #include "chrome/browser/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/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
11 #include "content/browser/webui/web_ui_factory.h" | 11 #include "content/browser/webui/web_ui_factory.h" |
12 | 12 |
| 13 FaviconService::FaviconData::FaviconData() |
| 14 : known_icon(false), |
| 15 expired(false), |
| 16 icon_type(history::INVALID_ICON) { |
| 17 } |
| 18 |
| 19 FaviconService::FaviconData::~FaviconData() { |
| 20 } |
| 21 |
13 FaviconService::FaviconService(Profile* profile) : profile_(profile) { | 22 FaviconService::FaviconService(Profile* profile) : profile_(profile) { |
14 } | 23 } |
15 | 24 |
16 FaviconService::Handle FaviconService::GetFavicon( | 25 FaviconService::Handle FaviconService::GetFavicon( |
17 const GURL& icon_url, | 26 const GURL& icon_url, |
| 27 history::IconType icon_type, |
18 CancelableRequestConsumerBase* consumer, | 28 CancelableRequestConsumerBase* consumer, |
19 FaviconDataCallback* callback) { | 29 FaviconDataCallback* callback) { |
20 GetFaviconRequest* request = new GetFaviconRequest(callback); | 30 GetFaviconRequest* request = new GetFaviconRequest(callback); |
21 AddRequest(request, consumer); | 31 AddRequest(request, consumer); |
22 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 32 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
23 if (hs) | 33 if (hs) |
24 hs->GetFavicon(request, icon_url); | 34 hs->GetFavicon(request, icon_url, icon_type); |
25 else | 35 else |
26 ForwardEmptyResultAsync(request); | 36 ForwardEmptyResultAsync(request); |
27 return request->handle(); | 37 return request->handle(); |
28 } | 38 } |
29 | 39 |
30 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( | 40 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( |
31 const GURL& page_url, | 41 const GURL& page_url, |
32 const GURL& icon_url, | 42 const GURL& icon_url, |
| 43 history::IconType icon_type, |
33 CancelableRequestConsumerBase* consumer, | 44 CancelableRequestConsumerBase* consumer, |
34 FaviconService::FaviconDataCallback* callback) { | 45 FaviconService::FaviconDataCallback* callback) { |
35 GetFaviconRequest* request = new GetFaviconRequest(callback); | 46 GetFaviconRequest* request = new GetFaviconRequest(callback); |
36 AddRequest(request, consumer); | 47 AddRequest(request, consumer); |
37 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 48 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
38 if (hs) | 49 if (hs) |
39 hs->UpdateFaviconMappingAndFetch(request, page_url, icon_url); | 50 hs->UpdateFaviconMappingAndFetch(request, page_url, icon_url, icon_type); |
40 else | 51 else |
41 ForwardEmptyResultAsync(request); | 52 ForwardEmptyResultAsync(request); |
42 return request->handle(); | 53 return request->handle(); |
43 } | 54 } |
44 | 55 |
45 FaviconService::Handle FaviconService::GetFaviconForURL( | 56 FaviconService::Handle FaviconService::GetFaviconForURL( |
46 const GURL& page_url, | 57 const GURL& page_url, |
| 58 int icon_types, |
47 CancelableRequestConsumerBase* consumer, | 59 CancelableRequestConsumerBase* consumer, |
48 FaviconDataCallback* callback) { | 60 FaviconDataCallback* callback) { |
49 GetFaviconRequest* request = new GetFaviconRequest(callback); | 61 GetFaviconRequest* request = new GetFaviconRequest(callback); |
50 AddRequest(request, consumer); | 62 AddRequest(request, consumer); |
51 FaviconService::Handle handle = request->handle(); | 63 FaviconService::Handle handle = request->handle(); |
52 if (page_url.SchemeIs(chrome::kChromeUIScheme) || | 64 if (page_url.SchemeIs(chrome::kChromeUIScheme) || |
53 page_url.SchemeIs(chrome::kExtensionScheme)) { | 65 page_url.SchemeIs(chrome::kExtensionScheme)) { |
54 WebUIFactory::GetFaviconForURL(profile_, request, page_url); | 66 WebUIFactory::GetFaviconForURL(profile_, request, page_url); |
55 } else { | 67 } else { |
56 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 68 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
57 if (hs) | 69 if (hs) |
58 hs->GetFaviconForURL(request, page_url); | 70 hs->GetFaviconForURL(request, page_url, icon_types); |
59 else | 71 else |
60 ForwardEmptyResultAsync(request); | 72 ForwardEmptyResultAsync(request); |
61 } | 73 } |
62 return handle; | 74 return handle; |
63 } | 75 } |
64 | 76 |
65 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { | 77 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { |
66 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 78 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
67 if (hs) | 79 if (hs) |
68 hs->SetFaviconOutOfDateForPage(page_url); | 80 hs->SetFaviconOutOfDateForPage(page_url); |
69 } | 81 } |
70 | 82 |
71 void FaviconService::SetImportedFavicons( | 83 void FaviconService::SetImportedFavicons( |
72 const std::vector<history::ImportedFavIconUsage>& favicon_usage) { | 84 const std::vector<history::ImportedFavIconUsage>& favicon_usage) { |
73 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 85 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
74 if (hs) | 86 if (hs) |
75 hs->SetImportedFavicons(favicon_usage); | 87 hs->SetImportedFavicons(favicon_usage); |
76 } | 88 } |
77 | 89 |
78 void FaviconService::SetFavicon(const GURL& page_url, | 90 void FaviconService::SetFavicon(const GURL& page_url, |
79 const GURL& icon_url, | 91 const GURL& icon_url, |
80 const std::vector<unsigned char>& image_data) { | 92 const std::vector<unsigned char>& image_data, |
| 93 history::IconType icon_type) { |
81 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 94 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
82 if (hs) | 95 if (hs) |
83 hs->SetFavicon(page_url, icon_url, image_data); | 96 hs->SetFavicon(page_url, icon_url, image_data, icon_type); |
84 } | 97 } |
85 | 98 |
86 FaviconService::~FaviconService() { | 99 FaviconService::~FaviconService() { |
87 } | 100 } |
88 | 101 |
89 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { | 102 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { |
90 request->ForwardResultAsync(FaviconDataCallback::TupleType(request->handle(), | 103 request->ForwardResultAsync(FaviconDataCallback::TupleType(request->handle(), |
91 false, NULL, false, GURL())); | 104 FaviconData())); |
92 } | 105 } |
OLD | NEW |