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

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: Incorporated enne and jbauman's feedback. Created 7 years, 3 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "content/public/common/content_switches.h" 52 #include "content/public/common/content_switches.h"
52 #include "content/public/common/result_codes.h" 53 #include "content/public/common/result_codes.h"
53 #include "skia/ext/image_operations.h" 54 #include "skia/ext/image_operations.h"
54 #include "skia/ext/platform_canvas.h" 55 #include "skia/ext/platform_canvas.h"
55 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 56 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
56 #include "ui/events/event.h" 57 #include "ui/events/event.h"
57 #include "ui/events/keycodes/keyboard_codes.h" 58 #include "ui/events/keycodes/keyboard_codes.h"
58 #include "ui/gfx/size_conversions.h" 59 #include "ui/gfx/size_conversions.h"
59 #include "ui/gfx/skbitmap_operations.h" 60 #include "ui/gfx/skbitmap_operations.h"
60 #include "ui/gfx/vector2d_conversions.h" 61 #include "ui/gfx/vector2d_conversions.h"
62 #include "ui/snapshot/snapshot.h"
61 #include "webkit/common/cursors/webcursor.h" 63 #include "webkit/common/cursors/webcursor.h"
62 #include "webkit/common/webpreferences.h" 64 #include "webkit/common/webpreferences.h"
63 65
64 #if defined(TOOLKIT_GTK) 66 #if defined(TOOLKIT_GTK)
65 #include "content/browser/renderer_host/backing_store_gtk.h" 67 #include "content/browser/renderer_host/backing_store_gtk.h"
66 #elif defined(OS_MACOSX) 68 #elif defined(OS_MACOSX)
67 #include "content/browser/renderer_host/backing_store_mac.h" 69 #include "content/browser/renderer_host/backing_store_mac.h"
68 #elif defined(OS_WIN) 70 #elif defined(OS_WIN)
69 #include "content/common/plugin_constants_win.h" 71 #include "content/common/plugin_constants_win.h"
70 #endif 72 #endif
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // problem, for example by tracking in the RenderWidgetHelper the routing id 206 // problem, for example by tracking in the RenderWidgetHelper the routing id
205 // (and surface id) that have been created, but whose RWH haven't yet. 207 // (and surface id) that have been created, but whose RWH haven't yet.
206 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( 208 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer(
207 process_->GetID(), 209 process_->GetID(),
208 routing_id_); 210 routing_id_);
209 DCHECK(surface_id_); 211 DCHECK(surface_id_);
210 } 212 }
211 213
212 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); 214 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled();
213 215
216
214 g_routing_id_widget_map.Get().insert(std::make_pair( 217 g_routing_id_widget_map.Get().insert(std::make_pair(
215 RenderWidgetHostID(process->GetID(), routing_id_), this)); 218 RenderWidgetHostID(process->GetID(), routing_id_), this));
216 process_->AddRoute(routing_id_, this); 219 process_->AddRoute(routing_id_, this);
217 220
218 // If we're initially visible, tell the process host that we're alive. 221 // If we're initially visible, tell the process host that we're alive.
219 // Otherwise we'll notify the process host when we are first shown. 222 // Otherwise we'll notify the process host when we are first shown.
220 if (!hidden) 223 if (!hidden)
221 process_->WidgetRestored(); 224 process_->WidgetRestored();
222 225
223 accessibility_mode_ = 226 accessibility_mode_ =
(...skipping 2287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2511 1000000, 2514 1000000,
2512 100); 2515 100);
2513 } 2516 }
2514 2517
2515 if (CommandLine::ForCurrentProcess()->HasSwitch( 2518 if (CommandLine::ForCurrentProcess()->HasSwitch(
2516 switches::kEnableGpuBenchmarking)) 2519 switches::kEnableGpuBenchmarking))
2517 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); 2520 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_));
2518 } 2521 }
2519 2522
2520 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { 2523 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) {
2524 ui::LatencyInfo::LatencyComponent window_snapshot_component;
2525 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2526 GetLatencyComponentId(),
2527 &window_snapshot_component)) {
2528 WindowSnapshotReachedScreen(
2529 static_cast<int>(window_snapshot_component.sequence_number));
2530 }
2531
2521 ui::LatencyInfo::LatencyComponent rwh_component; 2532 ui::LatencyInfo::LatencyComponent rwh_component;
2522 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, 2533 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT,
2523 GetLatencyComponentId(), 2534 GetLatencyComponentId(),
2524 &rwh_component)) 2535 &rwh_component))
2525 return; 2536 return;
2526 2537
2527 rendering_stats_.input_event_count += rwh_component.event_count; 2538 rendering_stats_.input_event_count += rwh_component.event_count;
2528 rendering_stats_.total_input_latency += 2539 rendering_stats_.total_input_latency +=
2529 rwh_component.event_count * 2540 rwh_component.event_count *
2530 (latency_info.swap_timestamp - rwh_component.event_time); 2541 (latency_info.swap_timestamp - rwh_component.event_time);
(...skipping 24 matching lines...) Expand all
2555 2566
2556 if (CommandLine::ForCurrentProcess()->HasSwitch( 2567 if (CommandLine::ForCurrentProcess()->HasSwitch(
2557 switches::kEnableGpuBenchmarking)) 2568 switches::kEnableGpuBenchmarking))
2558 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); 2569 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_));
2559 } 2570 }
2560 2571
2561 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2572 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2562 view_->DidReceiveRendererFrame(); 2573 view_->DidReceiveRendererFrame();
2563 } 2574 }
2564 2575
2576 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2577 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI));
2578
2579 std::vector<unsigned char> png;
2580
2581 // This feature is behind the kEnableGpuBenchmarking command line switch
2582 // because it poses security concerns and should only be used for testing.
2583 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2584 if (command_line.HasSwitch(switches::kEnableGpuBenchmarking)) {
2585 gfx::Rect view_bounds = GetView()->GetViewBounds();
2586 gfx::Rect snapshot_bounds(view_bounds.size());
2587 gfx::Size snapshot_size = snapshot_bounds.size();
2588
2589 if (ui::GrabViewSnapshot(GetView()->GetNativeView(),
2590 &png, snapshot_bounds)) {
2591 Send(new ViewMsg_WindowSnapshotCompleted(
2592 GetRoutingID(), snapshot_id, snapshot_size, png));
2593 return;
2594 }
2595 }
2596
2597 Send(new ViewMsg_WindowSnapshotCompleted(
2598 GetRoutingID(), snapshot_id, gfx::Size(), png));
2599 }
2600
2565 // static 2601 // static
2566 void RenderWidgetHostImpl::CompositorFrameDrawn( 2602 void RenderWidgetHostImpl::CompositorFrameDrawn(
2567 const ui::LatencyInfo& latency_info) { 2603 const ui::LatencyInfo& latency_info) {
2604 std::set<RenderWidgetHostImpl*> rwhi_set;
2605
2568 for (ui::LatencyInfo::LatencyMap::const_iterator b = 2606 for (ui::LatencyInfo::LatencyMap::const_iterator b =
2569 latency_info.latency_components.begin(); 2607 latency_info.latency_components.begin();
2570 b != latency_info.latency_components.end(); 2608 b != latency_info.latency_components.end();
2571 ++b) { 2609 ++b) {
2572 if (b->first.first != ui::INPUT_EVENT_LATENCY_RWH_COMPONENT) 2610 if (b->first.first == ui::INPUT_EVENT_LATENCY_RWH_COMPONENT ||
2573 continue; 2611 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) {
2574 // Matches with GetLatencyComponentId 2612 // Matches with GetLatencyComponentId
2575 int routing_id = b->first.second & 0xffffffff; 2613 int routing_id = b->first.second & 0xffffffff;
2576 int process_id = (b->first.second >> 32) & 0xffffffff; 2614 int process_id = (b->first.second >> 32) & 0xffffffff;
2577 RenderWidgetHost* rwh = 2615 RenderWidgetHost* rwh =
2578 RenderWidgetHost::FromID(process_id, routing_id); 2616 RenderWidgetHost::FromID(process_id, routing_id);
2579 if (!rwh) 2617 if (!rwh) {
2580 continue; 2618 continue;
2581 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); 2619 }
2620 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
2621 if (rwhi_set.insert(rwhi).second)
2622 rwhi->FrameSwapped(latency_info);
2623 }
2582 } 2624 }
2583 } 2625 }
2584 2626
2585 } // namespace content 2627 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698