diff options
author | arv@google.com <arv@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 21:56:48 +0000 |
---|---|---|
committer | arv@google.com <arv@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 21:56:48 +0000 |
commit | 0189bc72c90fab03afab623d0b2d8be3d35af3e7 (patch) | |
tree | a1962c2ecddcaf1eb1f1a27f6dde6991d19a9b07 /chrome/browser/favicon_service.cc | |
parent | 34a6418e00deca16a311b331ab4b2f257c674d74 (diff) | |
download | chromium_src-0189bc72c90fab03afab623d0b2d8be3d35af3e7.zip chromium_src-0189bc72c90fab03afab623d0b2d8be3d35af3e7.tar.gz chromium_src-0189bc72c90fab03afab623d0b2d8be3d35af3e7.tar.bz2 |
Adds a FaviconService class tied to the profile.
Original issue: http://codereview.chromium.org/115212/show
The favicons service is the entry point to getting favicons.
Make the DOMUIFactory handle the favicons of DOMUI pages so since DOMUI pages
are never added to the history.
BUG=5840
TEST=Open a new window and open history and downloads (Ctrl+H and Ctrl+J) in
this window. Then close the window and open the NTP. The recently closed
windows/tabs should show the favicons for the hsitroy and downloads page.
Review URL: http://codereview.chromium.org/178001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/favicon_service.cc')
-rw-r--r-- | chrome/browser/favicon_service.cc | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/chrome/browser/favicon_service.cc b/chrome/browser/favicon_service.cc new file mode 100644 index 0000000..937bc08 --- /dev/null +++ b/chrome/browser/favicon_service.cc @@ -0,0 +1,96 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/favicon_service.h" + +#include "chrome/browser/dom_ui/dom_ui_factory.h" +#include "chrome/browser/history/history.h" +#include "chrome/browser/history/history_backend.h" +#include "chrome/browser/profile.h" +#include "chrome/common/url_constants.h" + +FaviconService::FaviconService(Profile* profile) : profile_(profile) { +} + +FaviconService::Handle FaviconService::GetFavicon( + const GURL& icon_url, + CancelableRequestConsumerBase* consumer, + FaviconDataCallback* callback) { + GetFaviconRequest* request = new GetFaviconRequest(callback); + AddRequest(request, consumer); + HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); + if (hs) + hs->GetFavicon(request, icon_url); + else + ForwardEmptyResultAsync(request); + return request->handle(); +} + +FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( + const GURL& page_url, + const GURL& icon_url, + CancelableRequestConsumerBase* consumer, + FaviconService::FaviconDataCallback* callback) { + GetFaviconRequest* request = new GetFaviconRequest(callback); + AddRequest(request, consumer); + HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); + if (hs) + hs->UpdateFaviconMappingAndFetch(request, page_url, icon_url); + else + ForwardEmptyResultAsync(request); + return request->handle(); +} + +FaviconService::Handle FaviconService::GetFaviconForURL( + const GURL& page_url, + CancelableRequestConsumerBase* consumer, + FaviconDataCallback* callback) { + GetFaviconRequest* request = new GetFaviconRequest(callback); + AddRequest(request, consumer); + FaviconService::Handle handle = request->handle(); + if (page_url.SchemeIs(chrome::kChromeUIScheme)) { + std::vector<unsigned char> icon_bytes; + scoped_refptr<RefCountedBytes> icon_data = NULL; + bool know_icon = DOMUIFactory::GetFaviconResourceBytes(page_url, + &icon_bytes); + if (know_icon) + icon_data = new RefCountedBytes(icon_bytes); + + request->ForwardResultAsync(FaviconDataCallback::TupleType(handle, + know_icon, icon_data, false, GURL())); + } else { + HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); + if (hs) + hs->GetFaviconForURL(request, page_url); + else + ForwardEmptyResultAsync(request); + } + return handle; +} + +void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { + HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); + if (hs) + hs->SetFaviconOutOfDateForPage(page_url); +} + +void FaviconService::SetImportedFavicons( + const std::vector<history::ImportedFavIconUsage>& favicon_usage) { + HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); + if (hs) + hs->SetImportedFavicons(favicon_usage); +} + +void FaviconService::SetFavicon(const GURL& page_url, + const GURL& icon_url, + const std::vector<unsigned char>& image_data) { + HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); + if (hs) + hs->SetFavicon(page_url, icon_url, image_data); +} + +void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { + request->ForwardResultAsync(FaviconDataCallback::TupleType(request->handle(), + false, NULL, false, GURL())); +} |