| OLD | NEW |
| 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/memory/weak_ptr.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/image_fetcher/core/image_fetcher.h" | 14 #include "components/image_fetcher/core/image_fetcher.h" |
| 14 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
| 15 | 16 |
| 16 class GURL; | 17 class GURL; |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class TaskRunner; | 20 class TaskRunner; |
| 20 } | 21 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 41 // Case 1. An icon exists whose size is >= |min_source_size_in_pixel|: | 42 // Case 1. An icon exists whose size is >= |min_source_size_in_pixel|: |
| 42 // - If |desired_size_in_pixel| == 0: returns icon as is. | 43 // - If |desired_size_in_pixel| == 0: returns icon as is. |
| 43 // - Else: returns the icon resized to |desired_size_in_pixel|. | 44 // - Else: returns the icon resized to |desired_size_in_pixel|. |
| 44 // Case 2. An icon exists whose size is < |min_source_size_in_pixel|: | 45 // Case 2. An icon exists whose size is < |min_source_size_in_pixel|: |
| 45 // - Extracts dominant color of smaller image, returns a fallback icon style | 46 // - Extracts dominant color of smaller image, returns a fallback icon style |
| 46 // that has a matching background. | 47 // that has a matching background. |
| 47 // Case 3. No icon exists. | 48 // Case 3. No icon exists. |
| 48 // - Returns the default fallback icon style. | 49 // - Returns the default fallback icon style. |
| 49 // For cases 2 and 3, this function returns the style of the fallback icon | 50 // For cases 2 and 3, this function returns the style of the fallback icon |
| 50 // instead of rendering an icon so clients can render the icon themselves. | 51 // instead of rendering an icon so clients can render the icon themselves. |
| 52 // TODO(jkrcal): Rename to GetLargeIconRawBitmapOrFallbackStyle. |
| 51 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( | 53 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( |
| 52 const GURL& page_url, | 54 const GURL& page_url, |
| 53 int min_source_size_in_pixel, | 55 int min_source_size_in_pixel, |
| 54 int desired_size_in_pixel, | 56 int desired_size_in_pixel, |
| 55 const favicon_base::LargeIconCallback& callback, | 57 const favicon_base::LargeIconCallback& callback, |
| 56 base::CancelableTaskTracker* tracker); | 58 base::CancelableTaskTracker* tracker); |
| 59 |
| 60 // Behaves the same as GetLargeIconOrFallbackStyle, only returns the large |
| 61 // icon (if available) decoded. |
| 62 base::CancelableTaskTracker::TaskId GetLargeIconImageOrFallbackStyle( |
| 63 const GURL& page_url, |
| 64 int min_source_size_in_pixel, |
| 65 int desired_size_in_pixel, |
| 66 const favicon_base::LargeIconImageCallback& callback, |
| 67 base::CancelableTaskTracker* tracker); |
| 57 | 68 |
| 58 // Fetches the best large icon for the page at |page_url| from a Google | 69 // 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 | 70 // favicon server and stores the result in the FaviconService database |
| 60 // (implemented in HistoryService). The write will be a no-op if the local | 71 // (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 | 72 // favicon database contains an icon for |page_url|, so clients are |
| 62 // encouraged to use GetLargeIconOrFallbackStyle() first. | 73 // encouraged to use GetLargeIconOrFallbackStyle() first. |
| 63 // | 74 // |
| 64 // A minimum size |min_source_size_in_pixel| can be specified as a constraint. | 75 // A minimum size |min_source_size_in_pixel| can be specified as a constraint. |
| 65 // | 76 // |
| 66 // The callback is triggered when the operation finishes, where |success| | 77 // The callback is triggered when the operation finishes, where |success| |
| 67 // tells whether the fetch actually managed to database a new icon in the | 78 // tells whether the fetch actually managed to database a new icon in the |
| 68 // FaviconService. | 79 // FaviconService. |
| 69 // | 80 // |
| 70 // WARNING: This function will share the |page_url| with a Google server. This | 81 // 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 | 82 // Can be used only for urls that are not privacy sensitive or for users that |
| 72 // sync their history with Google servers. | 83 // sync their history with Google servers. |
| 73 void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( | 84 void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( |
| 74 const GURL& page_url, | 85 const GURL& page_url, |
| 75 int min_source_size_in_pixel, | 86 int min_source_size_in_pixel, |
| 76 const base::Callback<void(bool success)>& callback); | 87 const base::Callback<void(bool success)>& callback); |
| 77 | 88 |
| 78 private: | 89 private: |
| 90 void DecodeRawBitmap(const favicon_base::LargeIconImageCallback& callback, |
| 91 const favicon_base::LargeIconResult& raw_result); |
| 92 |
| 93 void DecodingRawBitmapFinished( |
| 94 const favicon_base::LargeIconImageCallback& callback, |
| 95 const gfx::Image& image); |
| 96 |
| 79 FaviconService* favicon_service_; | 97 FaviconService* favicon_service_; |
| 80 scoped_refptr<base::TaskRunner> background_task_runner_; | 98 scoped_refptr<base::TaskRunner> background_task_runner_; |
| 81 | 99 |
| 82 // A pre-populated list of icon types to consider when looking for large | 100 // A pre-populated list of icon types to consider when looking for large |
| 83 // icons. This is an optimization over populating an icon type vector on each | 101 // icons. This is an optimization over populating an icon type vector on each |
| 84 // request. | 102 // request. |
| 85 std::vector<int> large_icon_types_; | 103 std::vector<int> large_icon_types_; |
| 86 | 104 |
| 87 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; | 105 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; |
| 88 | 106 |
| 107 // Weak pointer factory as the requests to large icon service may last longer |
| 108 // than the service itself. |
| 109 base::WeakPtrFactory<LargeIconService> weak_ptr_factory_; |
| 110 |
| 89 DISALLOW_COPY_AND_ASSIGN(LargeIconService); | 111 DISALLOW_COPY_AND_ASSIGN(LargeIconService); |
| 90 }; | 112 }; |
| 91 | 113 |
| 92 } // namespace favicon | 114 } // namespace favicon |
| 93 | 115 |
| 94 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ | 116 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ |
| OLD | NEW |