Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1250)

Unified Diff: components/favicon/core/favicon_service.h

Issue 2347173002: Extend FaviconService to support fetching favicons from a Google server (Closed)
Patch Set: Peter's comments #2 Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/favicon/core/favicon_service.h
diff --git a/components/favicon/core/favicon_service.h b/components/favicon/core/favicon_service.h
index 9585934169f21c7407aff49adb9fa1718a3a30af..69aeffc66a63d6aa5b06625dabe7ab4ade6371bc 100644
--- a/components/favicon/core/favicon_service.h
+++ b/components/favicon/core/favicon_service.h
@@ -8,6 +8,7 @@
#include <stdint.h>
#include <memory>
+#include <string>
#include <vector>
#include "base/callback.h"
@@ -15,6 +16,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/task/cancelable_task_tracker.h"
+#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/favicon_base/favicon_callback.h"
#include "components/favicon_base/favicon_types.h"
#include "components/favicon_base/favicon_usage_data.h"
@@ -26,6 +28,10 @@ namespace history {
class HistoryService;
}
+namespace image_fetcher {
+class ImageFetcher;
+}
+
namespace favicon {
class FaviconClient;
@@ -37,7 +43,8 @@ class FaviconService : public KeyedService {
public:
// The FaviconClient must outlive the constructed FaviconService.
FaviconService(std::unique_ptr<FaviconClient> favicon_client,
- history::HistoryService* history_service);
+ history::HistoryService* history_service,
+ std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher);
~FaviconService() override;
@@ -135,6 +142,48 @@ class FaviconService : public KeyedService {
const favicon_base::FaviconResultsCallback& callback,
base::CancelableTaskTracker* tracker);
+ // If there are any FAVICONs for the page at |page_url| in the local cache, it
+ // uses only the local cache and never requests the icon from any Google
+ // server. If there is no icon in the cache larger than
+ // |minimum_size_in_pixel|, the result is an empty image. Otherwise, the
+ // result is a favicon rescaled to |desired_size_in_pixel|. If there are
+ // multiple icons to choose from, the one with size closest to the desired one
+ // is used (always preferring larger than |desired_size_in_pixel| over smaller
+ // ones).
+ //
+ // If there are no FAVICONs for the page at |page_url|, the function downloads
+ // the favicon for the page at |page_url| with size |desired_size_in_pixel|
+ // from a Google server. Currently, only icons of FAVICON IconType and of
+ // sizes 16, 24, 32, 48, and 64 are supported. If you specify any different
+ // size < 64, the smallest larger size is fetched. If you set
+ // |desired_size_in_pixel| > 64, the 64px size is fetched. If the fetched size
+ // is not available, the largest available size is upscaled to the fetched
+ // size (by the Google server, at indexing time). If no icon is available for
+ // the given url and size, the callback is called with a result with an empty
+ // image.
+ //
+ // If the request is successful, it stores the resulting favicon in the
+ // thumbnail database for future use (possibly overwriting previous image in
+ // the cache for the given url). The fetched favicon is immediately marked as
+ // expired so that when the user visits |page_url| for the next time, the
+ // favicon is re-downloaded.
+ //
+ // The Google favicon server requires to specify a string |client_id|
+ // used to identify your use case. Please negotiate a quota for your
+ // |client_id| before making use of this function in production (see
+ // g3doc/social/favicon/); use an arbitrary string in development builds. Use
+ // |data_use_service_name| to count the fetches to your data use (or
+ // NOT_TAGGED if not interested).
+ base::CancelableTaskTracker::TaskId
+ Get1xFaviconForPageURLDownloadFromGoogleServerIfMissing(
+ const GURL& page_url,
+ int minimum_size_in_pixel,
+ int desired_size_in_pixel,
+ std::string client_id,
+ data_use_measurement::DataUseUserData::ServiceName data_use_service_name,
+ const favicon_base::FaviconImageCallback& callback,
+ base::CancelableTaskTracker* tracker);
+
// Set the favicon mappings to |page_url| for |icon_types| in the history
// database.
// Sample |icon_urls|:
@@ -244,9 +293,33 @@ class FaviconService : public KeyedService {
const std::vector<favicon_base::FaviconRawBitmapResult>&
favicon_bitmap_results);
+ // Intermediate callback for
+ // GetRawFaviconForPageURLDownloadFromGoogleServerIfNeeded() so that the
+ // client code can deal solely with FaviconImageCallback.
+ void RunFaviconImageCallbackOrDownloadFromGoogleFaviconServer(
+ const GURL& page_url,
+ int minimum_size_in_pixel,
+ int desired_size_in_pixel,
+ std::string client_id,
+ data_use_measurement::DataUseUserData::ServiceName data_use_service_name,
+ const favicon_base::FaviconImageCallback& callback,
+ const std::vector<favicon_base::FaviconRawBitmapResult>&
+ favicon_bitmap_results);
+
+ // Intermediate callback for
+ // RunFaviconImageCallbackOrDownloadFromGoogleFaviconServer() so that the
+ // client code can deal solely with FaviconImageCallback.
+ void StoreFaviconFromGoogleServerAndRunFaviconImageCallback(
+ const favicon_base::FaviconImageCallback& callback,
+ const GURL& domain_url,
+ int desired_size_in_pixel,
+ const std::string& icon_url,
+ const gfx::Image& image);
+
base::hash_set<MissingFaviconURLHash> missing_favicon_urls_;
std::unique_ptr<FaviconClient> favicon_client_;
history::HistoryService* history_service_;
+ std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_;
DISALLOW_COPY_AND_ASSIGN(FaviconService);
};

Powered by Google App Engine
This is Rietveld 408576698