From eef1b5914f37b0fb0edbd1c340a60332d5453453 Mon Sep 17 00:00:00 2001 From: "mohan.reddy" Date: Fri, 12 Sep 2014 12:43:32 -0700 Subject: [PATCH] Refactoring the weak_ptr_factory order in content/browser/renderer_host Changing in the intialization order of WeakPtrFactory such that all member variables should appear before the WeakPtrFactory to ensure that any WeakPtrs to Controller are invalidated before its members variable's destructors are executed, rendering them invalid. BUG=303818 Review URL: https://codereview.chromium.org/567923002 Cr-Commit-Position: refs/heads/master@{#294637} --- content/browser/renderer_host/compositor_resize_lock_aura.cc | 4 ++-- content/browser/renderer_host/compositor_resize_lock_aura.h | 3 ++- content/browser/renderer_host/render_view_host_impl.cc | 4 ++-- content/browser/renderer_host/render_view_host_impl.h | 4 ++-- content/browser/renderer_host/render_widget_host_view_android.cc | 4 ++-- content/browser/renderer_host/render_widget_host_view_android.h | 3 ++- content/browser/renderer_host/socket_stream_dispatcher_host.cc | 4 ++-- content/browser/renderer_host/socket_stream_dispatcher_host.h | 3 ++- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/content/browser/renderer_host/compositor_resize_lock_aura.cc b/content/browser/renderer_host/compositor_resize_lock_aura.cc index 419b7b326b8a..9d5b7d87274f 100644 --- a/content/browser/renderer_host/compositor_resize_lock_aura.cc +++ b/content/browser/renderer_host/compositor_resize_lock_aura.cc @@ -19,8 +19,8 @@ CompositorResizeLock::CompositorResizeLock( const base::TimeDelta& timeout) : ResizeLock(new_size, defer_compositor_lock), host_(host), - weak_ptr_factory_(this), - cancelled_(false) { + cancelled_(false), + weak_ptr_factory_(this) { DCHECK(host_); TRACE_EVENT_ASYNC_BEGIN2("ui", "CompositorResizeLock", this, diff --git a/content/browser/renderer_host/compositor_resize_lock_aura.h b/content/browser/renderer_host/compositor_resize_lock_aura.h index 1c2be391053e..70595f94a06e 100644 --- a/content/browser/renderer_host/compositor_resize_lock_aura.h +++ b/content/browser/renderer_host/compositor_resize_lock_aura.h @@ -38,9 +38,10 @@ class CompositorResizeLock : public ResizeLock { private: aura::WindowTreeHost* host_; scoped_refptr compositor_lock_; - base::WeakPtrFactory weak_ptr_factory_; bool cancelled_; + base::WeakPtrFactory weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(CompositorResizeLock); }; diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 42707c47fa83..8f497f715c6a 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -193,9 +193,9 @@ RenderViewHostImpl::RenderViewHostImpl( sudden_termination_allowed_(false), render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), virtual_keyboard_requested_(false), - weak_factory_(this), is_focused_element_editable_(false), - updating_web_preferences_(false) { + updating_web_preferences_(false), + weak_factory_(this) { DCHECK(instance_.get()); CHECK(delegate_); // http://crbug.com/82827 diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h index 954046b41079..3b9967898df2 100644 --- a/content/browser/renderer_host/render_view_host_impl.h +++ b/content/browser/renderer_host/render_view_host_impl.h @@ -526,8 +526,6 @@ class CONTENT_EXPORT RenderViewHostImpl // TODO(nasko): Move to RenderFrameHost, as this is per-frame state. base::Closure pending_shutdown_on_swap_out_; - base::WeakPtrFactory weak_factory_; - // True if the current focused element is editable. bool is_focused_element_editable_; @@ -538,6 +536,8 @@ class CONTENT_EXPORT RenderViewHostImpl bool updating_web_preferences_; + base::WeakPtrFactory weak_factory_; + DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl); }; diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index e7a0cb248fe0..9ccfa6ccc049 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -273,7 +273,6 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( ime_adapter_android_(this), cached_background_color_(SK_ColorWHITE), last_output_surface_id_(kUndefinedOutputSurfaceId), - weak_ptr_factory_(this), overscroll_effect_enabled_( !base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableOverscrollEdgeEffect)), @@ -287,7 +286,8 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( widget_host->GetRoutingID()) != NULL), frame_evictor_(new DelegatedFrameEvictor(this)), locks_on_frame_count_(0), - observing_root_window_(false) { + observing_root_window_(false), + weak_ptr_factory_(this) { host_->SetView(this); SetContentViewCore(content_view_core); ImageTransportFactoryAndroid::AddObserver(this); diff --git a/content/browser/renderer_host/render_widget_host_view_android.h b/content/browser/renderer_host/render_widget_host_view_android.h index c41252dcd0ea..c7ec65a768c7 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.h +++ b/content/browser/renderer_host/render_widget_host_view_android.h @@ -383,7 +383,6 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid // The output surface id of the last received frame. uint32_t last_output_surface_id_; - base::WeakPtrFactory weak_ptr_factory_; std::queue ack_callbacks_; @@ -434,6 +433,8 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid // The last scroll offset of the view. gfx::Vector2dF last_scroll_offset_; + base::WeakPtrFactory weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAndroid); }; diff --git a/content/browser/renderer_host/socket_stream_dispatcher_host.cc b/content/browser/renderer_host/socket_stream_dispatcher_host.cc index c52023eb407c..5cd1d9445277 100644 --- a/content/browser/renderer_host/socket_stream_dispatcher_host.cc +++ b/content/browser/renderer_host/socket_stream_dispatcher_host.cc @@ -36,8 +36,8 @@ SocketStreamDispatcherHost::SocketStreamDispatcherHost( render_process_id_(render_process_id), request_context_callback_(request_context_callback), resource_context_(resource_context), - weak_ptr_factory_(this), - on_shutdown_(false) { + on_shutdown_(false), + weak_ptr_factory_(this) { net::WebSocketJob::EnsureInit(); } diff --git a/content/browser/renderer_host/socket_stream_dispatcher_host.h b/content/browser/renderer_host/socket_stream_dispatcher_host.h index bc0e35ffa5e0..d5e988ac1d19 100644 --- a/content/browser/renderer_host/socket_stream_dispatcher_host.h +++ b/content/browser/renderer_host/socket_stream_dispatcher_host.h @@ -88,9 +88,10 @@ class SocketStreamDispatcherHost GetRequestContextCallback request_context_callback_; ResourceContext* resource_context_; - base::WeakPtrFactory weak_ptr_factory_; bool on_shutdown_; + base::WeakPtrFactory weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(SocketStreamDispatcherHost); }; -- 2.11.4.GIT