OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/heartbeat_sender.h" | 5 #include "remoting/host/heartbeat_sender.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 DCHECK(message_loop_->BelongsToCurrentThread()); | 70 DCHECK(message_loop_->BelongsToCurrentThread()); |
71 DCHECK(state_ == INITIALIZED || state_ == STOPPED); | 71 DCHECK(state_ == INITIALIZED || state_ == STOPPED); |
72 state_ = STARTED; | 72 state_ = STARTED; |
73 | 73 |
74 full_jid_ = full_jid; | 74 full_jid_ = full_jid; |
75 request_.reset(signal_strategy->CreateIqRequest()); | 75 request_.reset(signal_strategy->CreateIqRequest()); |
76 request_->set_callback(base::Bind(&HeartbeatSender::ProcessResponse, | 76 request_->set_callback(base::Bind(&HeartbeatSender::ProcessResponse, |
77 base::Unretained(this))); | 77 base::Unretained(this))); |
78 | 78 |
79 DoSendStanza(); | 79 DoSendStanza(); |
80 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(interval_ms_), this, | 80 timer_.Start(base::TimeDelta::FromMilliseconds(interval_ms_), this, |
81 &HeartbeatSender::DoSendStanza); | 81 &HeartbeatSender::DoSendStanza); |
82 } | 82 } |
83 | 83 |
84 void HeartbeatSender::OnSignallingDisconnected() { | 84 void HeartbeatSender::OnSignallingDisconnected() { |
85 DCHECK(message_loop_->BelongsToCurrentThread()); | 85 DCHECK(message_loop_->BelongsToCurrentThread()); |
86 state_ = STOPPED; | 86 state_ = STOPPED; |
87 request_.reset(NULL); | 87 request_.reset(NULL); |
88 } | 88 } |
89 | 89 |
90 // Ignore any notifications other than signalling | 90 // Ignore any notifications other than signalling |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void HeartbeatSender::SetInterval(int interval) { | 139 void HeartbeatSender::SetInterval(int interval) { |
140 if (interval != interval_ms_) { | 140 if (interval != interval_ms_) { |
141 interval_ms_ = interval; | 141 interval_ms_ = interval; |
142 | 142 |
143 // Restart the timer with the new interval. | 143 // Restart the timer with the new interval. |
144 if (state_ == STARTED) { | 144 if (state_ == STARTED) { |
145 timer_.Stop(); | 145 timer_.Stop(); |
146 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(interval_ms_), | 146 timer_.Start(base::TimeDelta::FromMilliseconds(interval_ms_), this, |
147 this, &HeartbeatSender::DoSendStanza); | 147 &HeartbeatSender::DoSendStanza); |
148 } | 148 } |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 XmlElement* HeartbeatSender::CreateHeartbeatMessage() { | 152 XmlElement* HeartbeatSender::CreateHeartbeatMessage() { |
153 XmlElement* query = new XmlElement( | 153 XmlElement* query = new XmlElement( |
154 QName(kChromotingXmlNamespace, kHeartbeatQueryTag)); | 154 QName(kChromotingXmlNamespace, kHeartbeatQueryTag)); |
155 query->AddAttr(QName(kChromotingXmlNamespace, kHostIdAttr), host_id_); | 155 query->AddAttr(QName(kChromotingXmlNamespace, kHostIdAttr), host_id_); |
156 query->AddElement(CreateSignature()); | 156 query->AddElement(CreateSignature()); |
157 return query; | 157 return query; |
158 } | 158 } |
159 | 159 |
160 XmlElement* HeartbeatSender::CreateSignature() { | 160 XmlElement* HeartbeatSender::CreateSignature() { |
161 XmlElement* signature_tag = new XmlElement( | 161 XmlElement* signature_tag = new XmlElement( |
162 QName(kChromotingXmlNamespace, kHeartbeatSignatureTag)); | 162 QName(kChromotingXmlNamespace, kHeartbeatSignatureTag)); |
163 | 163 |
164 int64 time = static_cast<int64>(base::Time::Now().ToDoubleT()); | 164 int64 time = static_cast<int64>(base::Time::Now().ToDoubleT()); |
165 std::string time_str(base::Int64ToString(time)); | 165 std::string time_str(base::Int64ToString(time)); |
166 signature_tag->AddAttr( | 166 signature_tag->AddAttr( |
167 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); | 167 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); |
168 | 168 |
169 std::string message = full_jid_ + ' ' + time_str; | 169 std::string message = full_jid_ + ' ' + time_str; |
170 std::string signature(key_pair_.GetSignature(message)); | 170 std::string signature(key_pair_.GetSignature(message)); |
171 signature_tag->AddText(signature); | 171 signature_tag->AddText(signature); |
172 | 172 |
173 return signature_tag; | 173 return signature_tag; |
174 } | 174 } |
175 | 175 |
176 } // namespace remoting | 176 } // namespace remoting |
OLD | NEW |