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

Side by Side Diff: components/favicon/core/favicon_service.h

Issue 2347173002: Extend FaviconService to support fetching favicons from a Google server (Closed)
Patch Set: Minor polish Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ 5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_
6 #define COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ 6 #define COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/callback.h" 14 #include "base/callback.h"
14 #include "base/containers/hash_tables.h" 15 #include "base/containers/hash_tables.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
17 #include "base/task/cancelable_task_tracker.h" 18 #include "base/task/cancelable_task_tracker.h"
19 #include "components/data_use_measurement/core/data_use_user_data.h"
18 #include "components/favicon_base/favicon_callback.h" 20 #include "components/favicon_base/favicon_callback.h"
19 #include "components/favicon_base/favicon_types.h" 21 #include "components/favicon_base/favicon_types.h"
20 #include "components/favicon_base/favicon_usage_data.h" 22 #include "components/favicon_base/favicon_usage_data.h"
21 #include "components/keyed_service/core/keyed_service.h" 23 #include "components/keyed_service/core/keyed_service.h"
22 24
23 class GURL; 25 class GURL;
24 26
25 namespace history { 27 namespace history {
26 class HistoryService; 28 class HistoryService;
27 } 29 }
28 30
31 namespace image_fetcher {
32 class ImageFetcher;
33 }
34
29 namespace favicon { 35 namespace favicon {
30 36
31 class FaviconClient; 37 class FaviconClient;
32 38
33 // The favicon service provides methods to access favicons. It calls the history 39 // The favicon service provides methods to access favicons. It calls the history
34 // backend behind the scenes. The callbacks are run asynchronously, even in the 40 // backend behind the scenes. The callbacks are run asynchronously, even in the
35 // case of an error. 41 // case of an error.
36 class FaviconService : public KeyedService { 42 class FaviconService : public KeyedService {
37 public: 43 public:
38 // The FaviconClient must outlive the constructed FaviconService. 44 // The FaviconClient must outlive the constructed FaviconService.
39 FaviconService(std::unique_ptr<FaviconClient> favicon_client, 45 FaviconService(std::unique_ptr<FaviconClient> favicon_client,
40 history::HistoryService* history_service); 46 history::HistoryService* history_service,
47 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher);
41 48
42 ~FaviconService() override; 49 ~FaviconService() override;
43 50
44 // We usually pass parameters with pointer to avoid copy. This function is a 51 // We usually pass parameters with pointer to avoid copy. This function is a
45 // helper to run FaviconResultsCallback with pointer parameters. 52 // helper to run FaviconResultsCallback with pointer parameters.
46 static void FaviconResultsCallbackRunner( 53 static void FaviconResultsCallbackRunner(
47 const favicon_base::FaviconResultsCallback& callback, 54 const favicon_base::FaviconResultsCallback& callback,
48 const std::vector<favicon_base::FaviconRawBitmapResult>* results); 55 const std::vector<favicon_base::FaviconRawBitmapResult>* results);
49 56
50 ////////////////////////////////////////////////////////////////////////////// 57 //////////////////////////////////////////////////////////////////////////////
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 int minimum_size_in_pixels, 134 int minimum_size_in_pixels,
128 const favicon_base::FaviconRawBitmapCallback& callback, 135 const favicon_base::FaviconRawBitmapCallback& callback,
129 base::CancelableTaskTracker* tracker); 136 base::CancelableTaskTracker* tracker);
130 137
131 base::CancelableTaskTracker::TaskId GetFaviconForPageURL( 138 base::CancelableTaskTracker::TaskId GetFaviconForPageURL(
132 const GURL& page_url, 139 const GURL& page_url,
133 int icon_types, 140 int icon_types,
134 int desired_size_in_dip, 141 int desired_size_in_dip,
135 const favicon_base::FaviconResultsCallback& callback, 142 const favicon_base::FaviconResultsCallback& callback,
136 base::CancelableTaskTracker* tracker); 143 base::CancelableTaskTracker* tracker);
137 144
pkotwicz 2016/09/19 20:07:51 Thank you for the clear and very informative funct
jkrcal 2016/09/20 15:52:06 Thanks :)
145 // Downloads the favicon for the page at |page_url| with size
146 // |desired_size_in_pixel| from a Google server. Currently, only sizes 16, 24,
147 // 32, 48, and 64 are supported and only FAVICON IconType is supported. If you
148 // specify any different size < 64, the smallest larger size is fetched. If
149 // you set |desired_size_in_pixel| > 64, the 64px size is fetched. If the
150 // fetched size is not available, the largest available size is upscaled to
151 // the fetched size (by the Google server, at indexing time). If the URL at
152 // |domain_url| has non-empty path, its path is ignored (e.g.
153 // subdomain.foo.com/foo/bar -> subdomain.foo.com/). If no icon is available
pkotwicz 2016/09/19 20:07:51 I think that ignoring the path should be done in t
jkrcal 2016/09/20 15:52:06 You are right, I've changed the |domain_url| param
154 // for the given domain and size, the callback is called with a result with an
155 // empty image.
156 //
157 // This function does not check the local cache, it always directly calls the
158 // server. However, if the request is successful, it stores the resulting
159 // favicon in the cache for future use. The fetched favicon is immediately
160 // marked as expired so that when the user visits |page_url| for the next
161 // time, the favicon is re-downloaded.
162 //
163 // The Google favicon server requires to specify a string |client_id|
164 // used to identify your use case. Please negotiate a quota for your
165 // |client_id| before making use of this function in production (see
166 // g3doc/social/favicon/); use an arbitrary string in development builds. Use
167 // |data_use_service_name| to count the fetches to your data use (or
168 // NOT_TAGGED if not interested).
169 void DownloadFromGoogleServerFaviconImageForPageURL(
170 const GURL& domain_url,
171 int desired_size_in_pixel,
noyau (Ping after 24h) 2016/09/19 09:00:50 I would prefer this API to have a desired size in
pkotwicz 2016/09/19 20:07:51 Passing in the desired size in pixels matches the
jkrcal 2016/09/20 15:52:06 I would like to keep it consistent with the rest o
noyau (Ping after 24h) 2016/09/21 09:49:20 I thought the servers was only serving 1x images.
jkrcal 2016/12/09 13:57:44 All the images are favicons with 16 dip. They serv
172 std::string client_id,
173 data_use_measurement::DataUseUserData::ServiceName data_use_service_name,
174 const favicon_base::FaviconImageCallback& callback);
175
138 // Set the favicon mappings to |page_url| for |icon_types| in the history 176 // Set the favicon mappings to |page_url| for |icon_types| in the history
139 // database. 177 // database.
140 // Sample |icon_urls|: 178 // Sample |icon_urls|:
141 // { ICON_URL1 -> TOUCH_ICON, known to the database, 179 // { ICON_URL1 -> TOUCH_ICON, known to the database,
142 // ICON_URL2 -> TOUCH_ICON, not known to the database, 180 // ICON_URL2 -> TOUCH_ICON, not known to the database,
143 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } 181 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database }
144 // The new mappings are computed from |icon_urls| with these rules: 182 // The new mappings are computed from |icon_urls| with these rules:
145 // 1) Any urls in |icon_urls| which are not already known to the database are 183 // 1) Any urls in |icon_urls| which are not already known to the database are
146 // rejected. 184 // rejected.
147 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } 185 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL() 275 // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL()
238 // so that history service can deal solely with FaviconResultsCallback. 276 // so that history service can deal solely with FaviconResultsCallback.
239 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs 277 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs
240 // |callback|. 278 // |callback|.
241 void RunFaviconRawBitmapCallbackWithBitmapResults( 279 void RunFaviconRawBitmapCallbackWithBitmapResults(
242 const favicon_base::FaviconRawBitmapCallback& callback, 280 const favicon_base::FaviconRawBitmapCallback& callback,
243 int desired_size_in_pixel, 281 int desired_size_in_pixel,
244 const std::vector<favicon_base::FaviconRawBitmapResult>& 282 const std::vector<favicon_base::FaviconRawBitmapResult>&
245 favicon_bitmap_results); 283 favicon_bitmap_results);
246 284
285 // Intermediate callback for DownloadFromGoogleServerFaviconImageForPageURL()
286 // so that the client code can deal solely with FaviconImageCallback.
287 void StoreFaviconFromGoogleServiceAndRunFaviconImageCallback(
288 const favicon_base::FaviconImageCallback& callback,
289 const GURL& domain_url,
290 const std::string& icon_url,
291 const gfx::Image& image);
292
247 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; 293 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_;
248 std::unique_ptr<FaviconClient> favicon_client_; 294 std::unique_ptr<FaviconClient> favicon_client_;
249 history::HistoryService* history_service_; 295 history::HistoryService* history_service_;
296 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_;
250 297
251 DISALLOW_COPY_AND_ASSIGN(FaviconService); 298 DISALLOW_COPY_AND_ASSIGN(FaviconService);
252 }; 299 };
253 300
254 } // namespace favicon 301 } // namespace favicon
255 302
256 #endif // COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ 303 #endif // COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698