| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_COMMON_THUMBNAIL_SCORE_H_ | |
| 6 #define CHROME_COMMON_THUMBNAIL_SCORE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include "base/time/time.h" | |
| 10 | |
| 11 // A set of metadata about a Thumbnail. | |
| 12 struct ThumbnailScore { | |
| 13 // Initializes the ThumbnailScore to the absolute worst possible values | |
| 14 // except for time, which is set to Now(), and redirect_hops_from_dest which | |
| 15 // is set to 0. | |
| 16 ThumbnailScore(); | |
| 17 | |
| 18 // Builds a ThumbnailScore with the passed in values, and sets the | |
| 19 // thumbnail generation time to Now(). | |
| 20 ThumbnailScore(double score, bool clipping, bool top); | |
| 21 | |
| 22 // Builds a ThumbnailScore with the passed in values. | |
| 23 ThumbnailScore(double score, bool clipping, bool top, | |
| 24 const base::Time& time); | |
| 25 ~ThumbnailScore(); | |
| 26 | |
| 27 // Tests for equivalence between two ThumbnailScore objects. | |
| 28 bool Equals(const ThumbnailScore& rhs) const; | |
| 29 | |
| 30 // Returns string representation of this object. | |
| 31 std::string ToString() const; | |
| 32 | |
| 33 // How "boring" a thumbnail is. The boring score is the 0,1 ranged | |
| 34 // percentage of pixels that are the most common luma. Higher boring | |
| 35 // scores indicate that a higher percentage of a bitmap are all the | |
| 36 // same brightness (most likely the same color). | |
| 37 // | |
| 38 // The score should only be used for comparing two thumbnails taken from | |
| 39 // the same page to see which one is more boring/interesting. The | |
| 40 // absolute score is not suitable for judging whether the thumbnail is | |
| 41 // actually boring or not. For instance, www.google.com is very | |
| 42 // succinct, so the boring score can be as high as 0.9, depending on the | |
| 43 // browser window size. | |
| 44 double boring_score; | |
| 45 | |
| 46 // Whether the thumbnail was taken with height greater than | |
| 47 // width or width greater than height and the aspect ratio less than | |
| 48 // kTooWideAspectRatio. In cases where we don't have |good_clipping|, | |
| 49 // the thumbnails are either clipped from the horizontal center of the | |
| 50 // window, or are otherwise weirdly stretched. | |
| 51 bool good_clipping; | |
| 52 | |
| 53 // Whether this thumbnail was taken while the renderer was | |
| 54 // displaying the top of the page. Most pages are more recognizable | |
| 55 // by their headers then by a set of random text half way down the | |
| 56 // page; i.e. most MediaWiki sites would be indistinguishable by | |
| 57 // thumbnails with |at_top| set to false. | |
| 58 bool at_top; | |
| 59 | |
| 60 // Whether this thumbnail was taken after load was completed. | |
| 61 // Thumbnails taken while page loading may only contain partial | |
| 62 // contents. | |
| 63 bool load_completed; | |
| 64 | |
| 65 // Record the time when a thumbnail was taken. This is used to make | |
| 66 // sure thumbnails are kept fresh. | |
| 67 base::Time time_at_snapshot; | |
| 68 | |
| 69 // The number of hops from the final destination page that this thumbnail was | |
| 70 // taken at. When a thumbnail is taken, this will always be the redirect | |
| 71 // destination (value of 0). | |
| 72 // | |
| 73 // For the most visited view, we'll sometimes get thumbnails for URLs in the | |
| 74 // middle of a redirect chain. In this case, the top sites component will set | |
| 75 // this value so the distance from the destination can be taken into account | |
| 76 // by the comparison function. | |
| 77 // | |
| 78 // If "http://google.com/" redirected to "http://www.google.com/", then | |
| 79 // a thumbnail for the first would have a redirect hop of 1, and the second | |
| 80 // would have a redirect hop of 0. | |
| 81 int redirect_hops_from_dest; | |
| 82 | |
| 83 // How bad a thumbnail needs to be before we completely ignore it. | |
| 84 static const double kThumbnailMaximumBoringness; | |
| 85 | |
| 86 // We consider a thumbnail interesting enough if the boring score is | |
| 87 // lower than this. | |
| 88 static const double kThumbnailInterestingEnoughBoringness; | |
| 89 | |
| 90 // Time before we take a worse thumbnail (subject to | |
| 91 // kThumbnailMaximumBoringness) over what's currently in the database | |
| 92 // for freshness. | |
| 93 static const int64 kUpdateThumbnailTimeDays; | |
| 94 | |
| 95 // Penalty of how much more boring a thumbnail should be per hour. | |
| 96 static const double kThumbnailDegradePerHour; | |
| 97 | |
| 98 // If a thumbnail is taken with the aspect ratio greater than or equal to | |
| 99 // this value, |good_clipping| is to false. | |
| 100 static const double kTooWideAspectRatio; | |
| 101 | |
| 102 // Checks whether we should consider updating a new thumbnail based on | |
| 103 // this score. For instance, we don't have to update a new thumbnail | |
| 104 // if the current thumbnail is new and interesting enough. | |
| 105 bool ShouldConsiderUpdating(); | |
| 106 }; | |
| 107 | |
| 108 // Checks whether we should replace one thumbnail with another. | |
| 109 bool ShouldReplaceThumbnailWith(const ThumbnailScore& current, | |
| 110 const ThumbnailScore& replacement); | |
| 111 | |
| 112 #endif // CHROME_COMMON_THUMBNAIL_SCORE_H_ | |
| OLD | NEW |