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