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