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

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 23694031: Fix race conditions in window snapshot code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated unittest again, attempted to address feedback from jamesr@ Created 7 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_impl.h" 5 #include "content/browser/renderer_host/render_widget_host_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <set>
8 #include <utility> 9 #include <utility>
9 10
10 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
14 #include "base/debug/trace_event.h" 15 #include "base/debug/trace_event.h"
15 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
16 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
17 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "content/public/common/content_switches.h" 51 #include "content/public/common/content_switches.h"
51 #include "content/public/common/result_codes.h" 52 #include "content/public/common/result_codes.h"
52 #include "skia/ext/image_operations.h" 53 #include "skia/ext/image_operations.h"
53 #include "skia/ext/platform_canvas.h" 54 #include "skia/ext/platform_canvas.h"
54 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 55 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
55 #include "ui/events/event.h" 56 #include "ui/events/event.h"
56 #include "ui/events/keycodes/keyboard_codes.h" 57 #include "ui/events/keycodes/keyboard_codes.h"
57 #include "ui/gfx/size_conversions.h" 58 #include "ui/gfx/size_conversions.h"
58 #include "ui/gfx/skbitmap_operations.h" 59 #include "ui/gfx/skbitmap_operations.h"
59 #include "ui/gfx/vector2d_conversions.h" 60 #include "ui/gfx/vector2d_conversions.h"
61 #include "ui/snapshot/snapshot.h"
60 #include "webkit/common/cursors/webcursor.h" 62 #include "webkit/common/cursors/webcursor.h"
61 #include "webkit/common/webpreferences.h" 63 #include "webkit/common/webpreferences.h"
62 64
63 #if defined(TOOLKIT_GTK) 65 #if defined(TOOLKIT_GTK)
64 #include "content/browser/renderer_host/backing_store_gtk.h" 66 #include "content/browser/renderer_host/backing_store_gtk.h"
65 #elif defined(OS_MACOSX) 67 #elif defined(OS_MACOSX)
66 #include "content/browser/renderer_host/backing_store_mac.h" 68 #include "content/browser/renderer_host/backing_store_mac.h"
67 #elif defined(OS_WIN) 69 #elif defined(OS_WIN)
68 #include "content/common/plugin_constants_win.h" 70 #include "content/common/plugin_constants_win.h"
69 #endif 71 #endif
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // problem, for example by tracking in the RenderWidgetHelper the routing id 205 // problem, for example by tracking in the RenderWidgetHelper the routing id
204 // (and surface id) that have been created, but whose RWH haven't yet. 206 // (and surface id) that have been created, but whose RWH haven't yet.
205 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( 207 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer(
206 process_->GetID(), 208 process_->GetID(),
207 routing_id_); 209 routing_id_);
208 DCHECK(surface_id_); 210 DCHECK(surface_id_);
209 } 211 }
210 212
211 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); 213 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled();
212 214
215
213 g_routing_id_widget_map.Get().insert(std::make_pair( 216 g_routing_id_widget_map.Get().insert(std::make_pair(
214 RenderWidgetHostID(process->GetID(), routing_id_), this)); 217 RenderWidgetHostID(process->GetID(), routing_id_), this));
215 process_->AddRoute(routing_id_, this); 218 process_->AddRoute(routing_id_, this);
216 219
217 // If we're initially visible, tell the process host that we're alive. 220 // If we're initially visible, tell the process host that we're alive.
218 // Otherwise we'll notify the process host when we are first shown. 221 // Otherwise we'll notify the process host when we are first shown.
219 if (!hidden) 222 if (!hidden)
220 process_->WidgetRestored(); 223 process_->WidgetRestored();
221 224
222 accessibility_mode_ = 225 accessibility_mode_ =
(...skipping 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 1000000, 2521 1000000,
2519 100); 2522 100);
2520 } 2523 }
2521 2524
2522 if (CommandLine::ForCurrentProcess()->HasSwitch( 2525 if (CommandLine::ForCurrentProcess()->HasSwitch(
2523 switches::kEnableGpuBenchmarking)) 2526 switches::kEnableGpuBenchmarking))
2524 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); 2527 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_));
2525 } 2528 }
2526 2529
2527 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { 2530 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) {
2531 ui::LatencyInfo::LatencyComponent window_snapshot_component;
2532 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2533 GetLatencyComponentId(),
2534 &window_snapshot_component)) {
2535 WindowSnapshotReachedScreen(
2536 static_cast<int>(window_snapshot_component.sequence_number));
2537 }
2538
2528 ui::LatencyInfo::LatencyComponent rwh_component; 2539 ui::LatencyInfo::LatencyComponent rwh_component;
2529 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, 2540 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT,
2530 GetLatencyComponentId(), 2541 GetLatencyComponentId(),
2531 &rwh_component)) 2542 &rwh_component))
2532 return; 2543 return;
2533 2544
2534 rendering_stats_.input_event_count += rwh_component.event_count; 2545 rendering_stats_.input_event_count += rwh_component.event_count;
2535 rendering_stats_.total_input_latency += 2546 rendering_stats_.total_input_latency +=
2536 rwh_component.event_count * 2547 rwh_component.event_count *
2537 (latency_info.swap_timestamp - rwh_component.event_time); 2548 (latency_info.swap_timestamp - rwh_component.event_time);
(...skipping 24 matching lines...) Expand all
2562 2573
2563 if (CommandLine::ForCurrentProcess()->HasSwitch( 2574 if (CommandLine::ForCurrentProcess()->HasSwitch(
2564 switches::kEnableGpuBenchmarking)) 2575 switches::kEnableGpuBenchmarking))
2565 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); 2576 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_));
2566 } 2577 }
2567 2578
2568 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2579 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2569 view_->DidReceiveRendererFrame(); 2580 view_->DidReceiveRendererFrame();
2570 } 2581 }
2571 2582
2583 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2584 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI));
2585
2586 std::vector<unsigned char> png;
2587
2588 // This feature is behind the kEnableGpuBenchmarking command line switch
2589 // because it poses security concerns and should only be used for testing.
2590 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2591 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking)) {
2592 gfx::Rect view_bounds = GetView()->GetViewBounds();
2593 gfx::Rect snapshot_bounds(view_bounds.size());
2594 gfx::Size snapshot_size = snapshot_bounds.size();
2595
2596 if (ui::GrabViewSnapshot(GetView()->GetNativeView(),
2597 &png, snapshot_bounds)) {
2598 Send(new ViewMsg_WindowSnapshotCompleted(
2599 GetRoutingID(), snapshot_id, snapshot_size, png));
2600 return;
2601 }
2602 }
2603
2604 Send(new ViewMsg_WindowSnapshotCompleted(
2605 GetRoutingID(), snapshot_id, gfx::Size(), png));
2606 }
2607
2572 // static 2608 // static
2573 void RenderWidgetHostImpl::CompositorFrameDrawn( 2609 void RenderWidgetHostImpl::CompositorFrameDrawn(
2574 const ui::LatencyInfo& latency_info) { 2610 const ui::LatencyInfo& latency_info) {
2611 std::set<RenderWidgetHostImpl*> rwhi_set;
2612
2575 for (ui::LatencyInfo::LatencyMap::const_iterator b = 2613 for (ui::LatencyInfo::LatencyMap::const_iterator b =
2576 latency_info.latency_components.begin(); 2614 latency_info.latency_components.begin();
2577 b != latency_info.latency_components.end(); 2615 b != latency_info.latency_components.end();
2578 ++b) { 2616 ++b) {
2579 if (b->first.first != ui::INPUT_EVENT_LATENCY_RWH_COMPONENT) 2617 if (b->first.first == ui::INPUT_EVENT_LATENCY_RWH_COMPONENT ||
2580 continue; 2618 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) {
2581 // Matches with GetLatencyComponentId 2619 // Matches with GetLatencyComponentId
2582 int routing_id = b->first.second & 0xffffffff; 2620 int routing_id = b->first.second & 0xffffffff;
2583 int process_id = (b->first.second >> 32) & 0xffffffff; 2621 int process_id = (b->first.second >> 32) & 0xffffffff;
2584 RenderWidgetHost* rwh = 2622 RenderWidgetHost* rwh =
2585 RenderWidgetHost::FromID(process_id, routing_id); 2623 RenderWidgetHost::FromID(process_id, routing_id);
2586 if (!rwh) 2624 if (!rwh) {
2587 continue; 2625 continue;
2588 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); 2626 }
2627 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
2628 if (rwhi_set.insert(rwhi).second)
2629 rwhi->FrameSwapped(latency_info);
2630 }
2589 } 2631 }
2590 } 2632 }
2591 2633
2592 } // namespace content 2634 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698