Deallocate ChromotingJniInstance members on disconnection.

Ensure that the members are fully cleaned up during disconnection,
before the object gets destroyed (which can happen on a random thread).
Otherwise the members may be destroyed on the wrong thread, triggering
DCHECKs.

BUG=395312

Review URL: https://codereview.chromium.org/406123002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284621 0039d316-1c4b-4281-b951-d872f2087c98
parent 79ed457b
...@@ -90,13 +90,24 @@ ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, ...@@ -90,13 +90,24 @@ ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime,
this)); this));
} }
ChromotingJniInstance::~ChromotingJniInstance() {} ChromotingJniInstance::~ChromotingJniInstance() {
// This object is ref-counted, so this dtor can execute on any thread.
// Ensure that all these objects have been freed already, so they are not
// destroyed on some random thread.
DCHECK(!view_);
DCHECK(!client_context_);
DCHECK(!video_renderer_);
DCHECK(!authenticator_);
DCHECK(!client_);
DCHECK(!signaling_);
DCHECK(!client_status_logger_);
}
void ChromotingJniInstance::Cleanup() { void ChromotingJniInstance::Disconnect() {
if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) {
jni_runtime_->display_task_runner()->PostTask( jni_runtime_->display_task_runner()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&ChromotingJniInstance::Cleanup, this)); base::Bind(&ChromotingJniInstance::Disconnect, this));
return; return;
} }
...@@ -403,8 +414,11 @@ void ChromotingJniInstance::DisconnectFromHostOnNetworkThread() { ...@@ -403,8 +414,11 @@ void ChromotingJniInstance::DisconnectFromHostOnNetworkThread() {
// |client_| must be torn down before |signaling_|. // |client_| must be torn down before |signaling_|.
client_.reset(); client_.reset();
client_.reset();
client_status_logger_.reset(); client_status_logger_.reset();
client_context_.reset();
video_renderer_.reset();
authenticator_.reset();
signaling_.reset();
} }
void ChromotingJniInstance::FetchSecret( void ChromotingJniInstance::FetchSecret(
......
...@@ -52,7 +52,7 @@ class ChromotingJniInstance ...@@ -52,7 +52,7 @@ class ChromotingJniInstance
// Terminates the current connection (if it hasn't already failed) and cleans // Terminates the current connection (if it hasn't already failed) and cleans
// up. Must be called before destruction. // up. Must be called before destruction.
void Cleanup(); void Disconnect();
// Requests the android app to fetch a third-party token. // Requests the android app to fetch a third-party token.
void FetchThirdPartyToken( void FetchThirdPartyToken(
......
...@@ -230,7 +230,7 @@ void ChromotingJniRuntime::ConnectToHost(const char* username, ...@@ -230,7 +230,7 @@ void ChromotingJniRuntime::ConnectToHost(const char* username,
void ChromotingJniRuntime::DisconnectFromHost() { void ChromotingJniRuntime::DisconnectFromHost() {
DCHECK(ui_task_runner_->BelongsToCurrentThread()); DCHECK(ui_task_runner_->BelongsToCurrentThread());
if (session_) { if (session_) {
session_->Cleanup(); session_->Disconnect();
session_ = NULL; session_ = NULL;
} }
} }
......
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