Commit 933aeaf0 authored by kulkarni.a's avatar kulkarni.a Committed by Commit bot

Maintaining the proper order of initialization WeakPtrFactory in "src/remoting"

Changing in the intialization order of WeakPtrFactory in "src/remoting" module
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/569593002

Cr-Commit-Position: refs/heads/master@{#295868}
parent 511484be
...@@ -51,7 +51,6 @@ ClientSession::ClientSession( ...@@ -51,7 +51,6 @@ ClientSession::ClientSession(
: event_handler_(event_handler), : event_handler_(event_handler),
connection_(connection.Pass()), connection_(connection.Pass()),
client_jid_(connection_->session()->jid()), client_jid_(connection_->session()->jid()),
control_factory_(this),
desktop_environment_factory_(desktop_environment_factory), desktop_environment_factory_(desktop_environment_factory),
input_tracker_(&host_input_filter_), input_tracker_(&host_input_filter_),
remote_input_filter_(&input_tracker_), remote_input_filter_(&input_tracker_),
...@@ -71,7 +70,8 @@ ClientSession::ClientSession( ...@@ -71,7 +70,8 @@ ClientSession::ClientSession(
pairing_registry_(pairing_registry), pairing_registry_(pairing_registry),
pause_video_(false), pause_video_(false),
lossless_video_encode_(false), lossless_video_encode_(false),
lossless_video_color_(false) { lossless_video_color_(false),
weak_factory_(this) {
connection_->SetEventHandler(this); connection_->SetEventHandler(this);
// TODO(sergeyu): Currently ConnectionToClient expects stubs to be // TODO(sergeyu): Currently ConnectionToClient expects stubs to be
...@@ -274,7 +274,7 @@ void ClientSession::OnConnectionAuthenticated( ...@@ -274,7 +274,7 @@ void ClientSession::OnConnectionAuthenticated(
// Create the desktop environment. Drop the connection if it could not be // Create the desktop environment. Drop the connection if it could not be
// created for any reason (for instance the curtain could not initialize). // created for any reason (for instance the curtain could not initialize).
desktop_environment_ = desktop_environment_ =
desktop_environment_factory_->Create(control_factory_.GetWeakPtr()); desktop_environment_factory_->Create(weak_factory_.GetWeakPtr());
if (!desktop_environment_) { if (!desktop_environment_) {
DisconnectSession(); DisconnectSession();
return; return;
...@@ -347,7 +347,7 @@ void ClientSession::OnConnectionClosed( ...@@ -347,7 +347,7 @@ void ClientSession::OnConnectionClosed(
DCHECK_EQ(connection_.get(), connection); DCHECK_EQ(connection_.get(), connection);
// Ignore any further callbacks. // Ignore any further callbacks.
control_factory_.InvalidateWeakPtrs(); weak_factory_.InvalidateWeakPtrs();
// If the client never authenticated then the session failed. // If the client never authenticated then the session failed.
if (!auth_input_filter_.enabled()) if (!auth_input_filter_.enabled())
......
...@@ -173,10 +173,6 @@ class ClientSession ...@@ -173,10 +173,6 @@ class ClientSession
std::string client_jid_; std::string client_jid_;
// Used to disable callbacks to |this| once DisconnectSession() has been
// called.
base::WeakPtrFactory<ClientSessionControl> control_factory_;
// Used to create a DesktopEnvironment instance for this session. // Used to create a DesktopEnvironment instance for this session.
DesktopEnvironmentFactory* desktop_environment_factory_; DesktopEnvironmentFactory* desktop_environment_factory_;
...@@ -263,6 +259,10 @@ class ClientSession ...@@ -263,6 +259,10 @@ class ClientSession
bool lossless_video_encode_; bool lossless_video_encode_;
bool lossless_video_color_; bool lossless_video_color_;
// Used to disable callbacks to |this| once DisconnectSession() has been
// called.
base::WeakPtrFactory<ClientSessionControl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ClientSession); DISALLOW_COPY_AND_ASSIGN(ClientSession);
}; };
......
...@@ -120,10 +120,10 @@ DesktopSessionAgent::DesktopSessionAgent( ...@@ -120,10 +120,10 @@ DesktopSessionAgent::DesktopSessionAgent(
input_task_runner_(input_task_runner), input_task_runner_(input_task_runner),
io_task_runner_(io_task_runner), io_task_runner_(io_task_runner),
video_capture_task_runner_(video_capture_task_runner), video_capture_task_runner_(video_capture_task_runner),
control_factory_(this),
next_shared_buffer_id_(1), next_shared_buffer_id_(1),
shared_buffers_(0), shared_buffers_(0),
started_(false) { started_(false),
weak_factory_(this) {
DCHECK(caller_task_runner_->BelongsToCurrentThread()); DCHECK(caller_task_runner_->BelongsToCurrentThread());
} }
...@@ -268,7 +268,7 @@ void DesktopSessionAgent::OnStartSessionAgent( ...@@ -268,7 +268,7 @@ void DesktopSessionAgent::OnStartSessionAgent(
// Create a desktop environment for the new session. // Create a desktop environment for the new session.
desktop_environment_ = delegate_->desktop_environment_factory().Create( desktop_environment_ = delegate_->desktop_environment_factory().Create(
control_factory_.GetWeakPtr()); weak_factory_.GetWeakPtr());
// Create the session controller and set the initial screen resolution. // Create the session controller and set the initial screen resolution.
screen_controls_ = desktop_environment_->CreateScreenControls(); screen_controls_ = desktop_environment_->CreateScreenControls();
...@@ -407,7 +407,7 @@ void DesktopSessionAgent::Stop() { ...@@ -407,7 +407,7 @@ void DesktopSessionAgent::Stop() {
started_ = false; started_ = false;
// Ignore any further callbacks. // Ignore any further callbacks.
control_factory_.InvalidateWeakPtrs(); weak_factory_.InvalidateWeakPtrs();
client_jid_.clear(); client_jid_.clear();
remote_input_filter_.reset(); remote_input_filter_.reset();
......
...@@ -179,9 +179,6 @@ class DesktopSessionAgent ...@@ -179,9 +179,6 @@ class DesktopSessionAgent
std::string client_jid_; std::string client_jid_;
// Used to disable callbacks to |this|.
base::WeakPtrFactory<ClientSessionControl> control_factory_;
base::WeakPtr<Delegate> delegate_; base::WeakPtr<Delegate> delegate_;
// The DesktopEnvironment instance used by this agent. // The DesktopEnvironment instance used by this agent.
...@@ -228,6 +225,9 @@ class DesktopSessionAgent ...@@ -228,6 +225,9 @@ class DesktopSessionAgent
// before it's received. // before it's received.
scoped_ptr<webrtc::DesktopFrame> last_frame_; scoped_ptr<webrtc::DesktopFrame> last_frame_;
// Used to disable callbacks to |this|.
base::WeakPtrFactory<DesktopSessionAgent> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent);
}; };
......
...@@ -116,9 +116,10 @@ class HostService : public WtsTerminalMonitor { ...@@ -116,9 +116,10 @@ class HostService : public WtsTerminalMonitor {
// A waitable event that is used to wait until the service is stopped. // A waitable event that is used to wait until the service is stopped.
base::WaitableEvent stopped_event_; base::WaitableEvent stopped_event_;
base::WeakPtr<HostService> weak_ptr_;
// Used to post session change notifications and control events. // Used to post session change notifications and control events.
base::WeakPtrFactory<HostService> weak_factory_; base::WeakPtrFactory<HostService> weak_factory_;
base::WeakPtr<HostService> weak_ptr_;
// Singleton. // Singleton.
friend struct DefaultSingletonTraits<HostService>; friend struct DefaultSingletonTraits<HostService>;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment