Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Unified Diff: remoting/host/heartbeat_sender.cc

Issue 9004050: Move signaling connection creation out of ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/heartbeat_sender.h ('k') | remoting/host/heartbeat_sender_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/heartbeat_sender.cc
diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc
index 2a7d8ac0ad0159442c605ff93c5ecb108c182a24..4c883684bbd36f698cfaa79d5afaef7e0052ac6d 100644
--- a/remoting/host/heartbeat_sender.cc
+++ b/remoting/host/heartbeat_sender.cc
@@ -34,68 +34,61 @@ const char kSetIntervalTag[] = "set-interval";
const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes.
}
-HeartbeatSender::HeartbeatSender(base::MessageLoopProxy* message_loop,
- MutableHostConfig* config)
-
+HeartbeatSender::HeartbeatSender()
: state_(CREATED),
- message_loop_(message_loop),
- config_(config),
+ signal_strategy_(NULL),
interval_ms_(kDefaultHeartbeatIntervalMs) {
- DCHECK(config_);
}
HeartbeatSender::~HeartbeatSender() {
- DCHECK(state_ == CREATED || state_ == INITIALIZED || state_ == STOPPED);
+ if (signal_strategy_)
+ signal_strategy_->RemoveListener(this);
}
-bool HeartbeatSender::Init() {
+bool HeartbeatSender::Init(SignalStrategy* signal_strategy,
+ MutableHostConfig* config) {
DCHECK(state_ == CREATED);
- if (!config_->GetString(kHostIdConfigPath, &host_id_)) {
+ if (!config->GetString(kHostIdConfigPath, &host_id_)) {
LOG(ERROR) << "host_id is not defined in the config.";
return false;
}
- if (!key_pair_.Load(config_)) {
+ if (!key_pair_.Load(config)) {
return false;
}
- state_ = INITIALIZED;
-
- return true;
-}
-
-void HeartbeatSender::OnSignallingConnected(SignalStrategy* signal_strategy) {
- DCHECK(message_loop_->BelongsToCurrentThread());
- DCHECK(state_ == INITIALIZED || state_ == STOPPED);
- state_ = STARTED;
+ DCHECK(signal_strategy);
+ signal_strategy_ = signal_strategy;
+ signal_strategy_->AddListener(this);
- full_jid_ = signal_strategy->GetLocalJid();
+ state_ = INITIALIZED;
- iq_sender_.reset(new IqSender(signal_strategy));
+ // Update the state if the |signal_strategy_| is already connected.
+ OnSignalStrategyStateChange(signal_strategy_->GetState());
- DoSendStanza();
- timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(interval_ms_), this,
- &HeartbeatSender::DoSendStanza);
+ return true;
}
-void HeartbeatSender::OnSignallingDisconnected() {
- DCHECK(message_loop_->BelongsToCurrentThread());
- state_ = STOPPED;
- request_.reset();
- iq_sender_.reset();
- timer_.Stop();
+void HeartbeatSender::OnSignalStrategyStateChange(SignalStrategy::State state) {
+ if (state == SignalStrategy::CONNECTED) {
+ DCHECK(state_ == INITIALIZED || state_ == STOPPED);
+ state_ = STARTED;
+
+ iq_sender_.reset(new IqSender(signal_strategy_));
+
+ DoSendStanza();
+ timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(interval_ms_),
+ this, &HeartbeatSender::DoSendStanza);
+ } else if (state == SignalStrategy::DISCONNECTED) {
+ state_ = STOPPED;
+ request_.reset();
+ iq_sender_.reset();
+ timer_.Stop();
+ }
}
-// Ignore any notifications other than signalling
-// connected/disconnected events.
-void HeartbeatSender::OnAccessDenied() { }
-void HeartbeatSender::OnClientAuthenticated(const std::string& jid) { }
-void HeartbeatSender::OnClientDisconnected(const std::string& jid) { }
-void HeartbeatSender::OnShutdown() { }
-
void HeartbeatSender::DoSendStanza() {
- DCHECK(message_loop_->BelongsToCurrentThread());
DCHECK_EQ(state_, STARTED);
VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid;
@@ -106,8 +99,6 @@ void HeartbeatSender::DoSendStanza() {
}
void HeartbeatSender::ProcessResponse(const XmlElement* response) {
- DCHECK(message_loop_->BelongsToCurrentThread());
-
std::string type = response->Attr(buzz::QN_TYPE);
if (type == buzz::STR_ERROR) {
LOG(ERROR) << "Received error in response to heartbeat: "
@@ -167,7 +158,7 @@ XmlElement* HeartbeatSender::CreateSignature() {
signature_tag->AddAttr(
QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str);
- std::string message = full_jid_ + ' ' + time_str;
+ std::string message = signal_strategy_->GetLocalJid() + ' ' + time_str;
std::string signature(key_pair_.GetSignature(message));
signature_tag->AddText(signature);
« no previous file with comments | « remoting/host/heartbeat_sender.h ('k') | remoting/host/heartbeat_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698