Index: components/favicon/core/favicon_service_impl.h |
diff --git a/components/favicon/core/favicon_service_impl.h b/components/favicon/core/favicon_service_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ea030b260f1c7c5555cd372f488fc58e3fc3fcd3 |
--- /dev/null |
+++ b/components/favicon/core/favicon_service_impl.h |
@@ -0,0 +1,150 @@ |
+// Copyright (c) 2012 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 COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_IMPL_H_ |
+#define COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_IMPL_H_ |
+ |
+#include <stdint.h> |
+ |
+#include <memory> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "base/containers/hash_tables.h" |
+#include "base/macros.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/task/cancelable_task_tracker.h" |
+#include "components/favicon/core/favicon_service.h" |
+#include "components/favicon_base/favicon_callback.h" |
+#include "components/favicon_base/favicon_types.h" |
+#include "components/favicon_base/favicon_usage_data.h" |
+ |
+class GURL; |
+ |
+namespace history { |
+class HistoryService; |
+} |
+ |
+namespace favicon { |
+ |
+class FaviconClient; |
+ |
+// The favicon service provides methods to access favicons. It calls the history |
+// backend behind the scenes. The callbacks are run asynchronously, even in the |
+// case of an error. |
+class FaviconServiceImpl : public FaviconService { |
+ public: |
+ // |history_service| most not be nullptr and must outlive this object. |
+ FaviconServiceImpl(std::unique_ptr<FaviconClient> favicon_client, |
+ history::HistoryService* history_service); |
+ ~FaviconServiceImpl() override; |
+ |
+ // FaviconService implementation. |
+ base::CancelableTaskTracker::TaskId GetFaviconImage( |
+ const GURL& icon_url, |
+ const favicon_base::FaviconImageCallback& callback, |
+ base::CancelableTaskTracker* tracker) override; |
+ base::CancelableTaskTracker::TaskId GetRawFavicon( |
+ const GURL& icon_url, |
+ favicon_base::IconType icon_type, |
+ int desired_size_in_pixel, |
+ const favicon_base::FaviconRawBitmapCallback& callback, |
+ base::CancelableTaskTracker* tracker) override; |
+ base::CancelableTaskTracker::TaskId GetFavicon( |
+ const GURL& icon_url, |
+ favicon_base::IconType icon_type, |
+ int desired_size_in_dip, |
+ const favicon_base::FaviconResultsCallback& callback, |
+ base::CancelableTaskTracker* tracker) override; |
+ base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( |
+ const GURL& page_url, |
+ const favicon_base::FaviconImageCallback& callback, |
+ base::CancelableTaskTracker* tracker) override; |
+ base::CancelableTaskTracker::TaskId GetRawFaviconForPageURL( |
+ const GURL& page_url, |
+ int icon_types, |
+ int desired_size_in_pixel, |
+ const favicon_base::FaviconRawBitmapCallback& callback, |
+ base::CancelableTaskTracker* tracker) override; |
+ base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( |
+ const GURL& page_url, |
+ const std::vector<int>& icon_types, |
+ int minimum_size_in_pixels, |
+ const favicon_base::FaviconRawBitmapCallback& callback, |
+ base::CancelableTaskTracker* tracker) override; |
+ base::CancelableTaskTracker::TaskId GetFaviconForPageURL( |
+ const GURL& page_url, |
+ int icon_types, |
+ int desired_size_in_dip, |
+ const favicon_base::FaviconResultsCallback& callback, |
+ base::CancelableTaskTracker* tracker) override; |
+ base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( |
+ const GURL& page_url, |
+ const std::vector<GURL>& icon_urls, |
+ int icon_types, |
+ int desired_size_in_dip, |
+ const favicon_base::FaviconResultsCallback& callback, |
+ base::CancelableTaskTracker* tracker) override; |
+ base::CancelableTaskTracker::TaskId GetLargestRawFaviconForID( |
+ favicon_base::FaviconID favicon_id, |
+ const favicon_base::FaviconRawBitmapCallback& callback, |
+ base::CancelableTaskTracker* tracker) override; |
+ void SetFaviconOutOfDateForPage(const GURL& page_url) override; |
+ void SetImportedFavicons( |
+ const favicon_base::FaviconUsageDataList& favicon_usage) override; |
+ void MergeFavicon(const GURL& page_url, |
+ const GURL& icon_url, |
+ favicon_base::IconType icon_type, |
+ scoped_refptr<base::RefCountedMemory> bitmap_data, |
+ const gfx::Size& pixel_size) override; |
+ void SetFavicons(const GURL& page_url, |
+ const GURL& icon_url, |
+ favicon_base::IconType icon_type, |
+ const gfx::Image& image) override; |
+ void UnableToDownloadFavicon(const GURL& icon_url) override; |
+ bool WasUnableToDownloadFavicon(const GURL& icon_url) const override; |
+ void ClearUnableToDownloadFavicons() override; |
+ |
+ private: |
+ typedef uint32_t MissingFaviconURLHash; |
+ |
+ // Helper function for GetFaviconImageForPageURL(), GetRawFaviconForPageURL() |
+ // and GetFaviconForPageURL(). |
+ base::CancelableTaskTracker::TaskId GetFaviconForPageURLImpl( |
+ const GURL& page_url, |
+ int icon_types, |
+ const std::vector<int>& desired_sizes_in_pixel, |
+ const favicon_base::FaviconResultsCallback& callback, |
+ base::CancelableTaskTracker* tracker); |
+ |
+ // Intermediate callback for GetFaviconImage() and GetFaviconImageForPageURL() |
+ // so that history service can deal solely with FaviconResultsCallback. |
+ // Builds favicon_base::FaviconImageResult from |favicon_bitmap_results| and |
+ // runs |callback|. |
+ void RunFaviconImageCallbackWithBitmapResults( |
+ const favicon_base::FaviconImageCallback& callback, |
+ int desired_size_in_dip, |
+ const std::vector<favicon_base::FaviconRawBitmapResult>& |
+ favicon_bitmap_results); |
+ |
+ // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL() |
+ // so that history service can deal solely with FaviconResultsCallback. |
+ // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs |
+ // |callback|. |
+ void RunFaviconRawBitmapCallbackWithBitmapResults( |
+ const favicon_base::FaviconRawBitmapCallback& callback, |
+ int desired_size_in_pixel, |
+ const std::vector<favicon_base::FaviconRawBitmapResult>& |
+ favicon_bitmap_results); |
+ |
+ base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; |
+ std::unique_ptr<FaviconClient> favicon_client_; |
+ history::HistoryService* history_service_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FaviconServiceImpl); |
+}; |
+ |
+} // namespace favicon |
+ |
+#endif // COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_IMPL_H_ |