Index: chrome/browser/thumbnails/thumbnail_tab_helper.cc |
diff --git a/chrome/browser/thumbnails/thumbnail_tab_helper.cc b/chrome/browser/thumbnails/thumbnail_tab_helper.cc |
index a60fd56073a0620a8ad744aa6d319d39906591d1..118d51cd10e376f49cbee01f1d60d3969620f2ef 100644 |
--- a/chrome/browser/thumbnails/thumbnail_tab_helper.cc |
+++ b/chrome/browser/thumbnails/thumbnail_tab_helper.cc |
@@ -5,7 +5,7 @@ |
#include "chrome/browser/thumbnails/thumbnail_tab_helper.h" |
#include "base/feature_list.h" |
-#include "build/build_config.h" |
+#include "base/metrics/histogram_macros.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/thumbnails/thumbnail_service.h" |
#include "chrome/browser/thumbnails/thumbnail_service_factory.h" |
@@ -18,7 +18,6 @@ |
#include "content/public/browser/render_view_host.h" |
#include "content/public/browser/render_widget_host.h" |
#include "content/public/browser/render_widget_host_view.h" |
-#include "ui/gfx/geometry/size_conversions.h" |
#include "ui/gfx/scrollbar_size.h" |
DEFINE_WEB_CONTENTS_USER_DATA_KEY(ThumbnailTabHelper); |
@@ -41,10 +40,6 @@ class SkBitmap; |
// may also be captured when a page load finishes (subject to the same |
// heuristics). |
-using content::RenderViewHost; |
-using content::RenderWidgetHost; |
-using content::WebContents; |
- |
using thumbnails::ThumbnailingContext; |
using thumbnails::ThumbnailingAlgorithm; |
@@ -60,23 +55,23 @@ ThumbnailTabHelper::ThumbnailTabHelper(content::WebContents* contents) |
// aren't views like select popups. |
registrar_.Add(this, |
content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
- content::Source<WebContents>(contents)); |
+ content::Source<content::WebContents>(contents)); |
} |
-ThumbnailTabHelper::~ThumbnailTabHelper() { |
-} |
+ThumbnailTabHelper::~ThumbnailTabHelper() = default; |
void ThumbnailTabHelper::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
switch (type) { |
case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: |
- RenderViewHostCreated(content::Details<RenderViewHost>(details).ptr()); |
+ RenderViewHostCreated( |
+ content::Details<content::RenderViewHost>(details).ptr()); |
break; |
case content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED: |
if (!*content::Details<bool>(details).ptr()) |
- WidgetHidden(content::Source<RenderWidgetHost>(source).ptr()); |
+ WidgetHidden(content::Source<content::RenderWidgetHost>(source).ptr()); |
break; |
default: |
@@ -84,14 +79,17 @@ void ThumbnailTabHelper::Observe(int type, |
} |
} |
-void ThumbnailTabHelper::RenderViewDeleted(RenderViewHost* render_view_host) { |
+void ThumbnailTabHelper::RenderViewDeleted( |
+ content::RenderViewHost* render_view_host) { |
bool registered = registrar_.IsRegistered( |
this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
- content::Source<RenderWidgetHost>(render_view_host->GetWidget())); |
+ content::Source<content::RenderWidgetHost>( |
+ render_view_host->GetWidget())); |
if (registered) { |
- registrar_.Remove( |
- this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
- content::Source<RenderWidgetHost>(render_view_host->GetWidget())); |
+ registrar_.Remove(this, |
+ content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
+ content::Source<content::RenderWidgetHost>( |
+ render_view_host->GetWidget())); |
} |
} |
@@ -121,12 +119,14 @@ void ThumbnailTabHelper::UpdateThumbnailIfNecessary() { |
// Destroying a WebContents may trigger it to be hidden, prompting a snapshot |
// which would be unwise to attempt <http://crbug.com/130097>. If the |
// WebContents is in the middle of destruction, do not risk it. |
- if (!web_contents() || web_contents()->IsBeingDestroyed()) |
+ if (!web_contents() || web_contents()->IsBeingDestroyed()) { |
return; |
+ } |
// Skip if a pending entry exists. WidgetHidden can be called while navigating |
// pages and this is not a time when thumbnails should be generated. |
- if (web_contents()->GetController().GetPendingEntry()) |
+ if (web_contents()->GetController().GetPendingEntry()) { |
return; |
+ } |
const GURL& url = web_contents()->GetURL(); |
Profile* profile = |
Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
@@ -146,7 +146,7 @@ void ThumbnailTabHelper::UpdateThumbnailIfNecessary() { |
void ThumbnailTabHelper::AsyncProcessThumbnail( |
scoped_refptr<thumbnails::ThumbnailService> thumbnail_service) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
- RenderWidgetHost* render_widget_host = |
+ content::RenderWidgetHost* render_widget_host = |
web_contents()->GetRenderViewHost()->GetWidget(); |
content::RenderWidgetHostView* view = render_widget_host->GetView(); |
if (!view || !view->IsSurfaceAvailableForCopy()) { |
@@ -181,6 +181,7 @@ void ThumbnailTabHelper::AsyncProcessThumbnail( |
scale_factor, |
©_rect, |
&thumbnailing_context_->requested_copy_size); |
+ copy_from_surface_start_time_ = base::TimeTicks::Now(); |
view->CopyFromSurface(copy_rect, thumbnailing_context_->requested_copy_size, |
base::Bind(&ThumbnailTabHelper::ProcessCapturedBitmap, |
weak_factory_.GetWeakPtr(), algorithm), |
@@ -191,9 +192,14 @@ void ThumbnailTabHelper::ProcessCapturedBitmap( |
scoped_refptr<ThumbnailingAlgorithm> algorithm, |
const SkBitmap& bitmap, |
content::ReadbackResponse response) { |
+ base::TimeDelta copy_from_surface_time = |
+ base::TimeTicks::Now() - copy_from_surface_start_time_; |
+ UMA_HISTOGRAM_TIMES("Thumbnails.CopyFromSurfaceTime", copy_from_surface_time); |
+ |
if (response == content::READBACK_SUCCESS) { |
// On success, we must be on the UI thread. |
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ process_bitmap_start_time_ = base::TimeTicks::Now(); |
algorithm->ProcessBitmap(thumbnailing_context_, |
base::Bind(&ThumbnailTabHelper::UpdateThumbnail, |
weak_factory_.GetWeakPtr()), |
@@ -209,14 +215,13 @@ void ThumbnailTabHelper::ProcessCapturedBitmap( |
} |
} |
-void ThumbnailTabHelper::CleanUpFromThumbnailGeneration() { |
- // Make a note that thumbnail generation is complete. |
- thumbnailing_context_ = nullptr; |
-} |
- |
void ThumbnailTabHelper::UpdateThumbnail(const ThumbnailingContext& context, |
const SkBitmap& thumbnail) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ base::TimeDelta process_bitmap_time = |
+ base::TimeTicks::Now() - process_bitmap_start_time_; |
+ UMA_HISTOGRAM_TIMES("Thumbnails.ProcessBitmapTime", process_bitmap_time); |
+ |
// Feed the constructed thumbnail to the thumbnail service. |
gfx::Image image = gfx::Image::CreateFrom1xBitmap(thumbnail); |
context.service->SetPageThumbnail(context, image); |
@@ -226,19 +231,26 @@ void ThumbnailTabHelper::UpdateThumbnail(const ThumbnailingContext& context, |
CleanUpFromThumbnailGeneration(); |
} |
-void ThumbnailTabHelper::RenderViewHostCreated(RenderViewHost* renderer) { |
+void ThumbnailTabHelper::CleanUpFromThumbnailGeneration() { |
+ // Make a note that thumbnail generation is complete. |
+ thumbnailing_context_ = nullptr; |
+} |
+ |
+void ThumbnailTabHelper::RenderViewHostCreated( |
+ content::RenderViewHost* renderer) { |
// NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED is really a new |
// RenderView, not RenderViewHost, and there is no good way to get |
// notifications of RenderViewHosts. So just be tolerant of re-registrations. |
bool registered = registrar_.IsRegistered( |
this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
- content::Source<RenderWidgetHost>(renderer->GetWidget())); |
+ content::Source<content::RenderWidgetHost>(renderer->GetWidget())); |
if (!registered) { |
- registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
- content::Source<RenderWidgetHost>(renderer->GetWidget())); |
+ registrar_.Add( |
+ this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
+ content::Source<content::RenderWidgetHost>(renderer->GetWidget())); |
} |
} |
-void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { |
+void ThumbnailTabHelper::WidgetHidden(content::RenderWidgetHost* widget) { |
UpdateThumbnailIfNecessary(); |
} |