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

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: Added missing dependencies. 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/keyed_service/core/keyed_service.h" 13 #include "components/keyed_service/core/keyed_service.h"
14 14
15 class GURL; 15 class GURL;
16 16
17 namespace base { 17 namespace base {
18 class TaskRunner; 18 class TaskRunner;
19 } 19 }
20 20
21 namespace image_fetcher {
22 class ImageFetcher;
23 }
24
21 namespace favicon { 25 namespace favicon {
22 26
23 class FaviconService; 27 class FaviconService;
24 28
25 // The large icon service provides methods to access large icons. It relies on 29 // The large icon service provides methods to access large icons. It relies on
26 // the favicon service. 30 // the favicon service.
27 class LargeIconService : public KeyedService { 31 class LargeIconService : public KeyedService {
28 public: 32 public:
29 LargeIconService( 33 LargeIconService(
30 FaviconService* favicon_service, 34 FaviconService* favicon_service,
31 const scoped_refptr<base::TaskRunner>& background_task_runner); 35 const scoped_refptr<base::TaskRunner>& background_task_runner,
36 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher);
32 ~LargeIconService() override; 37 ~LargeIconService() override;
33 38
34 // Requests the best large icon for the page at |page_url|. 39 // 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|: 40 // Case 1. An icon exists whose size is >= |min_source_size_in_pixel|:
36 // - If |desired_size_in_pixel| == 0: returns icon as is. 41 // - If |desired_size_in_pixel| == 0: returns icon as is.
37 // - Else: returns the icon resized to |desired_size_in_pixel|. 42 // - Else: returns the icon resized to |desired_size_in_pixel|.
38 // Case 2. An icon exists whose size is < |min_source_size_in_pixel|: 43 // 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 44 // - Extracts dominant color of smaller image, returns a fallback icon style
40 // that has a matching background. 45 // that has a matching background.
41 // Case 3. No icon exists. 46 // Case 3. No icon exists.
42 // - Returns the default fallback icon style. 47 // - Returns the default fallback icon style.
43 // For cases 2 and 3, this function returns the style of the fallback icon 48 // 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. 49 // instead of rendering an icon so clients can render the icon themselves.
45 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( 50 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle(
46 const GURL& page_url, 51 const GURL& page_url,
47 int min_source_size_in_pixel, 52 int min_source_size_in_pixel,
48 int desired_size_in_pixel, 53 int desired_size_in_pixel,
49 const favicon_base::LargeIconCallback& callback, 54 const favicon_base::LargeIconCallback& callback,
50 base::CancelableTaskTracker* tracker); 55 base::CancelableTaskTracker* tracker);
51 56
57 // Fetches the best large icon for the page at |page_url| from a Google
58 // favicon server and stores the result in the FaviconService cache
59 // (implemented in HistoryService). The write will be a no-op if the local
60 // favicon cache contains an icon for |page_url|, so clients are encouraged to
61 // use GetLargeIconOrFallbackStyle() first.
62 //
63 // A minimum size |min_source_size_in_pixel| can be specified as constraint.
64 //
65 // The callback is triggered when the operation finishes, where |success|
66 // tells whether the fetch actually managed to cache a new icon in the
67 // FaviconService.
68 //
69 // WARNING: This function will share the |page_url| with a Google server. This
70 // Can be used only for urls that are not privacy sensitive or for users that
71 // sync their history with Google servers.
pkotwicz 2017/03/03 22:33:25 Has this feature had a privacy review? What do oth
72 void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
73 const GURL& page_url,
74 int min_source_size_in_pixel,
75 const base::Callback<void(bool success)>& callback);
76
52 private: 77 private:
53 FaviconService* favicon_service_; 78 FaviconService* favicon_service_;
54 scoped_refptr<base::TaskRunner> background_task_runner_; 79 scoped_refptr<base::TaskRunner> background_task_runner_;
55 80
56 // A pre-populated list of icon types to consider when looking for large 81 // 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 82 // icons. This is an optimization over populating an icon type vector on each
58 // request. 83 // request.
59 std::vector<int> large_icon_types_; 84 std::vector<int> large_icon_types_;
60 85
86 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_;
87
61 DISALLOW_COPY_AND_ASSIGN(LargeIconService); 88 DISALLOW_COPY_AND_ASSIGN(LargeIconService);
62 }; 89 };
63 90
64 } // namespace favicon 91 } // namespace favicon
65 92
66 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ 93 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698