diff options
Diffstat (limited to 'chrome')
32 files changed, 464 insertions, 176 deletions
diff --git a/chrome/browser/automation/automation_profile_impl.h b/chrome/browser/automation/automation_profile_impl.h index 9f4299d..c0f2592 100644 --- a/chrome/browser/automation/automation_profile_impl.h +++ b/chrome/browser/automation/automation_profile_impl.h @@ -69,6 +69,9 @@ class AutomationProfileImpl : public Profile { virtual net::ForceTLSState* GetForceTLSState() { return original_profile_->GetForceTLSState(); } + virtual FaviconService* GetFaviconService(ServiceAccessType access) { + return original_profile_->GetFaviconService(access); + } virtual HistoryService* GetHistoryService(ServiceAccessType access) { return original_profile_->GetHistoryService(access); } diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index 5bb5bb9..4769f90 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -632,7 +632,7 @@ BookmarkNode* BookmarkModel::CreateRootNodeFromStarredEntry( } void BookmarkModel::OnFavIconDataAvailable( - HistoryService::Handle handle, + FaviconService::Handle handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, @@ -640,7 +640,7 @@ void BookmarkModel::OnFavIconDataAvailable( SkBitmap fav_icon; BookmarkNode* node = load_consumer_.GetClientData( - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS), handle); + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle); DCHECK(node); node->set_favicon_load_handle(0); if (know_favicon && data.get() && @@ -655,24 +655,23 @@ void BookmarkModel::LoadFavIcon(BookmarkNode* node) { return; DCHECK(node->GetURL().is_valid()); - HistoryService* history_service = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (!history_service) + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + if (!favicon_service) return; - - HistoryService::Handle handle = history_service->GetFavIconForURL( + FaviconService::Handle handle = favicon_service->GetFaviconForURL( node->GetURL(), &load_consumer_, NewCallback(this, &BookmarkModel::OnFavIconDataAvailable)); - load_consumer_.SetClientData(history_service, handle, node); + load_consumer_.SetClientData(favicon_service, handle, node); node->set_favicon_load_handle(handle); } void BookmarkModel::CancelPendingFavIconLoadRequests(BookmarkNode* node) { if (node->favicon_load_handle()) { - HistoryService* history = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (history) - history->CancelRequest(node->favicon_load_handle()); + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + if (favicon_service) + favicon_service->CancelRequest(node->favicon_load_handle()); node->set_favicon_load_handle(0); } } diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h index 8da3bcd..3ff1533 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -19,6 +19,7 @@ #include "chrome/browser/bookmarks/bookmark_storage.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/cancelable_request.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_types.h" #include "chrome/common/notification_registrar.h" @@ -367,14 +368,14 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { // Notification that a favicon has finished loading. If we can decode the // favicon, FaviconLoaded is invoked. void OnFavIconDataAvailable( - HistoryService::Handle handle, + FaviconService::Handle handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, GURL icon_url); // Invoked from the node to load the favicon. Requests the favicon from the - // history service. + // favicon service. void LoadFavIcon(BookmarkNode* node); // If we're waiting on a favicon for node, the load request is canceled. diff --git a/chrome/browser/cancelable_request.h b/chrome/browser/cancelable_request.h index 713440e..80e4afc 100644 --- a/chrome/browser/cancelable_request.h +++ b/chrome/browser/cancelable_request.h @@ -494,6 +494,15 @@ class CancelableRequest : public CancelableRequestBase { } } + // Like |ForwardResult| but this never does a synchronous callback. + void ForwardResultAsync(const TupleType& param) { + DCHECK(callback_.get()); + if (!canceled()) { + callback_thread_->PostTask(FROM_HERE, NewRunnableMethod(this, + &CancelableRequest<CB>::ExecuteCallback, param)); + } + } + private: // Executes the callback and notifies the provider and the consumer that this // request has been completed. This must be called on the callback_thread_. diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc index 8b5a1c2..f776baa 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.cc +++ b/chrome/browser/dom_ui/dom_ui_factory.cc @@ -137,3 +137,18 @@ DOMUI* DOMUIFactory::CreateDOMUIForURL(TabContents* tab_contents, return NULL; return dom_ui; } + +// static +bool DOMUIFactory::GetFaviconResourceBytes(const GURL& page_url, + std::vector<unsigned char>* bytes) { + if (!HasDOMUIScheme(page_url)) + return false; + + if (page_url.host() == chrome::kChromeUIHistoryHost) + return HistoryUI::GetFaviconResourceBytes(bytes); + + if (page_url.host() == chrome::kChromeUIDownloadsHost) + return DownloadsUI::GetFaviconResourceBytes(bytes); + + return false; +} diff --git a/chrome/browser/dom_ui/dom_ui_factory.h b/chrome/browser/dom_ui/dom_ui_factory.h index 8644f64..e4e36c3 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.h +++ b/chrome/browser/dom_ui/dom_ui_factory.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_DOM_UI_DOM_UI_FACTORY_H_ #define CHROME_BROWSER_DOM_UI_DOM_UI_FACTORY_H_ +#include <vector> + class DOMUI; class GURL; class TabContents; @@ -25,6 +27,11 @@ class DOMUIFactory { // the returned pointer is passed to the caller. static DOMUI* CreateDOMUIForURL(TabContents* tab_contents, const GURL& url); + // Gets the data for the favicon for a DOMUI page. Returns false if the DOMUI + // does not have a favicon. + static bool GetFaviconResourceBytes(const GURL& page_url, + std::vector<unsigned char>* bytes); + private: // Class is for scoping only. DOMUIFactory() {}; diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.cc b/chrome/browser/dom_ui/dom_ui_favicon_source.cc index bb7b9f0..d117b784 100644 --- a/chrome/browser/dom_ui/dom_ui_favicon_source.cc +++ b/chrome/browser/dom_ui/dom_ui_favicon_source.cc @@ -16,36 +16,38 @@ DOMUIFavIconSource::DOMUIFavIconSource(Profile* profile) void DOMUIFavIconSource::StartDataRequest(const std::string& path, int request_id) { - HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (hs) { - HistoryService::Handle handle; + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + if (favicon_service) { + FaviconService::Handle handle; if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { - handle = hs->GetFavIcon( + handle = favicon_service->GetFavicon( GURL(path.substr(8)), &cancelable_consumer_, NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); } else { - handle = hs->GetFavIconForURL( + handle = favicon_service->GetFaviconForURL( GURL(path), &cancelable_consumer_, NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); } // Attach the ChromeURLDataManager request ID to the history request. - cancelable_consumer_.SetClientData(hs, handle, request_id); + cancelable_consumer_.SetClientData(favicon_service, handle, request_id); } else { SendResponse(request_id, NULL); } } void DOMUIFavIconSource::OnFavIconDataAvailable( - HistoryService::Handle request_handle, + FaviconService::Handle request_handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, GURL icon_url) { - HistoryService* hs = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - int request_id = cancelable_consumer_.GetClientData(hs, request_handle); + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + int request_id = cancelable_consumer_.GetClientData(favicon_service, + request_handle); if (know_favicon && data.get() && !data->data.empty()) { // Forward the data along to the networking system. diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.h b/chrome/browser/dom_ui/dom_ui_favicon_source.h index 42d770c..5e53754 100644 --- a/chrome/browser/dom_ui/dom_ui_favicon_source.h +++ b/chrome/browser/dom_ui/dom_ui_favicon_source.h @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" -#include "chrome/browser/history/history.h" +#include "chrome/browser/favicon_service.h" class GURL; class Profile; @@ -33,7 +33,7 @@ class DOMUIFavIconSource : public ChromeURLDataManager::DataSource { } // Called when favicon data is available from the history backend. - void OnFavIconDataAvailable(HistoryService::Handle request_handle, + void OnFavIconDataAvailable(FaviconService::Handle request_handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc index 5ef1d0d..deb5ef1 100644 --- a/chrome/browser/dom_ui/downloads_ui.cc +++ b/chrome/browser/dom_ui/downloads_ui.cc @@ -18,6 +18,7 @@ #include "chrome/common/url_constants.h" #include "grit/browser_resources.h" #include "grit/generated_resources.h" +#include "grit/theme_resources.h" #if defined(OS_WIN) // TODO(port): re-enable when download_util is ported @@ -136,3 +137,9 @@ DownloadsUI::DownloadsUI(TabContents* contents) : DOMUI(contents) { &ChromeURLDataManager::AddDataSource, html_source)); } + +// static +bool DownloadsUI::GetFaviconResourceBytes(std::vector<unsigned char>* bytes) { + return ResourceBundle::GetSharedInstance(). + LoadImageResourceBytes(IDR_DOWNLOADS_FAVICON, bytes); +} diff --git a/chrome/browser/dom_ui/downloads_ui.h b/chrome/browser/dom_ui/downloads_ui.h index a24e07b..c7ebcdb 100644 --- a/chrome/browser/dom_ui/downloads_ui.h +++ b/chrome/browser/dom_ui/downloads_ui.h @@ -5,12 +5,16 @@ #ifndef CHROME_BROWSER_DOM_UI_DOWNLOADS_UI_H_ #define CHROME_BROWSER_DOM_UI_DOWNLOADS_UI_H_ +#include <vector> + #include "chrome/browser/dom_ui/dom_ui.h" class DownloadsUI : public DOMUI { public: explicit DownloadsUI(TabContents* contents); + static bool GetFaviconResourceBytes(std::vector<unsigned char>* bytes); + private: DISALLOW_COPY_AND_ASSIGN(DownloadsUI); }; diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc index 62e2e5d..c3eb8ad 100644 --- a/chrome/browser/dom_ui/history_ui.cc +++ b/chrome/browser/dom_ui/history_ui.cc @@ -29,6 +29,7 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" +#include "grit/theme_resources.h" // Maximum number of search results to return in a given search. We should // eventually remove this. @@ -377,3 +378,9 @@ const GURL HistoryUI::GetHistoryURLWithSearchText(const std::wstring& text) { return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + EscapeQueryParamValue(WideToUTF8(text))); } + +// static +bool HistoryUI::GetFaviconResourceBytes(std::vector<unsigned char>* bytes) { + return ResourceBundle::GetSharedInstance(). + LoadImageResourceBytes(IDR_HISTORY_FAVICON, bytes); +} diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h index 0a47120..48b055b 100644 --- a/chrome/browser/dom_ui/history_ui.h +++ b/chrome/browser/dom_ui/history_ui.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_DOM_UI_HISTORY_UI_H_ #define CHROME_BROWSER_DOM_UI_HISTORY_UI_H_ +#include <vector> + #include "base/scoped_ptr.h" #include "chrome/browser/browsing_data_remover.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" @@ -93,6 +95,8 @@ class HistoryUI : public DOMUI { // Return the URL for a given search term. static const GURL GetHistoryURLWithSearchText(const std::wstring& text); + static bool GetFaviconResourceBytes(std::vector<unsigned char>* bytes); + private: DISALLOW_COPY_AND_ASSIGN(HistoryUI); }; diff --git a/chrome/browser/fav_icon_helper.cc b/chrome/browser/fav_icon_helper.cc index 564c262..991376c 100644 --- a/chrome/browser/fav_icon_helper.cc +++ b/chrome/browser/fav_icon_helper.cc @@ -34,8 +34,8 @@ void FavIconHelper::FetchFavIcon(const GURL& url) { // Request the favicon from the history service. In parallel to this the // renderer is going to notify us (well TabContents) when the favicon url is // available. - if (GetHistoryService()) { - GetHistoryService()->GetFavIconForURL(url_, &cancelable_consumer_, + if (GetFaviconService()) { + GetFaviconService()->GetFaviconForURL(url_, &cancelable_consumer_, NewCallback(this, &FavIconHelper::OnFavIconDataForInitialURL)); } } @@ -44,8 +44,8 @@ Profile* FavIconHelper::profile() { return tab_contents_->profile(); } -HistoryService* FavIconHelper::GetHistoryService() { - return profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); +FaviconService* FavIconHelper::GetFaviconService() { + return profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); } void FavIconHelper::SetFavIcon( @@ -63,10 +63,10 @@ void FavIconHelper::SetFavIcon( (image.width() == kFavIconSize && image.height() == kFavIconSize) ? image : ConvertToFavIconSize(image); - if (GetHistoryService() && !profile()->IsOffTheRecord()) { + if (GetFaviconService() && !profile()->IsOffTheRecord()) { std::vector<unsigned char> image_data; PNGEncoder::EncodeBGRASkBitmap(sized_image, false, &image_data); - GetHistoryService()->SetFavIcon(i->second.url, i->second.fav_icon_url, + GetFaviconService()->SetFavicon(i->second.url, i->second.fav_icon_url, image_data); } @@ -113,7 +113,7 @@ void FavIconHelper::UpdateFavIconURL(RenderViewHost* render_view_host, got_fav_icon_url_ = true; - if (!GetHistoryService()) + if (!GetFaviconService()) return; if (!fav_icon_expired_ && entry->favicon().is_valid() && @@ -151,7 +151,7 @@ NavigationEntry* FavIconHelper::GetEntry() { } void FavIconHelper::OnFavIconDataForInitialURL( - HistoryService::Handle handle, + FaviconService::Handle handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, @@ -197,12 +197,12 @@ void FavIconHelper::DownloadFavIconOrAskHistory(NavigationEntry* entry) { if (fav_icon_expired_) { // We have the mapping, but the favicon is out of date. Download it now. ScheduleDownload(entry); - } else if (GetHistoryService()) { + } else if (GetFaviconService()) { // We don't know the favicon, but we may have previously downloaded the // favicon for another page that shares the same favicon. Ask for the // favicon given the favicon URL. if (profile()->IsOffTheRecord()) { - GetHistoryService()->GetFavIcon( + GetFaviconService()->GetFavicon( entry->favicon().url(), &cancelable_consumer_, NewCallback(this, &FavIconHelper::OnFavIconData)); @@ -213,7 +213,7 @@ void FavIconHelper::DownloadFavIconOrAskHistory(NavigationEntry* entry) { // include the mapping between the page url and the favicon url. // This is asynchronous. The history service will call back when done. // Issue the request and associate the current page ID with it. - GetHistoryService()->UpdateFavIconMappingAndFetch( + GetFaviconService()->UpdateFaviconMappingAndFetch( entry->url(), entry->favicon().url(), &cancelable_consumer_, NewCallback(this, &FavIconHelper::OnFavIconData)); @@ -222,7 +222,7 @@ void FavIconHelper::DownloadFavIconOrAskHistory(NavigationEntry* entry) { } void FavIconHelper::OnFavIconData( - HistoryService::Handle handle, + FaviconService::Handle handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, diff --git a/chrome/browser/fav_icon_helper.h b/chrome/browser/fav_icon_helper.h index adbcaf0..b2d53ee 100644 --- a/chrome/browser/fav_icon_helper.h +++ b/chrome/browser/fav_icon_helper.h @@ -11,7 +11,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "chrome/browser/cancelable_request.h" -#include "chrome/browser/history/history.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/common/ref_counted_util.h" #include "googleurl/src/gurl.h" @@ -23,7 +23,8 @@ class TabContents; // FavIconHelper is used to fetch the favicon for TabContents. // -// FetchFavIcon requests the favicon from the history database. At this point +// FetchFavIcon requests the favicon from the favicon service which in turn +// requests the favicon from the history database. At this point // we only know the URL of the page, and not necessarily the url of the // favicon. To ensure we handle reloading stale favicons as well as // reloading a favicon on page reload we always request the favicon from @@ -113,10 +114,10 @@ class FavIconHelper : public RenderViewHostDelegate::FavIcon { Profile* profile(); - HistoryService* GetHistoryService(); + FaviconService* GetFaviconService(); // See description above class for details. - void OnFavIconDataForInitialURL(HistoryService::Handle handle, + void OnFavIconDataForInitialURL(FaviconService::Handle handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, @@ -128,7 +129,7 @@ class FavIconHelper : public RenderViewHostDelegate::FavIcon { void DownloadFavIconOrAskHistory(NavigationEntry* entry); // See description above class for details. - void OnFavIconData(HistoryService::Handle handle, + void OnFavIconData(FaviconService::Handle handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, 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())); +} diff --git a/chrome/browser/favicon_service.h b/chrome/browser/favicon_service.h new file mode 100644 index 0000000..327acc8 --- /dev/null +++ b/chrome/browser/favicon_service.h @@ -0,0 +1,97 @@ +// 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. + +#ifndef CHROME_BROWSER_FAVICON_SERVICE_H__ +#define CHROME_BROWSER_FAVICON_SERVICE_H__ + +#include <vector> + +#include "base/ref_counted.h" +#include "base/task.h" +#include "chrome/browser/cancelable_request.h" +#include "chrome/browser/history/history_types.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/ref_counted_util.h" + +class GURL; +class Profile; + +// The favicon service provides methods to access favicons. It calls the history +// backend behind the scenes. +// +// This service is thread safe. Each request callback is invoked in the +// thread that made the request. +class FaviconService : public CancelableRequestProvider, + public base::RefCountedThreadSafe<FaviconService> { + public: + explicit FaviconService(Profile* profile); + + // Callback for GetFavicon. If we have previously inquired about the favicon + // for this URL, |know_favicon| will be true, and the rest of the fields will + // be valid (otherwise they will be ignored). + // + // On |know_favicon| == true, |data| will either contain the PNG encoded + // favicon data, or it will be NULL to indicate that the site does not have + // a favicon (in other words, we know the site doesn't have a favicon, as + // opposed to not knowing anything). |expired| will be set to true if we + // refreshed the favicon "too long" ago and should be updated if the page + // is visited again. + typedef Callback5<Handle, // handle + bool, // know_favicon + scoped_refptr<RefCountedBytes>, // data + bool, // expired + GURL>::Type // url of the favicon + FaviconDataCallback; + + typedef CancelableRequest<FaviconDataCallback> GetFaviconRequest; + + // Requests the favicon. |consumer| is notified when the bits have been + // fetched. + Handle GetFavicon(const GURL& icon_url, + CancelableRequestConsumerBase* consumer, + FaviconDataCallback* callback); + + // Fetches the favicon at |icon_url|, sending the results to the given + // |callback|. If the favicon has previously been set via SetFavicon(), then + // the favicon URL for |page_url| and all redirects is set to |icon_url|. If + // the favicon has not been set, the database is not updated. + Handle UpdateFaviconMappingAndFetch(const GURL& page_url, + const GURL& icon_url, + CancelableRequestConsumerBase* consumer, + FaviconDataCallback* callback); + + // Requests a favicon for a web page URL. |consumer| is notified + // when the bits have been fetched. + // + // Note: this version is intended to be used to retrieve the favicon of a + // page that has been browsed in the past. |expired| in the callback is + // always false. + Handle GetFaviconForURL(const GURL& page_url, + CancelableRequestConsumerBase* consumer, + FaviconDataCallback* callback); + + // Marks the favicon for the page as being out of date. + void SetFaviconOutOfDateForPage(const GURL& page_url); + + // Allows the importer to set many favicons for many pages at once. The pages + // must exist, any favicon sets for unknown pages will be discarded. Existing + // favicons will not be overwritten. + void SetImportedFavicons( + const std::vector<history::ImportedFavIconUsage>& favicon_usage); + + // Sets the favicon for a page. + void SetFavicon(const GURL& page_url, + const GURL& icon_url, + const std::vector<unsigned char>& image_data); + + private: + Profile* profile_; + + // Helper to forward an empty result if we cannot get the history service. + void ForwardEmptyResultAsync(GetFaviconRequest* request); + + DISALLOW_COPY_AND_ASSIGN(FaviconService); +}; + +#endif // CHROME_BROWSER_FAVICON_SERVICE_H__ diff --git a/chrome/browser/gtk/list_store_favicon_loader.cc b/chrome/browser/gtk/list_store_favicon_loader.cc index f2af566..68cf557 100644 --- a/chrome/browser/gtk/list_store_favicon_loader.cc +++ b/chrome/browser/gtk/list_store_favicon_loader.cc @@ -26,10 +26,10 @@ ListStoreFavIconLoader::~ListStoreFavIconLoader() { void ListStoreFavIconLoader::LoadFaviconForRow(const GURL& url, GtkTreeIter* iter) { - HistoryService* history = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (history) { - HistoryService::Handle handle = history->GetFavIconForURL( + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + if (favicon_service) { + FaviconService::Handle handle = favicon_service->GetFaviconForURL( url, consumer_, NewCallback(this, &ListStoreFavIconLoader::OnGotFavIcon)); gtk_list_store_set(list_store_, iter, diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc index 3be928c..5cf61a9 100644 --- a/chrome/browser/history/history.cc +++ b/chrome/browser/history/history.cc @@ -380,37 +380,38 @@ HistoryService::Handle HistoryService::GetPageThumbnail( new history::GetPageThumbnailRequest(callback), page_url); } -HistoryService::Handle HistoryService::GetFavIcon( - const GURL& icon_url, - CancelableRequestConsumerBase* consumer, - FavIconDataCallback* callback) { - // We always do image requests at lower-than-UI priority even though they - // appear in the UI, since they can take a long time and the user can use the - // program without them. - return Schedule(PRIORITY_NORMAL, &HistoryBackend::GetFavIcon, consumer, - new history::GetFavIconRequest(callback), icon_url); -} - -HistoryService::Handle HistoryService::UpdateFavIconMappingAndFetch( - const GURL& page_url, - const GURL& icon_url, - CancelableRequestConsumerBase* consumer, - FavIconDataCallback* callback) { - return Schedule(PRIORITY_NORMAL, - &HistoryBackend::UpdateFavIconMappingAndFetch, consumer, - new history::GetFavIconRequest(callback), page_url, icon_url); +void HistoryService::GetFavicon(FaviconService::GetFaviconRequest* request, + const GURL& icon_url) { + ScheduleTask(PRIORITY_NORMAL, + NewRunnableMethod(history_backend_.get(), + &HistoryBackend::GetFavIcon, + scoped_refptr<FaviconService::GetFaviconRequest>(request), + icon_url)); } -HistoryService::Handle HistoryService::GetFavIconForURL( +void HistoryService::UpdateFaviconMappingAndFetch( + FaviconService::GetFaviconRequest* request, const GURL& page_url, - CancelableRequestConsumerBase* consumer, - FavIconDataCallback* callback) { - return Schedule(PRIORITY_UI, &HistoryBackend::GetFavIconForURL, - consumer, new history::GetFavIconRequest(callback), - page_url); -} - -void HistoryService::SetFavIcon(const GURL& page_url, + const GURL& icon_url) { + ScheduleTask(PRIORITY_NORMAL, + NewRunnableMethod(history_backend_.get(), + &HistoryBackend::UpdateFavIconMappingAndFetch, + scoped_refptr<FaviconService::GetFaviconRequest>(request), + page_url, + icon_url)); +} + +void HistoryService::GetFaviconForURL( + FaviconService::GetFaviconRequest* request, + const GURL& page_url) { + ScheduleTask(PRIORITY_UI, + NewRunnableMethod(history_backend_.get(), + &HistoryBackend::GetFavIconForURL, + scoped_refptr<FaviconService::GetFaviconRequest>(request), + page_url)); +} + +void HistoryService::SetFavicon(const GURL& page_url, const GURL& icon_url, const std::vector<unsigned char>& image_data) { if (!CanAddURL(page_url)) @@ -421,7 +422,7 @@ void HistoryService::SetFavIcon(const GURL& page_url, scoped_refptr<RefCountedBytes>(new RefCountedBytes(image_data))); } -void HistoryService::SetFavIconOutOfDateForPage(const GURL& page_url) { +void HistoryService::SetFaviconOutOfDateForPage(const GURL& page_url) { ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::SetFavIconOutOfDateForPage, page_url); } diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h index 0643139..cf80a57 100644 --- a/chrome/browser/history/history.h +++ b/chrome/browser/history/history.h @@ -13,6 +13,7 @@ #include "base/scoped_ptr.h" #include "base/task.h" #include "chrome/browser/cancelable_request.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history_notifications.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/search_engines/template_url.h" @@ -340,66 +341,6 @@ class HistoryService : public CancelableRequestProvider, CancelableRequestConsumerBase* consumer, ThumbnailDataCallback* callback); - // Favicon ------------------------------------------------------------------- - - // Callback for GetFavIcon. If we have previously inquired about the favicon - // for this URL, |know_favicon| will be true, and the rest of the fields will - // be valid (otherwise they will be ignored). - // - // On |know_favicon| == true, |data| will either contain the PNG encoded - // favicon data, or it will be NULL to indicate that the site does not have - // a favicon (in other words, we know the site doesn't have a favicon, as - // opposed to not knowing anything). |expired| will be set to true if we - // refreshed the favicon "too long" ago and should be updated if the page - // is visited again. - typedef Callback5<Handle, // handle - bool, // know_favicon - scoped_refptr<RefCountedBytes>, // data - bool, // expired - GURL>::Type // url of the favicon - FavIconDataCallback; - - // Requests the favicon. FavIconConsumer is notified - // when the bits have been fetched. The consumer is NOT deleted by the - // HistoryService, and must be valid until the request is serviced. - Handle GetFavIcon(const GURL& icon_url, - CancelableRequestConsumerBase* consumer, - FavIconDataCallback* callback); - - // Fetches the favicon at icon_url, sending the results to the given callback. - // If the favicon has previously been set via SetFavIcon(), then the favicon - // url for page_url and all redirects is set to icon_url. If the favicon has - // not been set, the database is not updated. - Handle UpdateFavIconMappingAndFetch(const GURL& page_url, - const GURL& icon_url, - CancelableRequestConsumerBase* consumer, - FavIconDataCallback* callback); - - // Requests a favicon for a web page URL. FavIconConsumer is notified - // when the bits have been fetched. The consumer is NOT deleted by the - // HistoryService, and must be valid until the request is serviced. - // - // Note: this version is intended to be used to retrieve the favicon of a - // page that has been browsed in the past. |expired| in the callback is - // always false. - Handle GetFavIconForURL(const GURL& page_url, - CancelableRequestConsumerBase* consumer, - FavIconDataCallback* callback); - - // Sets the favicon for a page. - void SetFavIcon(const GURL& page_url, - const GURL& icon_url, - const std::vector<unsigned char>& image_data); - - // Marks the favicon for the page as being out of date. - void SetFavIconOutOfDateForPage(const GURL& page_url); - - // Allows the importer to set many favicons for many pages at once. The pages - // must exist, any favicon sets for unknown pages will be discarded. Existing - // favicons will not be overwritten. - void SetImportedFavicons( - const std::vector<history::ImportedFavIconUsage>& favicon_usage); - // Database management operations -------------------------------------------- // Delete all the information related to a single url. @@ -571,6 +512,7 @@ class HistoryService : public CancelableRequestProvider, private: class BackendDelegate; friend class BackendDelegate; + friend class FaviconService; friend class history::HistoryBackend; friend class history::HistoryQueryTest; friend class HistoryOperation; @@ -619,6 +561,43 @@ class HistoryService : public CancelableRequestProvider, // history. We filter out some URLs such as JavaScript. bool CanAddURL(const GURL& url) const; + // FavIcon ------------------------------------------------------------------- + + // These favicon methods are exposed to the FaviconService. Instead of calling + // these methods directly you should call the respective method on the + // FaviconService. + + // Used by the FaviconService to get a favicon from the history backend. + void GetFavicon(FaviconService::GetFaviconRequest* request, + const GURL& icon_url); + + // Used by the FaviconService to update the favicon mappings on the history + // backend. + void UpdateFaviconMappingAndFetch(FaviconService::GetFaviconRequest* request, + const GURL& page_url, + const GURL& icon_url); + + // Used by the FaviconService to get a favicon from the history backend. + void GetFaviconForURL(FaviconService::GetFaviconRequest* request, + const GURL& page_url); + + // Used by the FaviconService to mark the favicon for the page as being out + // of date. + void SetFaviconOutOfDateForPage(const GURL& page_url); + + // Used by the FaviconService for importing many favicons for many pages at + // once. The pages must exist, any favicon sets for unknown pages will be + // discarded. Existing favicons will not be overwritten. + void SetImportedFavicons( + const std::vector<history::ImportedFavIconUsage>& favicon_usage); + + // Used by the FaviconService to set the favicon for a page on the history + // backend. + void SetFavicon(const GURL& page_url, + const GURL& icon_url, + const std::vector<unsigned char>& image_data); + + // Sets the in-memory URL database. This is called by the backend once the // database is loaded to make it available. void SetInMemoryBackend(history::InMemoryHistoryBackend* mem_backend); diff --git a/chrome/browser/history/history_marshaling.h b/chrome/browser/history/history_marshaling.h index 76317ba..b289228 100644 --- a/chrome/browser/history/history_marshaling.h +++ b/chrome/browser/history/history_marshaling.h @@ -10,6 +10,7 @@ #include "base/scoped_vector.h" #include "chrome/browser/cancelable_request.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/page_usage_data.h" @@ -82,7 +83,7 @@ typedef CancelableRequest<HistoryService::ThumbnailDataCallback> // Favicons ------------------------------------------------------------------- -typedef CancelableRequest<HistoryService::FavIconDataCallback> +typedef CancelableRequest<FaviconService::FaviconDataCallback> GetFavIconRequest; // Downloads ------------------------------------------------------------------ diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index 45302d2..d1c8a13 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -17,6 +17,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/first_run.h" #include "chrome/browser/importer/firefox2_importer.h" #include "chrome/browser/importer/firefox3_importer.h" @@ -165,7 +166,7 @@ void ProfileWriter::AddBookmarkEntry( void ProfileWriter::AddFavicons( const std::vector<history::ImportedFavIconUsage>& favicons) { - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)-> + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS)-> SetImportedFavicons(favicons); } diff --git a/chrome/browser/jumplist.cc b/chrome/browser/jumplist.cc index 26b0e75..bcfcaa9 100644 --- a/chrome/browser/jumplist.cc +++ b/chrome/browser/jumplist.cc @@ -23,6 +23,7 @@ #include "base/thread.h" #include "base/win_util.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/page_usage_data.h" #include "chrome/browser/profile.h" @@ -636,12 +637,12 @@ bool JumpList::StartLoadingFavIcon() { if (icon_urls_.empty()) return false; - // Ask HistoryService if it has a fav icon of a URL. - // When HistoryService has one, it will call OnFavIconDataAvailable(). + // Ask FaviconService if it has a fav icon of a URL. + // When FaviocnService has one, it will call OnFavIconDataAvailable(). GURL url(icon_urls_.front().first); - HistoryService* history_service = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - HistoryService::Handle handle = history_service->GetFavIconForURL( + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + FaviconService::Handle handle = favicon_service->GetFaviconForURL( url, &fav_icon_consumer_, NewCallback(this, &JumpList::OnFavIconDataAvailable)); return true; @@ -705,7 +706,7 @@ void JumpList::OnSegmentUsageAvailable( } void JumpList::OnFavIconDataAvailable( - HistoryService::Handle handle, + FaviconService::Handle handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, diff --git a/chrome/browser/possible_url_model.cc b/chrome/browser/possible_url_model.cc index 795755f..520678a 100644 --- a/chrome/browser/possible_url_model.cc +++ b/chrome/browser/possible_url_model.cc @@ -9,6 +9,7 @@ #include "app/table_model_observer.h" #include "base/gfx/png_decoder.h" #include "chrome/browser/cancelable_request.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/profile.h" #include "chrome/common/pref_names.h" #include "grit/app_resources.h" @@ -137,14 +138,14 @@ SkBitmap PossibleURLModel::GetIcon(int row) { if (!i->second.isNull()) return i->second; } else if (profile_) { - HistoryService* hs = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (hs) { + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + if (favicon_service) { CancelableRequestProvider::Handle h = - hs->GetFavIconForURL( + favicon_service->GetFaviconForURL( result.url, &consumer_, NewCallback(this, &PossibleURLModel::OnFavIconAvailable)); - consumer_.SetClientData(hs, h, result.index); + consumer_.SetClientData(favicon_service, h, result.index); // Add an entry to the map so that we don't attempt to request the // favicon again. fav_icon_map_[result.index] = SkBitmap(); diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 77d4ff1..66891d7 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -19,6 +19,7 @@ #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/user_script_master.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history.h" #include "chrome/browser/in_process_webkit/webkit_context.h" #include "chrome/browser/net/chrome_url_request_context.h" @@ -257,6 +258,15 @@ class OffTheRecordProfileImpl : public Profile, } } + virtual FaviconService* GetFaviconService(ServiceAccessType sat) { + if (sat == EXPLICIT_ACCESS) { + return profile_->GetFaviconService(sat); + } else { + NOTREACHED() << "This profile is OffTheRecord"; + return NULL; + } + } + virtual WebDataService* GetWebDataService(ServiceAccessType sat) { if (sat == EXPLICIT_ACCESS) { return profile_->GetWebDataService(sat); @@ -505,6 +515,7 @@ ProfileImpl::ProfileImpl(const FilePath& path) extensions_request_context_(NULL), blacklist_(NULL), history_service_created_(false), + favicon_service_created_(false), created_web_data_service_(false), created_password_store_(false), created_download_manager_(false), @@ -702,6 +713,10 @@ ProfileImpl::~ProfileImpl() { history_service_ = NULL; bookmark_bar_model_.reset(); + // FaviconService depends on HistoryServce so make sure we delete + // HistoryService first. + favicon_service_ = NULL; + extension_message_service_->ProfileDestroyed(); if (extensions_service_) @@ -861,6 +876,15 @@ URLRequestContext* ProfileImpl::GetRequestContextForMedia() { return media_request_context_; } +FaviconService* ProfileImpl::GetFaviconService(ServiceAccessType sat) { + if (!favicon_service_created_) { + favicon_service_created_ = true; + scoped_refptr<FaviconService> service(new FaviconService(this)); + favicon_service_.swap(service); + } + return favicon_service_.get(); +} + URLRequestContext* ProfileImpl::GetRequestContextForExtensions() { if (!extensions_request_context_) { FilePath cookie_path = GetPath(); diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 6ff28e8..36679a7 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -32,6 +32,7 @@ class ExtensionDevToolsManager; class ExtensionProcessManager; class ExtensionMessageService; class ExtensionsService; +class FaviconService; class HistoryService; class NavigationController; class PasswordStore; @@ -152,6 +153,19 @@ class Profile { // called. virtual net::ForceTLSState* GetForceTLSState() = 0; + // Retrieves a pointer to the FaviconService associated with this + // profile. The FaviconService is lazily created the first time + // that this method is called. + // + // Although FaviconService is refcounted, this will not addref, and callers + // do not need to do any reference counting as long as they keep the pointer + // only for the local scope (which they should do anyway since the browser + // process may decide to shut down). + // + // |access| defines what the caller plans to do with the service. See + // the ServiceAccessType definition above. + virtual FaviconService* GetFaviconService(ServiceAccessType access) = 0; + // Retrieves a pointer to the HistoryService associated with this // profile. The HistoryService is lazily created the first time // that this method is called. @@ -353,6 +367,7 @@ class ProfileImpl : public Profile, virtual ExtensionDevToolsManager* GetExtensionDevToolsManager(); virtual ExtensionProcessManager* GetExtensionProcessManager(); virtual ExtensionMessageService* GetExtensionMessageService(); + virtual FaviconService* GetFaviconService(ServiceAccessType sat); virtual HistoryService* GetHistoryService(ServiceAccessType sat); virtual WebDataService* GetWebDataService(ServiceAccessType sat); virtual PasswordStore* GetPasswordStore(ServiceAccessType sat); @@ -461,12 +476,14 @@ class ProfileImpl : public Profile, scoped_refptr<DownloadManager> download_manager_; scoped_refptr<HistoryService> history_service_; + scoped_refptr<FaviconService> favicon_service_; scoped_refptr<WebDataService> web_data_service_; scoped_refptr<PasswordStore> password_store_; scoped_refptr<SessionService> session_service_; scoped_refptr<BrowserThemeProvider> theme_provider_; scoped_refptr<WebKitContext> webkit_context_; bool history_service_created_; + bool favicon_service_created_; bool created_web_data_service_; bool created_password_store_; bool created_download_manager_; diff --git a/chrome/browser/search_engines/template_url_table_model.cc b/chrome/browser/search_engines/template_url_table_model.cc index 97c6525..59fb294 100644 --- a/chrome/browser/search_engines/template_url_table_model.cc +++ b/chrome/browser/search_engines/template_url_table_model.cc @@ -8,7 +8,7 @@ #include "app/resource_bundle.h" #include "app/table_model_observer.h" #include "base/gfx/png_decoder.h" -#include "chrome/browser/history/history.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" @@ -70,10 +70,10 @@ class ModelEntry { void LoadFavIcon() { load_state_ = LOADED; - HistoryService* hs = - model_->template_url_model()->profile()->GetHistoryService( + FaviconService* favicon_service = + model_->template_url_model()->profile()->GetFaviconService( Profile::EXPLICIT_ACCESS); - if (!hs) + if (!favicon_service) return; GURL fav_icon_url = template_url().GetFavIconURL(); if (!fav_icon_url.is_valid()) { @@ -87,13 +87,13 @@ class ModelEntry { return; } load_state_ = LOADING; - hs->GetFavIcon(fav_icon_url, + favicon_service->GetFavicon(fav_icon_url, &request_consumer_, NewCallback(this, &ModelEntry::OnFavIconDataAvailable)); } void OnFavIconDataAvailable( - HistoryService::Handle handle, + FaviconService::Handle handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, diff --git a/chrome/browser/sync/glue/change_processor.cc b/chrome/browser/sync/glue/change_processor.cc index 09ddb96..dc4cc0d 100644 --- a/chrome/browser/sync/glue/change_processor.cc +++ b/chrome/browser/sync/glue/change_processor.cc @@ -9,6 +9,7 @@ #include "base/gfx/png_encoder.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_utils.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/sync/profile_sync_service.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -516,11 +517,13 @@ bool ChangeProcessor::SetBookmarkFavicon( HistoryService* history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); + FaviconService* favicon_service = + profile->GetFaviconService(Profile::EXPLICIT_ACCESS); history->AddPage(bookmark_node->GetURL()); - history->SetFavIcon(bookmark_node->GetURL(), - fake_icon_url, - icon_bytes_vector); + favicon_service->SetFavicon(bookmark_node->GetURL(), + fake_icon_url, + icon_bytes_vector); return true; } diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index f9efc7c..e486f86 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -22,6 +22,7 @@ #include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_request_manager.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/gears_integration.h" #include "chrome/browser/google_util.h" #include "chrome/browser/hung_renderer_dialog.h" @@ -704,10 +705,10 @@ bool TabContents::NavigateToPendingEntry(bool reload) { GetPasswordManager()->ClearProvisionalSave(); if (reload && !profile()->IsOffTheRecord()) { - HistoryService* history = - profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); - if (history) - history->SetFavIconOutOfDateForPage(entry.url()); + FaviconService* favicon_service = + profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); + if (favicon_service) + favicon_service->SetFaviconOutOfDateForPage(entry.url()); } return true; diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 7e86dc4..8848b32 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -1087,7 +1087,7 @@ class TabContents : public PageNavigator, bool notify_disconnection_; // Maps from handle to page_id. - typedef std::map<HistoryService::Handle, int32> HistoryRequestMap; + typedef std::map<FaviconService::Handle, int32> HistoryRequestMap; HistoryRequestMap history_requests_; #if defined(OS_WIN) diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc index a1d9034..e2ca0aa 100644 --- a/chrome/browser/views/options/general_page_view.cc +++ b/chrome/browser/views/options/general_page_view.cc @@ -13,6 +13,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/dom_ui/new_tab_ui.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/profile.h" @@ -92,7 +93,7 @@ class CustomHomePagesTableModel : public TableModel { SkBitmap icon; // If non-zero, indicates we're loading the favicon for the page. - HistoryService::Handle fav_icon_handle; + FaviconService::Handle fav_icon_handle; }; static void InitClass(); @@ -102,7 +103,7 @@ class CustomHomePagesTableModel : public TableModel { // Callback from history service. Updates the icon of the Entry whose // fav_icon_handle matches handle and notifies the observer of the change. - void OnGotFavIcon(HistoryService::Handle handle, + void OnGotFavIcon(FaviconService::Handle handle, bool know_fav_icon, scoped_refptr<RefCountedBytes> image_data, bool is_expired, @@ -110,7 +111,7 @@ class CustomHomePagesTableModel : public TableModel { // Returns the entry whose fav_icon_handle matches handle and sets entry_index // to the index of the entry. - Entry* GetEntryByLoadHandle(HistoryService::Handle handle, int* entry_index); + Entry* GetEntryByLoadHandle(FaviconService::Handle handle, int* entry_index); // Set of entries we're showing. std::vector<Entry> entries_; @@ -164,10 +165,10 @@ void CustomHomePagesTableModel::Remove(int index) { if (entry->fav_icon_handle) { // Pending load request, cancel it now so we don't deref a bogus pointer // when we get loaded notification. - HistoryService* history = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (history) - history->CancelRequest(entry->fav_icon_handle); + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + if (favicon_service) + favicon_service->CancelRequest(entry->fav_icon_handle); } entries_.erase(entries_.begin() + static_cast<size_t>(index)); if (observer_) @@ -216,17 +217,17 @@ void CustomHomePagesTableModel::InitClass() { } void CustomHomePagesTableModel::LoadFavIcon(Entry* entry) { - HistoryService* history = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (!history) + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + if (!favicon_service) return; - entry->fav_icon_handle = history->GetFavIconForURL( + entry->fav_icon_handle = favicon_service->GetFaviconForURL( entry->url, &fav_icon_consumer_, NewCallback(this, &CustomHomePagesTableModel::OnGotFavIcon)); } void CustomHomePagesTableModel::OnGotFavIcon( - HistoryService::Handle handle, + FaviconService::Handle handle, bool know_fav_icon, scoped_refptr<RefCountedBytes> image_data, bool is_expired, @@ -253,7 +254,7 @@ void CustomHomePagesTableModel::OnGotFavIcon( CustomHomePagesTableModel::Entry* CustomHomePagesTableModel::GetEntryByLoadHandle( - HistoryService::Handle handle, + FaviconService::Handle handle, int* index) { for (size_t i = 0; i < entries_.size(); ++i) { if (entries_[i].fav_icon_handle == handle) { diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index d264846..665d24f 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1153,6 +1153,8 @@ 'browser/global_keyboard_shortcuts_mac.mm', 'browser/fav_icon_helper.cc', 'browser/fav_icon_helper.h', + 'browser/favicon_service.cc', + 'browser/favicon_service.h', 'browser/find_bar.h', 'browser/find_bar_controller.cc', 'browser/find_bar_controller.h', diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index ecfec35..ff89b61 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -11,6 +11,7 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_prefs.h" #include "chrome/browser/browser_theme_provider.h" +#include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url_model.h" @@ -98,6 +99,9 @@ class TestingProfile : public Profile { virtual net::ForceTLSState* GetForceTLSState() { return NULL; } + virtual FaviconService* GetFaviconService(ServiceAccessType access) { + return NULL; + } virtual HistoryService* GetHistoryService(ServiceAccessType access) { return history_service_.get(); } |