Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: components/favicon/core/large_icon_service.h

Issue 1122103003: [Large Icon Service] Move icon resizing into worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make Session a class; make using callback chain functions static. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
pkotwicz 2015/05/07 14:52:14 The forward declaration is unnecessary because you
huangs 2015/05/07 21:01:59 Done.
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 class Session : public base::RefCountedThreadSafe<Session> {
29 public:
30 Session();
31 ~Session();
pkotwicz 2015/05/07 14:52:14 Nit: Please add a new line
jochen (gone - plz use gerrit) 2015/05/07 15:00:41 ref counted dtor should be private and friend RefC
huangs 2015/05/07 21:01:59 Done.
huangs 2015/05/07 21:01:59 Done.
32 int desired_size_in_pixel;
jochen (gone - plz use gerrit) 2015/05/07 15:00:41 classes should have getters/setters
huangs 2015/05/07 21:01:59 This would add bunch of boiler-plates, and I think
33 favicon_base::LargeIconCallback callback;
34 base::CancelableTaskTracker* tracker;
35 favicon_base::FaviconRawBitmapResult bitmap_result;
36 scoped_ptr<favicon_base::LargeIconResult> result;
37
38 private:
39 DISALLOW_COPY_AND_ASSIGN(Session);
40 };
41
28 explicit LargeIconService(FaviconService* favicon_service); 42 explicit LargeIconService(FaviconService* favicon_service);
29 43
30 ~LargeIconService() override; 44 ~LargeIconService() override;
31 45
46 // Main entry point, must run on the UI thread.
32 // Requests the best large icon for the page at |page_url| given the requested 47 // 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 48 // |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 49 // 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 50 // 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 51 // style of the fallback icon rather than the rendered version so that clients
37 // can render the icon themselves. 52 // can render the icon themselves.
38 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle( 53 base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle(
39 const GURL& page_url, 54 const GURL& page_url,
40 int desired_size_in_pixel, 55 int desired_size_in_pixel,
41 const favicon_base::LargeIconCallback& callback, 56 const favicon_base::LargeIconCallback& callback,
42 base::CancelableTaskTracker* tracker); 57 base::CancelableTaskTracker* tracker);
43 58
44 private: 59 // Must run on a background thread.
45 // Resizes |bitmap_result| to |desired_size_in_pixel|x|desired_size_in_pixel|. 60 // 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 61 // Stores the resized bitmap data in |resized_bitmap_result| and returns true
47 // if successful. 62 // if successful.
48 bool ResizeLargeIconIfValid( 63 static bool ResizeLargeIconIfValid(
49 int desired_size_in_pixel, 64 int desired_size_in_pixel,
50 const favicon_base::FaviconRawBitmapResult& bitmap_result, 65 const favicon_base::FaviconRawBitmapResult& bitmap_result,
51 favicon_base::FaviconRawBitmapResult* resized_bitmap_result); 66 favicon_base::FaviconRawBitmapResult* resized_bitmap_result);
52 67
53 // Intermediate callback for GetLargeIconOrFallbackStyle(). Tries to resize 68 private:
54 // |bitmap_result| and pass the output to |callback|. If that does not work, 69 // Intermediate callback for GetLargeIconOrFallbackStyle(). Must run on the
55 // computes the icon fallback style and uses it to invoke |callback|. 70 // UI thread, and should not perform complex image operations.
56 void RunLargeIconCallback( 71 static void OnIconLookupComplete(
57 const favicon_base::LargeIconCallback& callback, 72 scoped_refptr<Session> session,
58 int desired_size_in_pixel,
59 const favicon_base::FaviconRawBitmapResult& bitmap_result); 73 const favicon_base::FaviconRawBitmapResult& bitmap_result);
60 74
75 // Must run on a background thread
pkotwicz 2015/05/07 14:52:14 Nit: missing period "thread."
huangs 2015/05/07 21:01:59 Done.
76 // Tries to resize |bitmap_result| and pass the output to |callback|. If that
77 // does not work, computes the icon fallback style and uses it to invoke
78 // |callback|. The runs on a background thread since image resizing and
pkotwicz 2015/05/07 14:52:14 How about: "The runs on a background thread since"
huangs 2015/05/07 21:01:59 Done.
79 // dominant color extraction can be expensive.
80 static void ProcessIconOnBackgroundThread(scoped_refptr<Session> session);
81
82 // Must run on the UI thread.
83 // Callback to be invoked when ProcessIconOnBackgroundThread() is ready.
pkotwicz 2015/05/07 14:52:14 How about: "Invoked when ProcessIconOnBackgroundTh
huangs 2015/05/07 21:01:59 Done.
84 static void OnIconProcessingComplete(scoped_refptr<Session> session);
85
61 FaviconService* favicon_service_; 86 FaviconService* favicon_service_;
62 87
63 // A pre-populated list of the types of icon files to consider when looking 88 // 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 89 // for large icons. This is an optimization over populating an icon type
65 // vector on each request. 90 // vector on each request.
66 std::vector<int> large_icon_types_; 91 std::vector<int> large_icon_types_;
67 92
68 DISALLOW_COPY_AND_ASSIGN(LargeIconService); 93 DISALLOW_COPY_AND_ASSIGN(LargeIconService);
69 }; 94 };
70 95
71 } // namespace favicon 96 } // namespace favicon
72 97
73 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_ 98 #endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698