OLD | NEW |
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 "chrome/browser/thumbnails/thumbnail_service.h" | 10 #include "chrome/browser/thumbnails/thumbnail_service.h" |
11 #include "components/history/core/common/thumbnail_score.h" | 11 #include "components/history/core/common/thumbnail_score.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_observer.h" | |
14 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
15 | 14 |
16 namespace thumbnails { | 15 namespace thumbnails { |
17 | 16 |
18 // The result of clipping. This can be used to determine if the | 17 // The result of clipping. This can be used to determine if the |
19 // generated thumbnail is good or not. | 18 // generated thumbnail is good or not. |
20 enum ClipResult { | 19 enum ClipResult { |
21 // Clipping is not done yet. | 20 // Clipping is not done yet. |
22 CLIP_RESULT_UNPROCESSED, | 21 CLIP_RESULT_UNPROCESSED, |
23 // The source image is smaller. | 22 // The source image is smaller. |
24 CLIP_RESULT_SOURCE_IS_SMALLER, | 23 CLIP_RESULT_SOURCE_IS_SMALLER, |
25 // Wider than tall by twice or more, clip horizontally. | 24 // Wider than tall by twice or more, clip horizontally. |
26 CLIP_RESULT_MUCH_WIDER_THAN_TALL, | 25 CLIP_RESULT_MUCH_WIDER_THAN_TALL, |
27 // Wider than tall, clip horizontally. | 26 // Wider than tall, clip horizontally. |
28 CLIP_RESULT_WIDER_THAN_TALL, | 27 CLIP_RESULT_WIDER_THAN_TALL, |
29 // Taller than wide, clip vertically. | 28 // Taller than wide, clip vertically. |
30 CLIP_RESULT_TALLER_THAN_WIDE, | 29 CLIP_RESULT_TALLER_THAN_WIDE, |
31 // The source and destination aspect ratios are identical. | 30 // The source and destination aspect ratios are identical. |
32 CLIP_RESULT_NOT_CLIPPED, | 31 CLIP_RESULT_NOT_CLIPPED, |
33 // The source and destination are identical. | 32 // The source and destination are identical. |
34 CLIP_RESULT_SOURCE_SAME_AS_TARGET, | 33 CLIP_RESULT_SOURCE_SAME_AS_TARGET, |
35 }; | 34 }; |
36 | 35 |
37 // Holds the information needed for processing a thumbnail. | 36 // Holds the information needed for processing a thumbnail. |
38 class ThumbnailingContext | 37 struct ThumbnailingContext : base::RefCountedThreadSafe<ThumbnailingContext> { |
39 : public base::RefCountedThreadSafe<ThumbnailingContext>, | |
40 public content::WebContentsObserver { | |
41 public: | |
42 ThumbnailingContext(content::WebContents* web_contents, | 38 ThumbnailingContext(content::WebContents* web_contents, |
43 ThumbnailService* receiving_service, | 39 ThumbnailService* receiving_service, |
44 bool load_interrupted); | 40 bool load_interrupted); |
45 | 41 |
46 // Create an instance for use with unit tests. | 42 // Create an instance for use with unit tests. |
47 static ThumbnailingContext* CreateThumbnailingContextForTest() { | 43 static ThumbnailingContext* CreateThumbnailingContextForTest() { |
48 return new ThumbnailingContext(); | 44 return new ThumbnailingContext(); |
49 } | 45 } |
50 | 46 |
51 const scoped_refptr<ThumbnailService>& service() const; | 47 scoped_refptr<ThumbnailService> service; |
52 | 48 GURL url; |
53 const GURL& GetURL() const; | 49 ClipResult clip_result; |
54 | 50 gfx::Size requested_copy_size; |
55 ClipResult clip_result() const; | 51 ThumbnailScore score; |
56 void set_clip_result(ClipResult result); | |
57 | |
58 gfx::Size requested_copy_size(); | |
59 void set_requested_copy_size(const gfx::Size& requested_size); | |
60 | |
61 ThumbnailScore score() const; | |
62 void SetBoringScore(double score); | |
63 void SetGoodClipping(bool is_good_clipping); | |
64 | 52 |
65 private: | 53 private: |
66 ThumbnailingContext(); | 54 ThumbnailingContext(); |
67 ~ThumbnailingContext() override; | 55 ~ThumbnailingContext(); |
68 | 56 |
69 friend class base::RefCountedThreadSafe<ThumbnailingContext>; | 57 friend class base::RefCountedThreadSafe<ThumbnailingContext>; |
70 | |
71 scoped_refptr<ThumbnailService> service_; | |
72 ClipResult clip_result_; | |
73 gfx::Size requested_copy_size_; | |
74 ThumbnailScore score_; | |
75 }; | 58 }; |
76 | 59 |
77 } // namespace thumbnails | 60 } // namespace thumbnails |
78 | 61 |
79 #endif // CHROME_BROWSER_THUMBNAILS_THUMBNAILING_CONTEXT_H_ | 62 #endif // CHROME_BROWSER_THUMBNAILS_THUMBNAILING_CONTEXT_H_ |
OLD | NEW |