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/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
10 #include "base/task/cancelable_task_tracker.h" | 12 #include "base/task/cancelable_task_tracker.h" |
11 #include "components/favicon_base/favicon_callback.h" | 13 #include "components/favicon_base/favicon_callback.h" |
14 #include "components/favicon_base/favicon_types.h" | |
12 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
13 | 16 |
14 class GURL; | 17 class GURL; |
15 | 18 |
16 namespace favicon_base { | |
17 struct FaviconRawBitmapResult; | |
18 } | |
19 | |
20 namespace favicon { | 19 namespace favicon { |
21 | 20 |
22 class FaviconService; | 21 class FaviconService; |
22 class LargeIconResult; | |
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: |
28 struct Session : base::RefCountedThreadSafe<Session> { | |
jochen (gone - plz use gerrit)
2015/05/06 12:58:49
this should be a class
huangs
2015/05/06 22:45:14
Done.
| |
29 public: | |
30 int desired_size_in_pixel; | |
31 favicon_base::LargeIconCallback callback; | |
32 base::CancelableTaskTracker* tracker; | |
33 favicon_base::FaviconRawBitmapResult bitmap_result; | |
34 scoped_ptr<favicon_base::LargeIconResult> result; | |
35 }; | |
36 | |
28 explicit LargeIconService(FaviconService* favicon_service); | 37 explicit LargeIconService(FaviconService* favicon_service); |
29 | 38 |
30 ~LargeIconService() override; | 39 ~LargeIconService() override; |
31 | 40 |
32 // Requests the best large icon for the page at |page_url| given the requested | 41 // Requests the best large icon for the page at |page_url| given the requested |
33 // |desired_size_in_pixel|. If no good large icon can be found, returns the | 42 // |desired_size_in_pixel|. If no good large icon can be found, returns the |
34 // fallback style to use, for which the background is set to the dominant | 43 // fallback style to use, for which the background is set to the dominant |
35 // color of a smaller icon when one is available. This function returns the | 44 // color of a smaller icon when one is available. This function returns the |
36 // style of the fallback icon rather than the rendered version so that clients | 45 // style of the fallback icon rather than the rendered version so that clients |
37 // can render the icon themselves. | 46 // can render the icon themselves. Must run on the UI thread. |
38 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( | 47 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( |
39 const GURL& page_url, | 48 const GURL& page_url, |
40 int desired_size_in_pixel, | 49 int desired_size_in_pixel, |
41 const favicon_base::LargeIconCallback& callback, | 50 const favicon_base::LargeIconCallback& callback, |
42 base::CancelableTaskTracker* tracker); | 51 base::CancelableTaskTracker* tracker); |
43 | 52 |
44 private: | |
45 // Resizes |bitmap_result| to |desired_size_in_pixel|x|desired_size_in_pixel|. | 53 // 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 | 54 // Stores the resized bitmap data in |resized_bitmap_result| and returns true |
47 // if successful. | 55 // if successful. Must run on a background thread. |
48 bool ResizeLargeIconIfValid( | 56 static bool ResizeLargeIconIfValid( |
49 int desired_size_in_pixel, | 57 int desired_size_in_pixel, |
50 const favicon_base::FaviconRawBitmapResult& bitmap_result, | 58 const favicon_base::FaviconRawBitmapResult& bitmap_result, |
51 favicon_base::FaviconRawBitmapResult* resized_bitmap_result); | 59 favicon_base::FaviconRawBitmapResult* resized_bitmap_result); |
52 | 60 |
53 // Intermediate callback for GetLargeIconOrFallbackStyle(). Tries to resize | 61 private: |
54 // |bitmap_result| and pass the output to |callback|. If that does not work, | 62 // Intermediate callback for GetLargeIconOrFallbackStyle(). Must run on the |
55 // computes the icon fallback style and uses it to invoke |callback|. | 63 // UI thread, and should not perform complex image operations. |
56 void RunLargeIconCallback( | 64 void OnIconLookupComplete( |
57 const favicon_base::LargeIconCallback& callback, | 65 scoped_refptr<Session> session, |
58 int desired_size_in_pixel, | |
59 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 66 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
60 | 67 |
68 // Tries to resize |bitmap_result| and pass the output to |callback|. If that | |
69 // does not work, computes the icon fallback style and uses it to invoke | |
70 // |callback|. The runs on a background thread since image resizing and | |
71 // dominant color extraction can be expensive. | |
72 void ProcessIconOnBackgroundThread(scoped_refptr<Session> session); | |
73 | |
74 // Callback to be invoked when ProcessIconOnBackgroundThread() is ready. Must | |
75 // run on the UI thread. | |
76 void OnIconProcessingComplete(scoped_refptr<Session> session); | |
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 |
68 DISALLOW_COPY_AND_ASSIGN(LargeIconService); | 85 DISALLOW_COPY_AND_ASSIGN(LargeIconService); |
69 }; | 86 }; |
70 | 87 |
71 } // namespace favicon | 88 } // namespace favicon |
72 | 89 |
73 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ | 90 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ |
OLD | NEW |