| OLD | NEW |
| 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/ui/webui/chrome_web_ui_controller_factory.h" | 11 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 11 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 12 | 13 |
| 13 FaviconService::FaviconService(HistoryService* history_service) | 14 FaviconService::FaviconService(Profile* profile) : profile_(profile) { |
| 14 : history_service_(history_service) { | |
| 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 if (history_service_) | 24 HistoryService* hs = |
| 25 history_service_->GetFavicon(request, icon_url, icon_type); | 25 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 26 if (hs) |
| 27 hs->GetFavicon(request, icon_url, icon_type); |
| 26 else | 28 else |
| 27 ForwardEmptyResultAsync(request); | 29 ForwardEmptyResultAsync(request); |
| 28 return request->handle(); | 30 return request->handle(); |
| 29 } | 31 } |
| 30 | 32 |
| 31 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( | 33 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( |
| 32 const GURL& page_url, | 34 const GURL& page_url, |
| 33 const GURL& icon_url, | 35 const GURL& icon_url, |
| 34 history::IconType icon_type, | 36 history::IconType icon_type, |
| 35 CancelableRequestConsumerBase* consumer, | 37 CancelableRequestConsumerBase* consumer, |
| 36 const FaviconDataCallback& callback) { | 38 const FaviconDataCallback& callback) { |
| 37 GetFaviconRequest* request = new GetFaviconRequest(callback); | 39 GetFaviconRequest* request = new GetFaviconRequest(callback); |
| 38 AddRequest(request, consumer); | 40 AddRequest(request, consumer); |
| 39 if (history_service_) | 41 HistoryService* hs = |
| 40 history_service_->UpdateFaviconMappingAndFetch(request, page_url, | 42 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 41 icon_url, icon_type); | 43 if (hs) |
| 44 hs->UpdateFaviconMappingAndFetch(request, page_url, icon_url, icon_type); |
| 42 else | 45 else |
| 43 ForwardEmptyResultAsync(request); | 46 ForwardEmptyResultAsync(request); |
| 44 return request->handle(); | 47 return request->handle(); |
| 45 } | 48 } |
| 46 | 49 |
| 47 FaviconService::Handle FaviconService::GetFaviconForURL( | 50 FaviconService::Handle FaviconService::GetFaviconForURL( |
| 48 Profile* profile, | |
| 49 const GURL& page_url, | 51 const GURL& page_url, |
| 50 int icon_types, | 52 int icon_types, |
| 51 CancelableRequestConsumerBase* consumer, | 53 CancelableRequestConsumerBase* consumer, |
| 52 const FaviconDataCallback& callback) { | 54 const FaviconDataCallback& callback) { |
| 53 GetFaviconRequest* request = new GetFaviconRequest(callback); | 55 GetFaviconRequest* request = new GetFaviconRequest(callback); |
| 54 AddRequest(request, consumer); | 56 AddRequest(request, consumer); |
| 55 FaviconService::Handle handle = request->handle(); | 57 FaviconService::Handle handle = request->handle(); |
| 56 if (page_url.SchemeIs(chrome::kChromeUIScheme) || | 58 if (page_url.SchemeIs(chrome::kChromeUIScheme) || |
| 57 page_url.SchemeIs(chrome::kExtensionScheme)) { | 59 page_url.SchemeIs(chrome::kExtensionScheme)) { |
| 58 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL( | 60 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL( |
| 59 profile, request, page_url); | 61 profile_, request, page_url); |
| 60 } else { | 62 } else { |
| 61 if (history_service_) | 63 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 62 history_service_->GetFaviconForURL(request, page_url, icon_types); | 64 profile_, Profile::EXPLICIT_ACCESS); |
| 65 if (hs) |
| 66 hs->GetFaviconForURL(request, page_url, icon_types); |
| 63 else | 67 else |
| 64 ForwardEmptyResultAsync(request); | 68 ForwardEmptyResultAsync(request); |
| 65 } | 69 } |
| 66 return handle; | 70 return handle; |
| 67 } | 71 } |
| 68 | 72 |
| 69 // Requests the favicon for |favicon_id|. The |consumer| is notified when the | 73 // Requests the favicon for |favicon_id|. The |consumer| is notified when the |
| 70 // bits have been fetched. | 74 // bits have been fetched. |
| 71 FaviconService::Handle FaviconService::GetFaviconForID( | 75 FaviconService::Handle FaviconService::GetFaviconForID( |
| 72 history::FaviconID favicon_id, | 76 history::FaviconID favicon_id, |
| 73 CancelableRequestConsumerBase* consumer, | 77 CancelableRequestConsumerBase* consumer, |
| 74 const FaviconDataCallback& callback) { | 78 const FaviconDataCallback& callback) { |
| 75 GetFaviconRequest* request = new GetFaviconRequest(callback); | 79 GetFaviconRequest* request = new GetFaviconRequest(callback); |
| 76 AddRequest(request, consumer); | 80 AddRequest(request, consumer); |
| 77 FaviconService::Handle handle = request->handle(); | 81 FaviconService::Handle handle = request->handle(); |
| 78 if (history_service_) | 82 HistoryService* hs = |
| 79 history_service_->GetFaviconForID(request, favicon_id); | 83 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 84 if (hs) |
| 85 hs->GetFaviconForID(request, favicon_id); |
| 80 else | 86 else |
| 81 ForwardEmptyResultAsync(request); | 87 ForwardEmptyResultAsync(request); |
| 82 | 88 |
| 83 return handle; | 89 return handle; |
| 84 } | 90 } |
| 85 | 91 |
| 86 | 92 |
| 87 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { | 93 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { |
| 88 if (history_service_) | 94 HistoryService* hs = |
| 89 history_service_->SetFaviconOutOfDateForPage(page_url); | 95 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 96 if (hs) |
| 97 hs->SetFaviconOutOfDateForPage(page_url); |
| 90 } | 98 } |
| 91 | 99 |
| 92 void FaviconService::CloneFavicon(const GURL& old_page_url, | 100 void FaviconService::CloneFavicon(const GURL& old_page_url, |
| 93 const GURL& new_page_url) { | 101 const GURL& new_page_url) { |
| 94 if (history_service_) | 102 HistoryService* hs = |
| 95 history_service_->CloneFavicon(old_page_url, new_page_url); | 103 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 104 if (hs) |
| 105 hs->CloneFavicon(old_page_url, new_page_url); |
| 96 } | 106 } |
| 97 | 107 |
| 98 void FaviconService::SetImportedFavicons( | 108 void FaviconService::SetImportedFavicons( |
| 99 const std::vector<history::ImportedFaviconUsage>& favicon_usage) { | 109 const std::vector<history::ImportedFaviconUsage>& favicon_usage) { |
| 100 if (history_service_) | 110 HistoryService* hs = |
| 101 history_service_->SetImportedFavicons(favicon_usage); | 111 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 112 if (hs) |
| 113 hs->SetImportedFavicons(favicon_usage); |
| 102 } | 114 } |
| 103 | 115 |
| 104 void FaviconService::SetFavicon(const GURL& page_url, | 116 void FaviconService::SetFavicon(const GURL& page_url, |
| 105 const GURL& icon_url, | 117 const GURL& icon_url, |
| 106 const std::vector<unsigned char>& image_data, | 118 const std::vector<unsigned char>& image_data, |
| 107 history::IconType icon_type) { | 119 history::IconType icon_type) { |
| 108 if (history_service_) | 120 HistoryService* hs = |
| 109 history_service_->SetFavicon(page_url, icon_url, image_data, icon_type); | 121 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 122 if (hs) |
| 123 hs->SetFavicon(page_url, icon_url, image_data, icon_type); |
| 110 } | 124 } |
| 111 | 125 |
| 112 FaviconService::~FaviconService() { | 126 FaviconService::~FaviconService() { |
| 113 } | 127 } |
| 114 | 128 |
| 115 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { | 129 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { |
| 116 request->ForwardResultAsync(request->handle(), history::FaviconData()); | 130 request->ForwardResultAsync(request->handle(), history::FaviconData()); |
| 117 } | 131 } |
| OLD | NEW |