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

Side by Side Diff: chrome/browser/thumbnails/thumbnailing_context.h

Issue 1461463002: Reland fix for thumbnail generation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rework how ignore spurrious thumbnail generation requests. Created 5 years, 1 month 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 CHROME_BROWSER_THUMBNAILS_THUMBNAILING_CONTEXT_H_ 5 #ifndef CHROME_BROWSER_THUMBNAILS_THUMBNAILING_CONTEXT_H_
6 #define CHROME_BROWSER_THUMBNAILS_THUMBNAILING_CONTEXT_H_ 6 #define CHROME_BROWSER_THUMBNAILS_THUMBNAILING_CONTEXT_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/thumbnails/thumbnail_service.h" 11 #include "chrome/browser/thumbnails/thumbnail_service.h"
11 #include "components/history/core/common/thumbnail_score.h" 12 #include "components/history/core/common/thumbnail_score.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_observer.h"
13 #include "ui/gfx/geometry/size.h" 15 #include "ui/gfx/geometry/size.h"
14 16
17 class ThumbnailTabHelper;
18
15 namespace thumbnails { 19 namespace thumbnails {
16 20
17 // The result of clipping. This can be used to determine if the 21 // The result of clipping. This can be used to determine if the
18 // generated thumbnail is good or not. 22 // generated thumbnail is good or not.
19 enum ClipResult { 23 enum ClipResult {
20 // Clipping is not done yet. 24 // Clipping is not done yet.
21 CLIP_RESULT_UNPROCESSED, 25 CLIP_RESULT_UNPROCESSED,
22 // The source image is smaller. 26 // The source image is smaller.
23 CLIP_RESULT_SOURCE_IS_SMALLER, 27 CLIP_RESULT_SOURCE_IS_SMALLER,
24 // Wider than tall by twice or more, clip horizontally. 28 // Wider than tall by twice or more, clip horizontally.
25 CLIP_RESULT_MUCH_WIDER_THAN_TALL, 29 CLIP_RESULT_MUCH_WIDER_THAN_TALL,
26 // Wider than tall, clip horizontally. 30 // Wider than tall, clip horizontally.
27 CLIP_RESULT_WIDER_THAN_TALL, 31 CLIP_RESULT_WIDER_THAN_TALL,
28 // Taller than wide, clip vertically. 32 // Taller than wide, clip vertically.
29 CLIP_RESULT_TALLER_THAN_WIDE, 33 CLIP_RESULT_TALLER_THAN_WIDE,
30 // The source and destination aspect ratios are identical. 34 // The source and destination aspect ratios are identical.
31 CLIP_RESULT_NOT_CLIPPED, 35 CLIP_RESULT_NOT_CLIPPED,
32 // The source and destination are identical. 36 // The source and destination are identical.
33 CLIP_RESULT_SOURCE_SAME_AS_TARGET, 37 CLIP_RESULT_SOURCE_SAME_AS_TARGET,
34 }; 38 };
35 39
36 // Holds the information needed for processing a thumbnail. 40 // Holds the information needed for processing a thumbnail.
37 struct ThumbnailingContext : base::RefCountedThreadSafe<ThumbnailingContext> { 41 class ThumbnailingContext
42 : public base::RefCountedThreadSafe<ThumbnailingContext>,
Lei Zhang 2015/11/20 20:01:04 BTW, I don't think ThumbnailingContext needs to be
shrike 2016/01/08 18:32:36 I think it does. At the very least the context is
43 public content::WebContentsObserver {
44 public:
38 ThumbnailingContext(content::WebContents* web_contents, 45 ThumbnailingContext(content::WebContents* web_contents,
39 ThumbnailService* receiving_service, 46 ThumbnailService* receiving_service,
47 base::WeakPtr<ThumbnailTabHelper> source_tab_helper,
Lei Zhang 2015/11/20 20:01:04 Isn't the ThumbnailTabHelper also a WebContentsUse
shrike 2016/01/08 18:32:36 Yes and yes. Having a link to the tab helper is im
40 bool load_interrupted); 48 bool load_interrupted);
41 49
42 // Create an instance for use with unit tests. 50 // Create an instance for use with unit tests.
43 static ThumbnailingContext* CreateThumbnailingContextForTest() { 51 static ThumbnailingContext* CreateThumbnailingContextForTest() {
44 return new ThumbnailingContext(); 52 return new ThumbnailingContext();
45 } 53 }
46 54
47 scoped_refptr<ThumbnailService> service; 55 const scoped_refptr<ThumbnailService>& service() const;
48 GURL url; 56
49 ClipResult clip_result; 57 const GURL& GetURL() const;
50 gfx::Size requested_copy_size; 58
51 ThumbnailScore score; 59 ClipResult clip_result() const;
60 void set_clip_result(ClipResult result);
61
62 gfx::Size requested_copy_size();
63 void set_requested_copy_size(const gfx::Size& requested_size);
64
65 ThumbnailScore score() const;
66 void SetBoringScore(double score);
67 void SetGoodClipping(bool is_good_clipping);
68 base::WeakPtr<ThumbnailTabHelper> source_tab_helper() const {
69 return source_tab_helper_;
70 }
52 71
53 private: 72 private:
54 ThumbnailingContext(); 73 ThumbnailingContext();
55 ~ThumbnailingContext(); 74 ~ThumbnailingContext() override;
56 75
57 friend class base::RefCountedThreadSafe<ThumbnailingContext>; 76 friend class base::RefCountedThreadSafe<ThumbnailingContext>;
77
78 scoped_refptr<ThumbnailService> service_;
79 ClipResult clip_result_;
80 gfx::Size requested_copy_size_;
81 ThumbnailScore score_;
82 base::WeakPtr<ThumbnailTabHelper> source_tab_helper_;
58 }; 83 };
59 84
60 } // namespace thumbnails 85 } // namespace thumbnails
61 86
62 #endif // CHROME_BROWSER_THUMBNAILS_THUMBNAILING_CONTEXT_H_ 87 #endif // CHROME_BROWSER_THUMBNAILS_THUMBNAILING_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698