OLD | NEW |
---|---|
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/memory/ref_counted.h" | |
10 #include "base/task/cancelable_task_tracker.h" | 11 #include "base/task/cancelable_task_tracker.h" |
12 #include "base/threading/thread_checker.h" | |
11 #include "components/favicon_base/favicon_callback.h" | 13 #include "components/favicon_base/favicon_callback.h" |
12 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
13 | 15 |
14 class GURL; | 16 class GURL; |
15 | 17 |
18 namespace base { | |
19 class TaskRunner; | |
20 } | |
21 | |
16 namespace favicon_base { | 22 namespace favicon_base { |
17 struct FaviconRawBitmapResult; | 23 struct FaviconRawBitmapResult; |
18 } | 24 } |
19 | 25 |
20 namespace favicon { | 26 namespace favicon { |
21 | 27 |
22 class FaviconService; | 28 class FaviconService; |
23 | 29 |
24 // 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 |
25 // the favicon service. | 31 // the favicon service. |
(...skipping 17 matching lines...) Expand all Loading... | |
43 | 49 |
44 private: | 50 private: |
45 // Resizes |bitmap_result| to |desired_size_in_pixel|x|desired_size_in_pixel|. | 51 // Resizes |bitmap_result| to |desired_size_in_pixel|x|desired_size_in_pixel|. |
46 // Stores the resized bitmap data in |resized_bitmap_result| and returns true | 52 // Stores the resized bitmap data in |resized_bitmap_result| and returns true |
47 // if successful. | 53 // if successful. |
48 bool ResizeLargeIconIfValid( | 54 bool ResizeLargeIconIfValid( |
49 int desired_size_in_pixel, | 55 int desired_size_in_pixel, |
50 const favicon_base::FaviconRawBitmapResult& bitmap_result, | 56 const favicon_base::FaviconRawBitmapResult& bitmap_result, |
51 favicon_base::FaviconRawBitmapResult* resized_bitmap_result); | 57 favicon_base::FaviconRawBitmapResult* resized_bitmap_result); |
52 | 58 |
53 // Intermediate callback for GetLargeIconOrFallbackStyle(). Tries to resize | 59 // Tries to resize |bitmap_result| and pass the output to |callback|. If that |
54 // |bitmap_result| and pass the output to |callback|. If that does not work, | 60 // does not work, computes the icon fallback style and uses it to invoke |
55 // computes the icon fallback style and uses it to invoke |callback|. | 61 // |callback|. The work is done on a background thread since image resizing |
56 void RunLargeIconCallback( | 62 // can be expensive, and should not occur on the UI thread. |
63 void RunLargeIconCallbackOnBackgroundThread( | |
57 const favicon_base::LargeIconCallback& callback, | 64 const favicon_base::LargeIconCallback& callback, |
58 int desired_size_in_pixel, | 65 int desired_size_in_pixel, |
59 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 66 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
60 | 67 |
68 // Intermediate callback for GetLargeIconOrFallbackStyle(). | |
beaudoin
2015/05/05 00:00:52
// Meant to be invoked on the UI thread, this shou
huangs
2015/05/05 15:22:13
Done.
| |
69 void RunLargeIconCallback( | |
70 const favicon_base::LargeIconCallback& callback, | |
71 int desired_size_in_pixel, | |
72 base::CancelableTaskTracker* tracker, | |
73 const favicon_base::FaviconRawBitmapResult& bitmap_result); | |
74 | |
75 // Return the TaskRunner used to execute background task. | |
76 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner(); | |
77 | |
61 FaviconService* favicon_service_; | 78 FaviconService* favicon_service_; |
62 | 79 |
63 // A pre-populated list of the types of icon files to consider when looking | 80 // A pre-populated list of the types of icon files to consider when looking |
64 // for large icons. This is an optimization over populating an icon type | 81 // for large icons. This is an optimization over populating an icon type |
65 // vector on each request. | 82 // vector on each request. |
66 std::vector<int> large_icon_types_; | 83 std::vector<int> large_icon_types_; |
67 | 84 |
85 base::ThreadChecker thread_checker_; | |
86 | |
68 DISALLOW_COPY_AND_ASSIGN(LargeIconService); | 87 DISALLOW_COPY_AND_ASSIGN(LargeIconService); |
69 }; | 88 }; |
70 | 89 |
71 } // namespace favicon | 90 } // namespace favicon |
72 | 91 |
73 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ | 92 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ |
OLD | NEW |