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