Chromium Code Reviews| Index: remoting/host/remoting_me2me_host.cc |
| diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc |
| index 3573414d075f307f6b1629097c2886d3f5603ddb..fedd5bb41e2ce6acb841c462979348176ffa18ca 100644 |
| --- a/remoting/host/remoting_me2me_host.cc |
| +++ b/remoting/host/remoting_me2me_host.cc |
| @@ -44,6 +44,8 @@ |
| #include "remoting/host/desktop_environment.h" |
| #include "remoting/host/desktop_session_connector.h" |
| #include "remoting/host/dns_blackhole_checker.h" |
| +#include "remoting/host/gcd_rest_client.h" |
| +#include "remoting/host/gcd_state_updater.h" |
| #include "remoting/host/heartbeat_sender.h" |
| #include "remoting/host/host_change_notification_listener.h" |
| #include "remoting/host/host_config.h" |
| @@ -72,6 +74,7 @@ |
| #include "remoting/protocol/pairing_registry.h" |
| #include "remoting/protocol/port_range.h" |
| #include "remoting/protocol/token_validator.h" |
| +#include "remoting/signaling/push_notification_subscriber.h" |
| #include "remoting/signaling/xmpp_signal_strategy.h" |
| #if defined(OS_POSIX) |
| @@ -304,6 +307,8 @@ class HostProcess : public ConfigWatcher::Delegate, |
| const std::string& file_name, |
| const int& line_number); |
| + bool using_gcd() { return !gcd_device_id_.empty(); } |
| + |
| scoped_ptr<ChromotingHostContext> context_; |
| // Accessed on the UI thread. |
| @@ -356,12 +361,20 @@ class HostProcess : public ConfigWatcher::Delegate, |
| // Used to specify which window to stream, if enabled. |
| webrtc::WindowId window_id_; |
| - // |heartbeat_sender_| and |signaling_connector_| have to be destroyed before |
| - // |signal_strategy_| because their destructors need to call |
| - // signal_strategy_->RemoveListener(this) |
| + // Must outlive |gcd_rest_client_| and |signaling_connector_|. |
| + scoped_ptr<OAuthTokenGetter> oauth_token_getter_; |
| + |
| + // Must outlive |gcd_state_updater_|. |
| + scoped_ptr<GcdRestClient> gcd_rest_client_; |
|
Sergey Ulanov
2015/06/03 22:25:35
Do we really need this here? Can OAuthTokenGetter
John Williams
2015/06/06 02:55:06
GcdStateUpdater could own it. It might even make
Sergey Ulanov
2015/06/08 17:02:31
I still think it's better to move ownership of Gcd
|
| + |
| + // Must outlive |signaling_connector_|, |gcd_subscriber_|, and |
| + // |heartbeat_sender_|. |
| scoped_ptr<SignalStrategy> signal_strategy_; |
| + |
| scoped_ptr<SignalingConnector> signaling_connector_; |
| scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| + scoped_ptr<GcdStateUpdater> gcd_state_updater_; |
| + scoped_ptr<PushNotificationSubscriber> gcd_subscriber_; |
| scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
| scoped_ptr<HostStatusLogger> host_status_logger_; |
| @@ -1304,8 +1317,14 @@ bool HostProcess::OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies) { |
| } |
| void HostProcess::InitializeSignaling() { |
| - DCHECK(!host_id_.empty()); // |ApplyConfig| should already have been run. |
| + DCHECK(!host_id_.empty()); // ApplyConfig() should already have been run. |
| DCHECK(!signal_strategy_); |
| + DCHECK(!oauth_token_getter_); |
| + DCHECK(!signaling_connector_); |
| + DCHECK(!gcd_rest_client_); |
| + DCHECK(!gcd_state_updater_); |
| + DCHECK(!gcd_subscriber_); |
| + DCHECK(!heartbeat_sender_); |
| // Create SignalStrategy. |
| XmppSignalStrategy* xmpp_signal_strategy = new XmppSignalStrategy( |
| @@ -1320,21 +1339,43 @@ void HostProcess::InitializeSignaling() { |
| new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username, |
| oauth_refresh_token_, |
| use_service_account_)); |
| - scoped_ptr<OAuthTokenGetter> oauth_token_getter(new OAuthTokenGetter( |
| + oauth_token_getter_.reset(new OAuthTokenGetter( |
| oauth_credentials.Pass(), context_->url_request_context_getter(), false, |
| - gcd_device_id_.empty())); |
| + !using_gcd())); |
| signaling_connector_.reset(new SignalingConnector( |
| xmpp_signal_strategy, dns_blackhole_checker.Pass(), |
| - oauth_token_getter.Pass(), |
| + oauth_token_getter_.get(), |
| base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); |
| - // Create HeartbeatSender. |
| - heartbeat_sender_.reset(new HeartbeatSender( |
| - base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), |
| - base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), |
| - host_id_, xmpp_signal_strategy, key_pair_, directory_bot_jid_)); |
| + if (using_gcd()) { |
| + // Create objects to manage GCD state. |
| + ServiceUrls* service_urls = ServiceUrls::GetInstance(); |
| + gcd_rest_client_.reset(new GcdRestClient( |
| + service_urls->gcd_base_url(), gcd_device_id_, |
| + context_->url_request_context_getter(), oauth_token_getter_.get())); |
| + gcd_state_updater_.reset( |
| + new GcdStateUpdater(base::Bind(&HostProcess::OnHeartbeatSuccessful, |
| + base::Unretained(this)), |
| + // TODO(jrw): Add callback for |
| + // OnUnknownHostIdError. |
| + signal_strategy_.get(), gcd_rest_client_.get())); |
| + |
| + PushNotificationSubscriber::Subscription sub; |
| + sub.channel = "cloud_devices"; |
| + PushNotificationSubscriber::SubscriptionList subs; |
| + subs.push_back(sub); |
| + gcd_subscriber_.reset( |
| + new PushNotificationSubscriber(signal_strategy_.get(), subs)); |
| + } else { |
| + // Create HeartbeatSender. |
| + heartbeat_sender_.reset(new HeartbeatSender( |
| + base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)), |
| + base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)), |
| + host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_)); |
| + } |
| } |
| + |
|
Sergey Ulanov
2015/06/03 22:25:35
remove extra empty line
John Williams
2015/06/06 02:55:06
Done.
|
| void HostProcess::StartHostIfReady() { |
| DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| DCHECK_EQ(state_, HOST_STARTING); |
| @@ -1352,6 +1393,7 @@ void HostProcess::StartHostIfReady() { |
| void HostProcess::StartHost() { |
| DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| DCHECK(!host_); |
| + DCHECK(!gcd_rest_client_); |
| SetState(HOST_STARTED); |
| @@ -1408,9 +1450,14 @@ void HostProcess::StartHost() { |
| host_change_notification_listener_.reset(new HostChangeNotificationListener( |
| this, host_id_, signal_strategy_.get(), directory_bot_jid_)); |
| - host_status_logger_.reset( |
| - new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::ME2ME, |
| - signal_strategy_.get(), directory_bot_jid_)); |
| + if (using_gcd()) { |
| + // TODO(jrw): Implement logging for GCD hosts. |
| + HOST_LOG << "Logging not implemented for GCD hosts."; |
| + } else { |
| + host_status_logger_.reset(new HostStatusLogger( |
| + host_->AsWeakPtr(), ServerLogEntry::ME2ME, |
| + signal_strategy_.get(), directory_bot_jid_)); |
| + } |
| // Set up reporting the host status notifications. |
| #if defined(REMOTING_MULTI_PROCESS) |
| @@ -1484,10 +1531,18 @@ void HostProcess::GoOffline(const std::string& host_offline_reason) { |
| InitializeSignaling(); |
| HOST_LOG << "SendHostOfflineReason: sending " << host_offline_reason << "."; |
| - heartbeat_sender_->SetHostOfflineReason( |
| - host_offline_reason, |
| - base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds), |
| - base::Bind(&HostProcess::OnHostOfflineReasonAck, this)); |
| + if (heartbeat_sender_) { |
| + heartbeat_sender_->SetHostOfflineReason( |
| + host_offline_reason, |
| + base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds), |
| + base::Bind(&HostProcess::OnHostOfflineReasonAck, this)); |
| + } |
| + if (gcd_state_updater_) { |
| + gcd_state_updater_->SetHostOfflineReason( |
| + host_offline_reason, |
| + base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds), |
| + base::Bind(&HostProcess::OnHostOfflineReasonAck, this)); |
| + } |
| return; // Shutdown will resume after OnHostOfflineReasonAck. |
| } |
| @@ -1503,8 +1558,12 @@ void HostProcess::OnHostOfflineReasonAck(bool success) { |
| HOST_LOG << "SendHostOfflineReason " << (success ? "succeeded." : "failed."); |
| heartbeat_sender_.reset(); |
| + oauth_token_getter_.reset(); |
| signaling_connector_.reset(); |
| signal_strategy_.reset(); |
| + gcd_state_updater_.reset(); |
| + gcd_subscriber_.reset(); |
| + gcd_rest_client_.reset(); |
| if (state_ == HOST_GOING_OFFLINE_TO_RESTART) { |
| SetState(HOST_STARTING); |