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

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

Issue 2685173002: Extend LargeIconService to fetch missing favicons from a Google server (Closed)
Patch Set: Peter's comments #2 (WIP) Created 3 years, 9 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
« no previous file with comments | « components/favicon/core/features.cc ('k') | components/favicon/core/large_icon_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_LARGE_ICON_SERVICE_H_ 5 #ifndef COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_
6 #define COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ 6 #define COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_
7 7
8 #include <string>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/task/cancelable_task_tracker.h" 12 #include "base/task/cancelable_task_tracker.h"
12 #include "components/favicon_base/favicon_callback.h" 13 #include "components/favicon_base/favicon_callback.h"
13 #include "components/keyed_service/core/keyed_service.h" 14 #include "components/keyed_service/core/keyed_service.h"
14 15
15 class GURL; 16 class GURL;
16 17
17 namespace base { 18 namespace base {
18 class TaskRunner; 19 class TaskRunner;
19 } 20 }
20 21
22 namespace image_fetcher {
23 class ImageFetcher;
24 }
25
21 namespace favicon { 26 namespace favicon {
22 27
23 class FaviconService; 28 class FaviconService;
24 29
25 // The large icon service provides methods to access large icons. It relies on 30 // The large icon service provides methods to access large icons. It relies on
26 // the favicon service. 31 // the favicon service.
27 class LargeIconService : public KeyedService { 32 class LargeIconService : public KeyedService {
28 public: 33 public:
29 LargeIconService( 34 LargeIconService(
30 FaviconService* favicon_service, 35 FaviconService* favicon_service,
31 const scoped_refptr<base::TaskRunner>& background_task_runner); 36 const scoped_refptr<base::TaskRunner>& background_task_runner,
37 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher);
32 ~LargeIconService() override; 38 ~LargeIconService() override;
33 39
34 // Requests the best large icon for the page at |page_url|. 40 // Requests the best large icon for the page at |page_url|.
35 // Case 1. An icon exists whose size is >= |min_source_size_in_pixel|: 41 // Case 1. An icon exists whose size is >= |min_source_size_in_pixel|:
36 // - If |desired_size_in_pixel| == 0: returns icon as is. 42 // - If |desired_size_in_pixel| == 0: returns icon as is.
37 // - Else: returns the icon resized to |desired_size_in_pixel|. 43 // - Else: returns the icon resized to |desired_size_in_pixel|.
38 // Case 2. An icon exists whose size is < |min_source_size_in_pixel|: 44 // Case 2. An icon exists whose size is < |min_source_size_in_pixel|:
39 // - Extracts dominant color of smaller image, returns a fallback icon style 45 // - Extracts dominant color of smaller image, returns a fallback icon style
40 // that has a matching background. 46 // that has a matching background.
41 // Case 3. No icon exists. 47 // Case 3. No icon exists.
42 // - Returns the default fallback icon style. 48 // - Returns the default fallback icon style.
43 // For cases 2 and 3, this function returns the style of the fallback icon 49 // For cases 2 and 3, this function returns the style of the fallback icon
44 // instead of rendering an icon so clients can render the icon themselves. 50 // instead of rendering an icon so clients can render the icon themselves.
45 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( 51 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle(
46 const GURL& page_url, 52 const GURL& page_url,
47 int min_source_size_in_pixel, 53 int min_source_size_in_pixel,
48 int desired_size_in_pixel, 54 int desired_size_in_pixel,
49 const favicon_base::LargeIconCallback& callback, 55 const favicon_base::LargeIconCallback& callback,
50 base::CancelableTaskTracker* tracker); 56 base::CancelableTaskTracker* tracker);
51 57
58 // Fetches the best large icon for the page at |page_url| from a Google
59 // favicon server. Similarly to |GetLargeIconOrFallbackStyle|.
60 // Case 1. An icon is fetched whose size is >= |min_source_size_in_pixel|:
61 // - If |desired_size_in_pixel| == 0: returns icon as is.
62 // - Else: returns the icon resized to |desired_size_in_pixel|.
63 // Case 2. An icon is fetched whose size is < |min_source_size_in_pixel|:
64 // - Extracts dominant color of smaller image, returns a fallback icon style
65 // that has a matching background.
66 // Case 3. No icon exists.
67 // - Returns the default fallback icon style.
68 // For cases 2 and 3, this function returns the style of the fallback icon
69 // instead of rendering an icon so clients can render the icon themselves.
70 // WARNING: This function will share the |page_url| with a Google server. This
71 // Can be used only for urls that are not privacy sensitive or for users that
72 // sync their history with Google servers.
73 base::CancelableTaskTracker::TaskId
74 GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
75 const GURL& page_url,
76 int min_source_size_in_pixel,
77 int desired_size_in_pixel,
78 const favicon_base::LargeIconCallback& callback,
79 base::CancelableTaskTracker* tracker);
80
52 private: 81 private:
53 FaviconService* favicon_service_; 82 FaviconService* favicon_service_;
54 scoped_refptr<base::TaskRunner> background_task_runner_; 83 scoped_refptr<base::TaskRunner> background_task_runner_;
55 84
56 // A pre-populated list of icon types to consider when looking for large 85 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_;
57 // icons. This is an optimization over populating an icon type vector on each
58 // request.
59 std::vector<int> large_icon_types_;
60 86
61 DISALLOW_COPY_AND_ASSIGN(LargeIconService); 87 DISALLOW_COPY_AND_ASSIGN(LargeIconService);
62 }; 88 };
63 89
64 } // namespace favicon 90 } // namespace favicon
65 91
66 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ 92 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_
OLDNEW
« no previous file with comments | « components/favicon/core/features.cc ('k') | components/favicon/core/large_icon_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698