summaryrefslogtreecommitdiffstats
path: root/chrome/common/thumbnail_score.cc
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-31 08:36:16 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-31 08:36:16 +0000
commiteb0b24e6cd9c7f6cb6a8274d9a2fe490edb3f401 (patch)
tree449f5dece2d41d247aaf9a6b50fc9709242bc643 /chrome/common/thumbnail_score.cc
parent72654a6bdb78772bc94082dd84f0b7facb21dc7e (diff)
downloadchromium_src-eb0b24e6cd9c7f6cb6a8274d9a2fe490edb3f401.zip
chromium_src-eb0b24e6cd9c7f6cb6a8274d9a2fe490edb3f401.tar.gz
chromium_src-eb0b24e6cd9c7f6cb6a8274d9a2fe490edb3f401.tar.bz2
Add load_completed property to ThumbnailScore.
Thumbnails taken while page loading may only contain partial contents, hence these are not desirable. BUG=65936 TEST=with --enable-in-browser-thumbnailing --vmodule=thumbnail_generator=1, confirm that thumbnails taken while page loading were replaced with new ones properly. Review URL: http://codereview.chromium.org/6962008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87284 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/thumbnail_score.cc')
-rw-r--r--chrome/common/thumbnail_score.cc41
1 files changed, 21 insertions, 20 deletions
diff --git a/chrome/common/thumbnail_score.cc b/chrome/common/thumbnail_score.cc
index 37c942a..055429d 100644
--- a/chrome/common/thumbnail_score.cc
+++ b/chrome/common/thumbnail_score.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,27 +15,25 @@ const double ThumbnailScore::kThumbnailMaximumBoringness = 0.94;
const double ThumbnailScore::kThumbnailDegradePerHour = 0.01;
// Calculates a numeric score from traits about where a snapshot was
-// taken. We store the raw components in the database because I'm sure
-// this will evolve and I don't want to break databases.
-static int GetThumbnailType(bool good_clipping, bool at_top) {
- if (good_clipping && at_top) {
- return 0;
- } else if (good_clipping && !at_top) {
- return 1;
- } else if (!good_clipping && at_top) {
- return 2;
- } else if (!good_clipping && !at_top) {
- return 3;
- } else {
- NOTREACHED();
- return -1;
- }
+// taken. The lower the better. We store the raw components in the
+// database because I'm sure this will evolve and I don't want to break
+// databases.
+static int GetThumbnailType(const ThumbnailScore& score) {
+ int type = 0;
+ if (!score.at_top)
+ type += 1;
+ if (!score.good_clipping)
+ type += 2;
+ if (!score.load_completed)
+ type += 3;
+ return type;
}
ThumbnailScore::ThumbnailScore()
: boring_score(1.0),
good_clipping(false),
at_top(false),
+ load_completed(false),
time_at_snapshot(Time::Now()),
redirect_hops_from_dest(0) {
}
@@ -44,6 +42,7 @@ ThumbnailScore::ThumbnailScore(double score, bool clipping, bool top)
: boring_score(score),
good_clipping(clipping),
at_top(top),
+ load_completed(false),
time_at_snapshot(Time::Now()),
redirect_hops_from_dest(0) {
}
@@ -53,6 +52,7 @@ ThumbnailScore::ThumbnailScore(double score, bool clipping, bool top,
: boring_score(score),
good_clipping(clipping),
at_top(top),
+ load_completed(false),
time_at_snapshot(time),
redirect_hops_from_dest(0) {
}
@@ -73,19 +73,20 @@ bool ThumbnailScore::Equals(const ThumbnailScore& rhs) const {
std::string ThumbnailScore::ToString() const {
return StringPrintf("boring_score: %f, at_top %d, good_clipping %d, "
+ "load_completed: %d, "
"time_at_snapshot: %f, redirect_hops_from_dest: %d",
boring_score,
at_top,
good_clipping,
+ load_completed,
time_at_snapshot.ToDoubleT(),
redirect_hops_from_dest);
}
bool ShouldReplaceThumbnailWith(const ThumbnailScore& current,
const ThumbnailScore& replacement) {
- int current_type = GetThumbnailType(current.good_clipping, current.at_top);
- int replacement_type = GetThumbnailType(replacement.good_clipping,
- replacement.at_top);
+ int current_type = GetThumbnailType(current);
+ int replacement_type = GetThumbnailType(replacement);
if (replacement_type < current_type) {
// If we have a better class of thumbnail, add it if it meets
// certain minimum boringness.
@@ -131,7 +132,7 @@ bool ShouldReplaceThumbnailWith(const ThumbnailScore& current,
bool ThumbnailScore::ShouldConsiderUpdating() {
const TimeDelta time_elapsed = Time::Now() - time_at_snapshot;
if (time_elapsed < kUpdateThumbnailTime &&
- good_clipping && at_top) {
+ good_clipping && at_top && load_completed) {
// The current thumbnail is new and has good properties.
return false;
}