Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/tab_contents/thumbnail_generator.cc

Issue 6389001: Add heuristics to skip thumbnail generation when it's unnecessary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix debug unit tests Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/tab_contents/thumbnail_generator.h" 5 #include "chrome/browser/tab_contents/thumbnail_generator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 625 }
626 } 626 }
627 627
628 SkBitmap clipped_bitmap; 628 SkBitmap clipped_bitmap;
629 bitmap.extractSubset(&clipped_bitmap, src_rect); 629 bitmap.extractSubset(&clipped_bitmap, src_rect);
630 return clipped_bitmap; 630 return clipped_bitmap;
631 } 631 }
632 632
633 void ThumbnailGenerator::UpdateThumbnailIfNecessary( 633 void ThumbnailGenerator::UpdateThumbnailIfNecessary(
634 TabContents* tab_contents, const GURL& url) { 634 TabContents* tab_contents, const GURL& url) {
635 if (tab_contents->profile()->IsOffTheRecord() || 635 history::TopSites* top_sites = tab_contents->profile()->GetTopSites();
636 (url.SchemeIs("chrome") && url.host() == "newtab")) 636 // Skip if we don't need to update the thumbnail.
637 if (!ShouldUpdateThumbnail(tab_contents->profile(), top_sites, url))
637 return; 638 return;
638 // TODO(satorux): Add more conditions here to avoid unnecessary
639 // thumbnail generation.
640 639
641 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator(); 640 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
642 const int options = ThumbnailGenerator::kClippedThumbnail; 641 const int options = ThumbnailGenerator::kClippedThumbnail;
643 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; 642 ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
644 SkBitmap thumbnail = generator->GetThumbnailForRendererWithOptions( 643 SkBitmap thumbnail = generator->GetThumbnailForRendererWithOptions(
645 tab_contents->render_view_host(), options, &clip_result); 644 tab_contents->render_view_host(), options, &clip_result);
646 // Failed to generate a thumbnail. Maybe the tab is in the background? 645 // Failed to generate a thumbnail. Maybe the tab is in the background?
647 if (thumbnail.isNull()) 646 if (thumbnail.isNull())
648 return; 647 return;
649 648
650 // Compute the thumbnail score. 649 // Compute the thumbnail score.
651 ThumbnailScore score; 650 ThumbnailScore score;
652 score.at_top = 651 score.at_top =
653 (tab_contents->render_view_host()->last_scroll_offset().height() == 0); 652 (tab_contents->render_view_host()->last_scroll_offset().height() == 0);
654 score.boring_score = ThumbnailGenerator::CalculateBoringScore(&thumbnail); 653 score.boring_score = ThumbnailGenerator::CalculateBoringScore(&thumbnail);
655 score.good_clipping = 654 score.good_clipping =
656 (clip_result == ThumbnailGenerator::kTallerThanWide || 655 (clip_result == ThumbnailGenerator::kTallerThanWide ||
657 clip_result == ThumbnailGenerator::kNotClipped); 656 clip_result == ThumbnailGenerator::kNotClipped);
658 657
659 history::TopSites* top_sites = tab_contents->profile()->GetTopSites();
660 top_sites->SetPageThumbnail(url, thumbnail, score); 658 top_sites->SetPageThumbnail(url, thumbnail, score);
661 VLOG(1) << "Thumbnail taken for " << url 659 VLOG(1) << "Thumbnail taken for " << url << ": " << score.ToString();
662 << ", at_top: " << score.at_top
663 << ", boring_score: " << score.boring_score
664 << ", good_clipping: " << score.good_clipping;
665 } 660 }
661
662 bool ThumbnailGenerator::ShouldUpdateThumbnail(Profile* profile,
663 history::TopSites* top_sites,
664 const GURL& url) {
665 if (!profile || !top_sites)
666 return false;
667 // Skip if it's in the off-the-record mode.
668 if (profile->IsOffTheRecord())
669 return false;
670 // Skip if the given URL is not appropriate for history.
671 if (!HistoryService::CanAddURL(url))
672 return false;
673 // Skip if the top sites list is full, and the URL is not known.
674 const bool is_known = top_sites->IsKnownURL(url);
675 if (top_sites->IsFull() && !is_known)
676 return false;
677 // Skip if we don't have to udpate the existing thumbnail.
678 ThumbnailScore current_score;
679 if (is_known &&
680 top_sites->GetPageThumbnailScore(url, &current_score) &&
681 !current_score.ShouldConsiderUpdating())
682 return false;
683
684 return true;
685 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698