| Index: remoting/host/remoting_me2me_host.cc
|
| diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
|
| index d216b5a72e085c526919ff6d59c1e99e48c8b1a3..e4eafc4e919b7e6574926ad35050c812fc2b92f3 100644
|
| --- a/remoting/host/remoting_me2me_host.cc
|
| +++ b/remoting/host/remoting_me2me_host.cc
|
| @@ -27,7 +27,6 @@
|
| #include "ipc/ipc_channel_proxy.h"
|
| #include "ipc/ipc_listener.h"
|
| #include "media/base/media.h"
|
| -#include "net/base/network_change_notifier.h"
|
| #include "net/socket/client_socket_factory.h"
|
| #include "net/socket/ssl_server_socket.h"
|
| #include "net/url_request/url_fetcher.h"
|
| @@ -46,8 +45,6 @@
|
| #include "remoting/host/config_watcher.h"
|
| #include "remoting/host/desktop_environment.h"
|
| #include "remoting/host/desktop_session_connector.h"
|
| -#include "remoting/host/dns_blackhole_checker.h"
|
| -#include "remoting/host/heartbeat_sender.h"
|
| #include "remoting/host/host_change_notification_listener.h"
|
| #include "remoting/host/host_config.h"
|
| #include "remoting/host/host_event_logger.h"
|
| @@ -60,10 +57,10 @@
|
| #include "remoting/host/json_host_config.h"
|
| #include "remoting/host/logging.h"
|
| #include "remoting/host/me2me_desktop_environment.h"
|
| +#include "remoting/host/minimum_heartbeat_supporter.h"
|
| #include "remoting/host/pairing_registry_delegate.h"
|
| #include "remoting/host/policy_hack/policy_watcher.h"
|
| #include "remoting/host/session_manager_factory.h"
|
| -#include "remoting/host/signaling_connector.h"
|
| #include "remoting/host/single_window_desktop_environment.h"
|
| #include "remoting/host/token_validator_factory_impl.h"
|
| #include "remoting/host/usage_stats_consent.h"
|
| @@ -142,7 +139,7 @@ namespace remoting {
|
|
|
| class HostProcess
|
| : public ConfigWatcher::Delegate,
|
| - public HeartbeatSender::Listener,
|
| + public MinimumHeartbeatSupporter::Listener,
|
| public HostChangeNotificationListener::Listener,
|
| public IPC::Listener,
|
| public base::RefCountedThreadSafe<HostProcess> {
|
| @@ -158,9 +155,10 @@ class HostProcess
|
| virtual bool OnMessageReceived(const IPC::Message& message) override;
|
| virtual void OnChannelError() override;
|
|
|
| - // HeartbeatSender::Listener overrides.
|
| + // MinimumHeartbeatSupporter::Listener overrides.
|
| virtual void OnHeartbeatSuccessful() override;
|
| virtual void OnUnknownHostIdError() override;
|
| + virtual void OnAuthFailed() override;
|
|
|
| // HostChangeNotificationListener::Listener overrides.
|
| virtual void OnHostDeleted() override;
|
| @@ -247,17 +245,15 @@ class HostProcess
|
| bool OnPairingPolicyUpdate(base::DictionaryValue* policies);
|
| bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies);
|
|
|
| - void StartHost();
|
| + scoped_refptr<MinimumHeartbeatSupporter> CreateMinimumHeartbeatSupporter();
|
|
|
| - void OnAuthFailed();
|
| + void StartHost();
|
|
|
| void RestartHost();
|
|
|
| // Stops the host and shuts down the process with the specified |exit_code|.
|
| void ShutdownHost(HostExitCodes exit_code);
|
|
|
| - void ScheduleHostShutdown();
|
| -
|
| void ShutdownOnNetworkThread();
|
|
|
| // Crashes the process in response to a daemon's request. The daemon passes
|
| @@ -269,9 +265,6 @@ class HostProcess
|
|
|
| scoped_ptr<ChromotingHostContext> context_;
|
|
|
| - // Created on the UI thread but used from the network thread.
|
| - scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
|
| -
|
| // Accessed on the UI thread.
|
| scoped_ptr<IPC::ChannelProxy> daemon_channel_;
|
|
|
| @@ -321,10 +314,7 @@ class HostProcess
|
| // Used to specify which window to stream, if enabled.
|
| webrtc::WindowId window_id_;
|
|
|
| - scoped_ptr<OAuthTokenGetter> oauth_token_getter_;
|
| - scoped_ptr<XmppSignalStrategy> signal_strategy_;
|
| - scoped_ptr<SignalingConnector> signaling_connector_;
|
| - scoped_ptr<HeartbeatSender> heartbeat_sender_;
|
| + scoped_refptr<MinimumHeartbeatSupporter> minimum_heartbeat_supporter_;
|
| scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_;
|
| scoped_ptr<HostStatusLogger> host_status_logger_;
|
| scoped_ptr<HostEventLogger> host_event_logger_;
|
| @@ -751,7 +741,6 @@ void HostProcess::ShutdownOnUiThread() {
|
| DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
|
|
|
| // Tear down resources that need to be torn down on the UI thread.
|
| - network_change_notifier_.reset();
|
| daemon_channel_.reset();
|
| desktop_environment_factory_.reset();
|
|
|
| @@ -767,12 +756,13 @@ void HostProcess::ShutdownOnUiThread() {
|
| #endif
|
| }
|
|
|
| -// Overridden from HeartbeatSender::Listener
|
| +// Overridden from MinimumHeartbeatSupporter::Listener
|
| void HostProcess::OnUnknownHostIdError() {
|
| LOG(ERROR) << "Host ID not found.";
|
| ShutdownHost(kInvalidHostIdExitCode);
|
| }
|
|
|
| +// Overridden from MinimumHeartbeatSupporter::Listener
|
| void HostProcess::OnHeartbeatSuccessful() {
|
| HOST_LOG << "Host ready to receive connections.";
|
| #if defined(OS_POSIX)
|
| @@ -854,7 +844,8 @@ bool HostProcess::ApplyConfig(scoped_ptr<JsonHostConfig> config) {
|
| }
|
|
|
| if (!oauth_refresh_token_.empty()) {
|
| - // SignalingConnector is responsible for getting OAuth token.
|
| + // SignalingConnector (inside MinimumHeartbeatSupporter) is responsible for
|
| + // getting OAuth token.
|
| xmpp_server_config_.auth_token = "";
|
| xmpp_server_config_.auth_service = "oauth2";
|
| } else if (!config->GetString(kXmppAuthServiceConfigPath,
|
| @@ -1234,44 +1225,31 @@ bool HostProcess::OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies) {
|
| return true;
|
| }
|
|
|
| +scoped_refptr<MinimumHeartbeatSupporter>
|
| +HostProcess::CreateMinimumHeartbeatSupporter() {
|
| + DCHECK(!host_id_.empty()); // assumming |ApplyConfig| has already been run
|
| + return new MinimumHeartbeatSupporter(
|
| + context_.get(),
|
| + xmpp_server_config_,
|
| + talkgadget_prefix_,
|
| + host_id_,
|
| + key_pair_,
|
| + directory_bot_jid_,
|
| + oauth_refresh_token_,
|
| + use_service_account_);
|
| +}
|
| +
|
| void HostProcess::StartHost() {
|
| DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
|
| DCHECK(!host_);
|
| - DCHECK(!signal_strategy_.get());
|
| + DCHECK(!minimum_heartbeat_supporter_.get());
|
| +
|
| DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART ||
|
| state_ == HOST_STOPPED) << state_;
|
| state_ = HOST_STARTED;
|
|
|
| - signal_strategy_.reset(
|
| - new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
|
| - context_->url_request_context_getter(),
|
| - xmpp_server_config_));
|
| -
|
| - scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(
|
| - new DnsBlackholeChecker(context_->url_request_context_getter(),
|
| - talkgadget_prefix_));
|
| -
|
| - // Create a NetworkChangeNotifier for use by the signaling connector.
|
| - network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
|
| -
|
| - signaling_connector_.reset(new SignalingConnector(
|
| - signal_strategy_.get(),
|
| - dns_blackhole_checker.Pass(),
|
| - base::Bind(&HostProcess::OnAuthFailed, this)));
|
| -
|
| - if (!oauth_refresh_token_.empty()) {
|
| - scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials;
|
| - oauth_credentials.reset(
|
| - new OAuthTokenGetter::OAuthCredentials(
|
| - xmpp_server_config_.username, oauth_refresh_token_,
|
| - use_service_account_));
|
| -
|
| - oauth_token_getter_.reset(new OAuthTokenGetter(
|
| - oauth_credentials.Pass(), context_->url_request_context_getter(),
|
| - false));
|
| -
|
| - signaling_connector_->EnableOAuth(oauth_token_getter_.get());
|
| - }
|
| + minimum_heartbeat_supporter_ = CreateMinimumHeartbeatSupporter();
|
| + minimum_heartbeat_supporter_->SetListener(this);
|
|
|
| uint32 network_flags = 0;
|
| if (allow_nat_traversal_) {
|
| @@ -1295,10 +1273,12 @@ void HostProcess::StartHost() {
|
| }
|
|
|
| host_.reset(new ChromotingHost(
|
| - signal_strategy_.get(),
|
| + minimum_heartbeat_supporter_->GetSignalStrategy(),
|
| desktop_environment_factory_.get(),
|
| - CreateHostSessionManager(signal_strategy_.get(), network_settings,
|
| - context_->url_request_context_getter()),
|
| + CreateHostSessionManager(
|
| + minimum_heartbeat_supporter_->GetSignalStrategy(),
|
| + network_settings,
|
| + context_->url_request_context_getter()),
|
| context_->audio_task_runner(),
|
| context_->input_task_runner(),
|
| context_->video_capture_task_runner(),
|
| @@ -1325,16 +1305,19 @@ void HostProcess::StartHost() {
|
| host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20));
|
| #endif
|
|
|
| - heartbeat_sender_.reset(new HeartbeatSender(
|
| - this, host_id_, signal_strategy_.get(), key_pair_,
|
| - directory_bot_jid_));
|
| -
|
| - host_change_notification_listener_.reset(new HostChangeNotificationListener(
|
| - this, host_id_, signal_strategy_.get(), directory_bot_jid_));
|
| + host_change_notification_listener_.reset(
|
| + new HostChangeNotificationListener(
|
| + this,
|
| + host_id_,
|
| + minimum_heartbeat_supporter_->GetSignalStrategy(),
|
| + directory_bot_jid_));
|
|
|
| host_status_logger_.reset(
|
| - new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::ME2ME,
|
| - signal_strategy_.get(), directory_bot_jid_));
|
| + new HostStatusLogger(
|
| + host_->AsWeakPtr(),
|
| + ServerLogEntry::ME2ME,
|
| + minimum_heartbeat_supporter_->GetSignalStrategy(),
|
| + directory_bot_jid_));
|
|
|
| // Set up reporting the host status notifications.
|
| #if defined(REMOTING_MULTI_PROCESS)
|
| @@ -1351,6 +1334,7 @@ void HostProcess::StartHost() {
|
| CreateAuthenticatorFactory();
|
| }
|
|
|
| +// Overridden from MinimumHeartbeatSupporter::Listener
|
| void HostProcess::OnAuthFailed() {
|
| ShutdownHost(kInvalidOauthCredentialsExitCode);
|
| }
|
| @@ -1371,14 +1355,23 @@ void HostProcess::ShutdownHost(HostExitCodes exit_code) {
|
| switch (state_) {
|
| case HOST_INITIALIZING:
|
| state_ = HOST_STOPPING;
|
| + {
|
| + DCHECK(!minimum_heartbeat_supporter_.get());
|
| + scoped_refptr<MinimumHeartbeatSupporter> tmpHeartbeatSupporter =
|
| + CreateMinimumHeartbeatSupporter();
|
| + tmpHeartbeatSupporter->SendHostOfflineReason(
|
| + ExitCodeToString(exit_code),
|
| + base::TimeDelta::FromSeconds(30) /* timeout */);
|
| + }
|
| ShutdownOnNetworkThread();
|
| break;
|
|
|
| case HOST_STARTED:
|
| state_ = HOST_STOPPING;
|
| - heartbeat_sender_->SetHostOfflineReason(
|
| - ExitCodeToString(exit_code), base::Bind(base::DoNothing));
|
| - ScheduleHostShutdown();
|
| + minimum_heartbeat_supporter_->SendHostOfflineReason(
|
| + ExitCodeToString(exit_code),
|
| + base::TimeDelta::FromSeconds(30) /* timeout */);
|
| + ShutdownOnNetworkThread();
|
| break;
|
|
|
| case HOST_STOPPING_TO_RESTART:
|
| @@ -1392,28 +1385,17 @@ void HostProcess::ShutdownHost(HostExitCodes exit_code) {
|
| }
|
| }
|
|
|
| -// TODO(weitaosu): shut down the host once we get an ACK for the offline status
|
| -// XMPP message.
|
| -void HostProcess::ScheduleHostShutdown() {
|
| - // Delay the shutdown by 2 second to allow SendOfflineStatus to complete.
|
| - context_->network_task_runner()->PostDelayedTask(
|
| - FROM_HERE,
|
| - base::Bind(&HostProcess::ShutdownOnNetworkThread, base::Unretained(this)),
|
| - base::TimeDelta::FromSeconds(2));
|
| -}
|
| -
|
| void HostProcess::ShutdownOnNetworkThread() {
|
| DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
|
|
|
| host_.reset();
|
| host_event_logger_.reset();
|
| host_status_logger_.reset();
|
| - heartbeat_sender_.reset();
|
| + if (minimum_heartbeat_supporter_.get()) {
|
| + minimum_heartbeat_supporter_->SetListener(nullptr);
|
| + minimum_heartbeat_supporter_ = nullptr;
|
| + }
|
| host_change_notification_listener_.reset();
|
| - signaling_connector_.reset();
|
| - oauth_token_getter_.reset();
|
| - signal_strategy_.reset();
|
| - network_change_notifier_.reset();
|
|
|
| if (state_ == HOST_STOPPING_TO_RESTART) {
|
| StartHost();
|
|
|