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

Unified Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 190693002: Migrate Telemetry from beginWindowSnapshotPNG to Page.captureScreenshot (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/common/view_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/render_widget_host_impl.cc
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc
index 5afb35d3ee61214ba6724785ebde7a2d0158b34e..064248bb85401680075b02e1f31745ffdf872cd8 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -193,7 +193,8 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
allow_privileged_mouse_lock_(false),
has_touch_handler_(false),
weak_factory_(this),
- last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32) {
+ last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32),
+ next_browser_snapshot_id_(0) {
CHECK(delegate_);
if (routing_id_ == MSG_ROUTING_NONE) {
routing_id_ = process_->GetNextRoutingID();
@@ -1180,6 +1181,13 @@ void RenderWidgetHostImpl::InvalidateScreenInfo() {
screen_info_.reset();
}
+void RenderWidgetHostImpl::GetSnapshotFromBrowser(
+ const base::Callback<void(const unsigned char*,size_t)> callback) {
+ int id = next_browser_snapshot_id_++;
+ pending_browser_snapshots_.insert(std::make_pair(id, callback));
+ Send(new ViewMsg_ForceRedraw(GetRoutingID(), id));
+}
+
void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text,
size_t offset,
const gfx::Range& range) {
@@ -2222,44 +2230,16 @@ void RenderWidgetHostImpl::DidReceiveRendererFrame() {
view_->DidReceiveRendererFrame();
}
-void RenderWidgetHostImpl::WindowSnapshotAsyncCallback(
- int routing_id,
- int snapshot_id,
- gfx::Size snapshot_size,
- scoped_refptr<base::RefCountedBytes> png_data) {
- if (!png_data) {
- std::vector<unsigned char> png_vector;
- Send(new ViewMsg_WindowSnapshotCompleted(
- routing_id, snapshot_id, gfx::Size(), png_vector));
- return;
- }
-
- Send(new ViewMsg_WindowSnapshotCompleted(
- routing_id, snapshot_id, snapshot_size, png_data->data()));
-}
-
void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
DCHECK(base::MessageLoopForUI::IsCurrent());
- std::vector<unsigned char> png;
-
- // This feature is behind the kEnableGpuBenchmarking command line switch
- // because it poses security concerns and should only be used for testing.
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) {
- Send(new ViewMsg_WindowSnapshotCompleted(
- GetRoutingID(), snapshot_id, gfx::Size(), png));
- return;
- }
-
gfx::Rect view_bounds = GetView()->GetViewBounds();
gfx::Rect snapshot_bounds(view_bounds.size());
- gfx::Size snapshot_size = snapshot_bounds.size();
+ std::vector<unsigned char> png;
if (ui::GrabViewSnapshot(
- GetView()->GetNativeView(), &png, snapshot_bounds)) {
- Send(new ViewMsg_WindowSnapshotCompleted(
- GetRoutingID(), snapshot_id, snapshot_size, png));
+ GetView()->GetNativeView(), &png, snapshot_bounds)) {
+ OnSnapshotDataReceived(snapshot_id, &png.front(), png.size());
return;
}
@@ -2267,11 +2247,34 @@ void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
GetView()->GetNativeView(),
snapshot_bounds,
base::ThreadTaskRunnerHandle::Get(),
- base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback,
+ base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync,
weak_factory_.GetWeakPtr(),
- GetRoutingID(),
- snapshot_id,
- snapshot_size));
+ snapshot_id));
+}
+
+void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id,
+ const unsigned char* data,
+ size_t size) {
+ // Any pending snapshots with a lower ID than the one received are considered
+ // to be implicitly complete, and returned the same snapshot data.
+ PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin();
+ while(it != pending_browser_snapshots_.end()) {
+ if (it->first <= snapshot_id) {
+ it->second.Run(data, size);
+ pending_browser_snapshots_.erase(it++);
+ } else {
+ ++it;
+ }
+ }
+}
+
+void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync(
+ int snapshot_id,
+ scoped_refptr<base::RefCountedBytes> png_data) {
+ if (png_data)
+ OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size());
+ else
+ OnSnapshotDataReceived(snapshot_id, NULL, 0);
}
// static
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/common/view_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698