summaryrefslogtreecommitdiffstats
path: root/remoting/client
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-24 21:51:42 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-24 21:51:42 +0000
commit9c910e4187919cbb2d0dccdb8e720de869dabd2f (patch)
tree8791c509540b91971d63d6a22fa166de140d5a8c /remoting/client
parent5ee0a182a58cf59c24ccd485a0804e3f327ef412 (diff)
downloadchromium_src-9c910e4187919cbb2d0dccdb8e720de869dabd2f.zip
chromium_src-9c910e4187919cbb2d0dccdb8e720de869dabd2f.tar.gz
chromium_src-9c910e4187919cbb2d0dccdb8e720de869dabd2f.tar.bz2
Cleanup client shutdown sequence.
BUG=None TEST=Client doesn't crash when reloading the tab. Review URL: http://codereview.chromium.org/7241016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90443 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client')
-rw-r--r--remoting/client/chromoting_client.cc14
-rw-r--r--remoting/client/chromoting_client.h4
-rw-r--r--remoting/client/plugin/chromoting_instance.cc15
3 files changed, 26 insertions, 7 deletions
diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc
index 8161089..d7eee8e 100644
--- a/remoting/client/chromoting_client.cc
+++ b/remoting/client/chromoting_client.cc
@@ -4,6 +4,7 @@
#include "remoting/client/chromoting_client.h"
+#include "base/bind.h"
#include "base/message_loop.h"
#include "remoting/base/tracer.h"
#include "remoting/client/chromoting_view.h"
@@ -57,17 +58,22 @@ void ChromotingClient::Start(scoped_refptr<XmppProxy> xmpp_proxy) {
}
}
-void ChromotingClient::Stop() {
+void ChromotingClient::Stop(const base::Closure& shutdown_task) {
if (message_loop() != MessageLoop::current()) {
message_loop()->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &ChromotingClient::Stop));
+ FROM_HERE, base::Bind(&ChromotingClient::Stop,
+ base::Unretained(this), shutdown_task));
return;
}
- connection_->Disconnect();
+ connection_->Disconnect(base::Bind(&ChromotingClient::OnDisconnected,
+ base::Unretained(this), shutdown_task));
+}
+void ChromotingClient::OnDisconnected(const base::Closure& shutdown_task) {
view_->TearDown();
+
+ shutdown_task.Run();
}
void ChromotingClient::ClientDone() {
diff --git a/remoting/client/chromoting_client.h b/remoting/client/chromoting_client.h
index f485e97..67bda81 100644
--- a/remoting/client/chromoting_client.h
+++ b/remoting/client/chromoting_client.h
@@ -51,7 +51,7 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
virtual ~ChromotingClient();
void Start(scoped_refptr<XmppProxy> xmpp_proxy);
- void Stop();
+ void Stop(const base::Closure& shutdown_task);
void ClientDone();
// Return the stats recorded by this client.
@@ -109,6 +109,8 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
// the packet will start to be processed.
void OnPacketDone(bool last_packet, base::Time decode_start);
+ void OnDisconnected(const base::Closure& shutdown_task);
+
// The following are not owned by this class.
ClientConfig config_;
ClientContext* context_;
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc
index c1d7548..459c701 100644
--- a/remoting/client/plugin/chromoting_instance.cc
+++ b/remoting/client/plugin/chromoting_instance.cc
@@ -7,9 +7,11 @@
#include <string>
#include <vector>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/stringprintf.h"
+#include "base/synchronization/waitable_event.h"
#include "base/task.h"
#include "base/threading/thread.h"
// TODO(sergeyu): We should not depend on renderer here. Instead P2P
@@ -55,8 +57,13 @@ ChromotingInstance::ChromotingInstance(PP_Instance pp_instance)
}
ChromotingInstance::~ChromotingInstance() {
+ DCHECK(CurrentlyOnPluginThread());
+
if (client_.get()) {
- client_->Stop();
+ base::WaitableEvent done_event(true, false);
+ client_->Stop(base::Bind(&base::WaitableEvent::Signal,
+ base::Unretained(&done_event)));
+ done_event.Wait();
}
// Stopping the context shutdown all chromoting threads. This is a requirement
@@ -142,7 +149,11 @@ void ChromotingInstance::Disconnect() {
logger_.Log(logging::LOG_INFO, "Disconnecting from host.");
if (client_.get()) {
- client_->Stop();
+ // TODO(sergeyu): Should we disconnect asynchronously?
+ base::WaitableEvent done_event(true, false);
+ client_->Stop(base::Bind(&base::WaitableEvent::Signal,
+ base::Unretained(&done_event)));
+ done_event.Wait();
}
GetScriptableObject()->SetConnectionInfo(STATUS_CLOSED, QUALITY_UNKNOWN);