| OLD | NEW |
| 1 // Copyright (c) 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/task/cancelable_task_tracker.h" | 10 #include "base/task/cancelable_task_tracker.h" |
| 11 #include "components/favicon_base/favicon_callback.h" | 11 #include "components/favicon_base/favicon_callback.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 | 13 |
| 14 class GURL; | 14 class GURL; |
| 15 | 15 |
| 16 namespace favicon_base { | 16 namespace base { |
| 17 struct FaviconRawBitmapResult; | 17 class TaskRunner; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace favicon { | 20 namespace favicon { |
| 21 | 21 |
| 22 class FaviconService; | 22 class FaviconService; |
| 23 | 23 |
| 24 // The large icon service provides methods to access large icons. It relies on | 24 // The large icon service provides methods to access large icons. It relies on |
| 25 // the favicon service. | 25 // the favicon service. |
| 26 class LargeIconService : public KeyedService { | 26 class LargeIconService : public KeyedService { |
| 27 public: | 27 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 40 // - Returns the default fallback icon style. | 40 // - Returns the default fallback icon style. |
| 41 // For cases 2 and 3, this function returns the style of the fallback icon | 41 // For cases 2 and 3, this function returns the style of the fallback icon |
| 42 // instead of rendering an icon so clients can render the icon themselves. | 42 // instead of rendering an icon so clients can render the icon themselves. |
| 43 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( | 43 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( |
| 44 const GURL& page_url, | 44 const GURL& page_url, |
| 45 int min_source_size_in_pixel, | 45 int min_source_size_in_pixel, |
| 46 int desired_size_in_pixel, | 46 int desired_size_in_pixel, |
| 47 const favicon_base::LargeIconCallback& callback, | 47 const favicon_base::LargeIconCallback& callback, |
| 48 base::CancelableTaskTracker* tracker); | 48 base::CancelableTaskTracker* tracker); |
| 49 | 49 |
| 50 // Returns TaskRunner used to execute background task. |
| 51 virtual scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner(); |
| 52 |
| 50 private: | 53 private: |
| 51 // For testing. | 54 // For testing. |
| 52 friend class TestLargeIconService; | 55 friend class TestLargeIconService; |
| 53 | 56 |
| 54 // Resizes |bitmap_result| to |desired_size_in_pixel|x|desired_size_in_pixel|. | |
| 55 // Stores the resized bitmap data in |resized_bitmap_result| and returns true | |
| 56 // if successful. | |
| 57 bool ResizeLargeIconIfValid( | |
| 58 int min_source_size_in_pixel, | |
| 59 int desired_size_in_pixel, | |
| 60 const favicon_base::FaviconRawBitmapResult& bitmap_result, | |
| 61 favicon_base::FaviconRawBitmapResult* resized_bitmap_result); | |
| 62 | |
| 63 // Intermediate callback for GetLargeIconOrFallbackStyle(). Tries to resize | |
| 64 // |bitmap_result| and pass the output to |callback|. If that does not work, | |
| 65 // computes the icon fallback style and uses it to invoke |callback|. | |
| 66 void RunLargeIconCallback( | |
| 67 const favicon_base::LargeIconCallback& callback, | |
| 68 int min_source_size_in_pixel, | |
| 69 int desired_size_in_pixel, | |
| 70 const favicon_base::FaviconRawBitmapResult& bitmap_result); | |
| 71 | |
| 72 FaviconService* favicon_service_; | 57 FaviconService* favicon_service_; |
| 73 | 58 |
| 74 // A pre-populated list of the types of icon files to consider when looking | 59 // A pre-populated list of icon types to consider when looking for large |
| 75 // for large icons. This is an optimization over populating an icon type | 60 // icons. This is an optimization over populating an icon type vector on each |
| 76 // vector on each request. | 61 // request. |
| 77 std::vector<int> large_icon_types_; | 62 std::vector<int> large_icon_types_; |
| 78 | 63 |
| 79 DISALLOW_COPY_AND_ASSIGN(LargeIconService); | 64 DISALLOW_COPY_AND_ASSIGN(LargeIconService); |
| 80 }; | 65 }; |
| 81 | 66 |
| 82 } // namespace favicon | 67 } // namespace favicon |
| 83 | 68 |
| 84 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ | 69 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ |
| OLD | NEW |