Index: components/favicon/core/large_icon_service.h |
diff --git a/components/favicon/core/large_icon_service.h b/components/favicon/core/large_icon_service.h |
index bb8c1381f01ceaff4f7ece32adfbef69066f6056..ede064172c9337c9edc47ee92e358fa1f5d13501 100644 |
--- a/components/favicon/core/large_icon_service.h |
+++ b/components/favicon/core/large_icon_service.h |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -7,24 +7,33 @@ |
#include <vector> |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
#include "base/task/cancelable_task_tracker.h" |
#include "components/favicon_base/favicon_callback.h" |
+#include "components/favicon_base/favicon_types.h" |
#include "components/keyed_service/core/keyed_service.h" |
class GURL; |
-namespace favicon_base { |
-struct FaviconRawBitmapResult; |
-} |
- |
namespace favicon { |
class FaviconService; |
+class LargeIconResult; |
// The large icon service provides methods to access large icons. It relies on |
// the favicon service. |
class LargeIconService : public KeyedService { |
public: |
+ struct Session : base::RefCountedThreadSafe<Session> { |
+ public: |
+ int desired_size_in_pixel; |
+ favicon_base::LargeIconCallback callback; |
+ base::CancelableTaskTracker* tracker; |
+ favicon_base::FaviconRawBitmapResult bitmap_result; |
+ scoped_ptr<favicon_base::LargeIconResult> result; |
+ }; |
+ |
explicit LargeIconService(FaviconService* favicon_service); |
~LargeIconService() override; |
@@ -34,30 +43,38 @@ class LargeIconService : public KeyedService { |
// fallback style to use, for which the background is set to the dominant |
// color of a smaller icon when one is available. This function returns the |
// style of the fallback icon rather than the rendered version so that clients |
- // can render the icon themselves. |
+ // can render the icon themselves. This run on the UI thread. |
base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( |
const GURL& page_url, |
int desired_size_in_pixel, |
const favicon_base::LargeIconCallback& callback, |
base::CancelableTaskTracker* tracker); |
- private: |
// Resizes |bitmap_result| to |desired_size_in_pixel|x|desired_size_in_pixel|. |
// Stores the resized bitmap data in |resized_bitmap_result| and returns true |
- // if successful. |
- bool ResizeLargeIconIfValid( |
- int desired_size_in_pixel, |
- const favicon_base::FaviconRawBitmapResult& bitmap_result, |
- favicon_base::FaviconRawBitmapResult* resized_bitmap_result); |
- |
- // Intermediate callback for GetLargeIconOrFallbackStyle(). Tries to resize |
- // |bitmap_result| and pass the output to |callback|. If that does not work, |
- // computes the icon fallback style and uses it to invoke |callback|. |
- void RunLargeIconCallback( |
- const favicon_base::LargeIconCallback& callback, |
- int desired_size_in_pixel, |
+ // if successful. This runs on a background thread. |
+ static bool ResizeLargeIconIfValid( |
+ int desired_size_in_pixel, |
+ const favicon_base::FaviconRawBitmapResult& bitmap_result, |
+ favicon_base::FaviconRawBitmapResult* resized_bitmap_result); |
+ |
+ private: |
+ // Intermediate callback for GetLargeIconOrFallbackStyle(). This runs on the |
+ // UI thread, and should not perform complex image operations. |
+ void OnIconLookupComplete( |
+ scoped_refptr<Session> session, |
const favicon_base::FaviconRawBitmapResult& bitmap_result); |
+ // Tries to resize |bitmap_result| and pass the output to |callback|. If that |
+ // does not work, computes the icon fallback style and uses it to invoke |
+ // |callback|. The runs on a background thread since image resizing and |
+ // dominant color extraction can be expensive. |
+ void ProcessIconOnBackgroundThread(scoped_refptr<Session> session); |
+ |
+ // Callback to be invoked when ProcessIconOnBackgroundThread() is ready. This |
+ // runs on the UI thread. |
+ void OnIconProcessingComplete(scoped_refptr<Session> session); |
+ |
FaviconService* favicon_service_; |
// A pre-populated list of the types of icon files to consider when looking |