| Index: remoting/host/plugin/host_script_object.cc
|
| diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
|
| index 705b6ebcec19c723b750bd6fffccae4c2fb6bd7c..d25f89cdb5117907534863d57d482c9ac284b499 100644
|
| --- a/remoting/host/plugin/host_script_object.cc
|
| +++ b/remoting/host/plugin/host_script_object.cc
|
| @@ -67,7 +67,6 @@ HostNPScriptObject::HostNPScriptObject(
|
| np_thread_id_(base::PlatformThread::CurrentId()),
|
| plugin_message_loop_proxy_(
|
| new PluginMessageLoopProxy(plugin_thread_delegate)),
|
| - host_context_(plugin_message_loop_proxy_),
|
| failed_login_attempts_(0),
|
| daemon_controller_(DaemonController::Create()),
|
| disconnected_event_(true, false),
|
| @@ -97,25 +96,32 @@ HostNPScriptObject::~HostNPScriptObject() {
|
| nat_policy_.reset();
|
| }
|
|
|
| - // Disconnect synchronously. We cannot disconnect asynchronously
|
| - // here because |host_context_| needs to be stopped on the plugin
|
| - // thread, but the plugin thread may not exist after the instance
|
| - // is destroyed.
|
| - disconnected_event_.Reset();
|
| - DisconnectInternal();
|
| - disconnected_event_.Wait();
|
| + if (host_context_.get()) {
|
| + // Disconnect synchronously. We cannot disconnect asynchronously
|
| + // here because |host_context_| needs to be stopped on the plugin
|
| + // thread, but the plugin thread may not exist after the instance
|
| + // is destroyed.
|
| + disconnected_event_.Reset();
|
| + DisconnectInternal();
|
| + disconnected_event_.Wait();
|
|
|
| - // Stop all threads.
|
| - host_context_.Stop();
|
| + // Stops all threads.
|
| + host_context_.reset();
|
| + }
|
| }
|
|
|
| bool HostNPScriptObject::Init() {
|
| DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread());
|
| VLOG(2) << "Init";
|
| - // TODO(wez): This starts a bunch of threads, which might fail.
|
| - host_context_.Start();
|
| +
|
| + host_context_.reset(new ChromotingHostContext(plugin_message_loop_proxy_));
|
| + if (!host_context_->Start()) {
|
| + host_context_.reset();
|
| + return false;
|
| + }
|
| +
|
| nat_policy_.reset(
|
| - policy_hack::NatPolicy::Create(host_context_.network_message_loop()));
|
| + policy_hack::NatPolicy::Create(host_context_->network_message_loop()));
|
| nat_policy_->StartWatching(
|
| base::Bind(&HostNPScriptObject::OnNatPolicyUpdate,
|
| base::Unretained(this)));
|
| @@ -334,7 +340,7 @@ bool HostNPScriptObject::Enumerate(std::vector<std::string>* values) {
|
| }
|
|
|
| void HostNPScriptObject::OnAccessDenied(const std::string& jid) {
|
| - DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread());
|
| + DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread());
|
|
|
| ++failed_login_attempts_;
|
| if (failed_login_attempts_ == kMaxLoginAttempts) {
|
| @@ -343,7 +349,7 @@ void HostNPScriptObject::OnAccessDenied(const std::string& jid) {
|
| }
|
|
|
| void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) {
|
| - DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread());
|
| + DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread());
|
|
|
| if (state_ == kDisconnecting) {
|
| // Ignore the new connection if we are disconnecting.
|
| @@ -359,13 +365,13 @@ void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) {
|
| }
|
|
|
| void HostNPScriptObject::OnClientDisconnected(const std::string& jid) {
|
| - DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread());
|
| + DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread());
|
| client_username_.clear();
|
| DisconnectInternal();
|
| }
|
|
|
| void HostNPScriptObject::OnShutdown() {
|
| - DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread());
|
| + DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread());
|
|
|
| register_request_.reset();
|
| log_to_server_.reset();
|
| @@ -420,8 +426,8 @@ bool HostNPScriptObject::Connect(const NPVariant* args,
|
| void HostNPScriptObject::ReadPolicyAndConnect(const std::string& uid,
|
| const std::string& auth_token,
|
| const std::string& auth_service) {
|
| - if (!host_context_.network_message_loop()->BelongsToCurrentThread()) {
|
| - host_context_.network_message_loop()->PostTask(
|
| + if (!host_context_->network_message_loop()->BelongsToCurrentThread()) {
|
| + host_context_->network_message_loop()->PostTask(
|
| FROM_HERE, base::Bind(
|
| &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this),
|
| uid, auth_token, auth_service));
|
| @@ -446,8 +452,8 @@ void HostNPScriptObject::FinishConnectMainThread(
|
| const std::string& uid,
|
| const std::string& auth_token,
|
| const std::string& auth_service) {
|
| - if (host_context_.main_message_loop() != MessageLoop::current()) {
|
| - host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind(
|
| + if (host_context_->main_message_loop() != MessageLoop::current()) {
|
| + host_context_->main_message_loop()->PostTask(FROM_HERE, base::Bind(
|
| &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this),
|
| uid, auth_token, auth_service));
|
| return;
|
| @@ -458,7 +464,7 @@ void HostNPScriptObject::FinishConnectMainThread(
|
| // TODO(sergeyu): Fix DesktopEnvironment so that it can be created
|
| // on either the UI or the network thread so that we can avoid
|
| // jumping to the main thread here.
|
| - desktop_environment_.reset(DesktopEnvironment::Create(&host_context_));
|
| + desktop_environment_.reset(DesktopEnvironment::Create(host_context_.get()));
|
|
|
| FinishConnectNetworkThread(uid, auth_token, auth_service);
|
| }
|
| @@ -467,8 +473,8 @@ void HostNPScriptObject::FinishConnectNetworkThread(
|
| const std::string& uid,
|
| const std::string& auth_token,
|
| const std::string& auth_service) {
|
| - if (!host_context_.network_message_loop()->BelongsToCurrentThread()) {
|
| - host_context_.network_message_loop()->PostTask(FROM_HERE, base::Bind(
|
| + if (!host_context_->network_message_loop()->BelongsToCurrentThread()) {
|
| + host_context_->network_message_loop()->PostTask(FROM_HERE, base::Bind(
|
| &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this),
|
| uid, auth_token, auth_service));
|
| return;
|
| @@ -491,7 +497,7 @@ void HostNPScriptObject::FinishConnectNetworkThread(
|
|
|
| // Create XMPP connection.
|
| scoped_ptr<SignalStrategy> signal_strategy(
|
| - new XmppSignalStrategy(host_context_.jingle_thread(), uid,
|
| + new XmppSignalStrategy(host_context_->jingle_thread(), uid,
|
| auth_token, auth_service));
|
|
|
| // Request registration of the host for support.
|
| @@ -508,13 +514,13 @@ void HostNPScriptObject::FinishConnectNetworkThread(
|
| // Create the Host.
|
| LOG(INFO) << "NAT state: " << nat_traversal_enabled_;
|
| host_ = new ChromotingHost(
|
| - &host_context_, signal_strategy_.get(), desktop_environment_.get(),
|
| + host_context_.get(), signal_strategy_.get(), desktop_environment_.get(),
|
| protocol::NetworkSettings(nat_traversal_enabled_));
|
| host_->AddStatusObserver(this);
|
| log_to_server_.reset(
|
| new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get()));
|
| it2me_host_user_interface_.reset(
|
| - new It2MeHostUserInterface(host_.get(), &host_context_));
|
| + new It2MeHostUserInterface(host_.get(), host_context_.get()));
|
| it2me_host_user_interface_->Init();
|
|
|
| {
|
| @@ -605,8 +611,8 @@ bool HostNPScriptObject::StopDaemon(const NPVariant* args,
|
| }
|
|
|
| void HostNPScriptObject::DisconnectInternal() {
|
| - if (!host_context_.network_message_loop()->BelongsToCurrentThread()) {
|
| - host_context_.network_message_loop()->PostTask(
|
| + if (!host_context_->network_message_loop()->BelongsToCurrentThread()) {
|
| + host_context_->network_message_loop()->PostTask(
|
| FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal,
|
| base::Unretained(this)));
|
| return;
|
| @@ -634,7 +640,7 @@ void HostNPScriptObject::DisconnectInternal() {
|
| // synchronously, bug SignalStrategy::Listener handlers are not
|
| // allowed to destroy SignalStrategy, so post task to call
|
| // Shutdown() later.
|
| - host_context_.network_message_loop()->PostTask(
|
| + host_context_->network_message_loop()->PostTask(
|
| FROM_HERE, base::Bind(
|
| &ChromotingHost::Shutdown, host_,
|
| base::Bind(&HostNPScriptObject::OnShutdownFinished,
|
| @@ -643,14 +649,14 @@ void HostNPScriptObject::DisconnectInternal() {
|
| }
|
|
|
| void HostNPScriptObject::OnShutdownFinished() {
|
| - DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread());
|
| + DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread());
|
|
|
| disconnected_event_.Signal();
|
| }
|
|
|
| void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) {
|
| - if (!host_context_.network_message_loop()->BelongsToCurrentThread()) {
|
| - host_context_.network_message_loop()->PostTask(
|
| + if (!host_context_->network_message_loop()->BelongsToCurrentThread()) {
|
| + host_context_->network_message_loop()->PostTask(
|
| FROM_HERE,
|
| base::Bind(&HostNPScriptObject::OnNatPolicyUpdate,
|
| base::Unretained(this), nat_traversal_enabled));
|
| @@ -683,7 +689,7 @@ void HostNPScriptObject::OnReceivedSupportID(
|
| bool success,
|
| const std::string& support_id,
|
| const base::TimeDelta& lifetime) {
|
| - DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread());
|
| + DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread());
|
|
|
| if (!success) {
|
| SetState(kError);
|
| @@ -709,7 +715,7 @@ void HostNPScriptObject::OnReceivedSupportID(
|
| }
|
|
|
| void HostNPScriptObject::SetState(State state) {
|
| - DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread());
|
| + DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread());
|
| switch (state_) {
|
| case kDisconnected:
|
| DCHECK(state == kStarting ||
|
|
|