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

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

Issue 2721363002: Extend LargeIconService to fetch missing favicons from a Google server (Closed)
Patch Set: Add fallback_opts=TYPE 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
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 <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/task/cancelable_task_tracker.h" 11 #include "base/task/cancelable_task_tracker.h"
12 #include "components/favicon_base/favicon_callback.h" 12 #include "components/favicon_base/favicon_callback.h"
13 #include "components/image_fetcher/core/image_fetcher.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 and stores the result in the FaviconService database
60 // (implemented in HistoryService). The write will be a no-op if the local
61 // favicon database contains an icon for |page_url|, so clients are
62 // encouraged to use GetLargeIconOrFallbackStyle() first.
63 //
64 // A minimum size |min_source_size_in_pixel| can be specified as a constraint.
65 //
66 // The callback is triggered when the operation finishes, where |success|
67 // tells whether the fetch actually managed to database a new icon in the
68 // FaviconService.
69 //
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 void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
74 const GURL& page_url,
75 int min_source_size_in_pixel,
76 const base::Callback<void(bool success)>& callback);
77
52 private: 78 private:
53 FaviconService* favicon_service_; 79 FaviconService* favicon_service_;
54 scoped_refptr<base::TaskRunner> background_task_runner_; 80 scoped_refptr<base::TaskRunner> background_task_runner_;
55 81
56 // A pre-populated list of icon types to consider when looking for large 82 // A pre-populated list of icon types to consider when looking for large
57 // icons. This is an optimization over populating an icon type vector on each 83 // icons. This is an optimization over populating an icon type vector on each
58 // request. 84 // request.
59 std::vector<int> large_icon_types_; 85 std::vector<int> large_icon_types_;
60 86
87 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_;
88
61 DISALLOW_COPY_AND_ASSIGN(LargeIconService); 89 DISALLOW_COPY_AND_ASSIGN(LargeIconService);
62 }; 90 };
63 91
64 } // namespace favicon 92 } // namespace favicon
65 93
66 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ 94 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_
OLDNEW
« no previous file with comments | « components/favicon/core/favicon_service_impl.cc ('k') | components/favicon/core/large_icon_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698