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
3 // found in the LICENSE file.
5 #include "chrome/browser/favicon/favicon_service.h"
7 #include "chrome/browser/history/history.h"
8 #include "chrome/browser/history/history_backend.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
11 #include "chrome/common/url_constants.h"
13 FaviconService::FaviconService(Profile
* profile
) : profile_(profile
) {
16 FaviconService::Handle
FaviconService::GetFavicon(
18 history::IconType icon_type
,
19 CancelableRequestConsumerBase
* consumer
,
20 const FaviconDataCallback
& callback
) {
21 GetFaviconRequest
* request
= new GetFaviconRequest(callback
);
22 AddRequest(request
, consumer
);
23 HistoryService
* hs
= profile_
->GetHistoryService(Profile::EXPLICIT_ACCESS
);
25 hs
->GetFavicon(request
, icon_url
, icon_type
);
27 ForwardEmptyResultAsync(request
);
28 return request
->handle();
31 FaviconService::Handle
FaviconService::UpdateFaviconMappingAndFetch(
34 history::IconType icon_type
,
35 CancelableRequestConsumerBase
* consumer
,
36 const FaviconDataCallback
& callback
) {
37 GetFaviconRequest
* request
= new GetFaviconRequest(callback
);
38 AddRequest(request
, consumer
);
39 HistoryService
* hs
= profile_
->GetHistoryService(Profile::EXPLICIT_ACCESS
);
41 hs
->UpdateFaviconMappingAndFetch(request
, page_url
, icon_url
, icon_type
);
43 ForwardEmptyResultAsync(request
);
44 return request
->handle();
47 FaviconService::Handle
FaviconService::GetFaviconForURL(
50 CancelableRequestConsumerBase
* consumer
,
51 const FaviconDataCallback
& callback
) {
52 GetFaviconRequest
* request
= new GetFaviconRequest(callback
);
53 AddRequest(request
, consumer
);
54 FaviconService::Handle handle
= request
->handle();
55 if (page_url
.SchemeIs(chrome::kChromeUIScheme
) ||
56 page_url
.SchemeIs(chrome::kExtensionScheme
)) {
57 ChromeWebUIFactory::GetInstance()->GetFaviconForURL(
58 profile_
, request
, page_url
);
60 HistoryService
* hs
= profile_
->GetHistoryService(Profile::EXPLICIT_ACCESS
);
62 hs
->GetFaviconForURL(request
, page_url
, icon_types
);
64 ForwardEmptyResultAsync(request
);
69 void FaviconService::SetFaviconOutOfDateForPage(const GURL
& page_url
) {
70 HistoryService
* hs
= profile_
->GetHistoryService(Profile::EXPLICIT_ACCESS
);
72 hs
->SetFaviconOutOfDateForPage(page_url
);
75 void FaviconService::CloneFavicon(const GURL
& old_page_url
,
76 const GURL
& new_page_url
) {
77 HistoryService
* hs
= profile_
->GetHistoryService(Profile::EXPLICIT_ACCESS
);
79 hs
->CloneFavicon(old_page_url
, new_page_url
);
82 void FaviconService::SetImportedFavicons(
83 const std::vector
<history::ImportedFaviconUsage
>& favicon_usage
) {
84 HistoryService
* hs
= profile_
->GetHistoryService(Profile::EXPLICIT_ACCESS
);
86 hs
->SetImportedFavicons(favicon_usage
);
89 void FaviconService::SetFavicon(const GURL
& page_url
,
91 const std::vector
<unsigned char>& image_data
,
92 history::IconType icon_type
) {
93 HistoryService
* hs
= profile_
->GetHistoryService(Profile::EXPLICIT_ACCESS
);
95 hs
->SetFavicon(page_url
, icon_url
, image_data
, icon_type
);
98 FaviconService::~FaviconService() {
101 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest
* request
) {
102 request
->ForwardResultAsync(request
->handle(), history::FaviconData());