| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void HeartbeatSender::Start() { | 61 void HeartbeatSender::Start() { |
| 62 if (MessageLoop::current() != jingle_client_->message_loop()) { | 62 if (MessageLoop::current() != jingle_client_->message_loop()) { |
| 63 jingle_client_->message_loop()->PostTask( | 63 jingle_client_->message_loop()->PostTask( |
| 64 FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::Start)); | 64 FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::Start)); |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 | 67 |
| 68 DCHECK(state_ == INITIALIZED); | 68 DCHECK_EQ(INITIALIZED, state_); |
| 69 state_ = STARTED; | 69 state_ = STARTED; |
| 70 | 70 |
| 71 request_.reset(jingle_client_->CreateIqRequest()); | 71 request_.reset(jingle_client_->CreateIqRequest()); |
| 72 request_->set_callback(NewCallback(this, &HeartbeatSender::ProcessResponse)); | 72 request_->set_callback(NewCallback(this, &HeartbeatSender::ProcessResponse)); |
| 73 | 73 |
| 74 jingle_client_->message_loop()->PostTask( | 74 jingle_client_->message_loop()->PostTask( |
| 75 FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::DoSendStanza)); | 75 FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::DoSendStanza)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void HeartbeatSender::Stop() { | 78 void HeartbeatSender::Stop() { |
| 79 if (MessageLoop::current() != jingle_client_->message_loop()) { | 79 if (MessageLoop::current() != jingle_client_->message_loop()) { |
| 80 jingle_client_->message_loop()->PostTask( | 80 jingle_client_->message_loop()->PostTask( |
| 81 FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::Stop)); | 81 FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::Stop)); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 | 84 |
| 85 DCHECK(state_ == STARTED); | 85 // We may call Stop() even if we have not started. |
| 86 if (state_ != STARTED) |
| 87 return; |
| 86 state_ = STOPPED; | 88 state_ = STOPPED; |
| 87 request_.reset(NULL); | 89 request_.reset(NULL); |
| 88 } | 90 } |
| 89 | 91 |
| 90 void HeartbeatSender::DoSendStanza() { | 92 void HeartbeatSender::DoSendStanza() { |
| 91 if (state_ == STARTED) { | 93 if (state_ == STARTED) { |
| 92 // |jingle_client_| may be already destroyed if |state_| is set to | 94 // |jingle_client_| may be already destroyed if |state_| is set to |
| 93 // |STOPPED|, so don't touch it here unless we are in |STARTED| state. | 95 // |STOPPED|, so don't touch it here unless we are in |STARTED| state. |
| 94 DCHECK(MessageLoop::current() == jingle_client_->message_loop()); | 96 DCHECK(MessageLoop::current() == jingle_client_->message_loop()); |
| 95 | 97 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 buzz::QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); | 132 buzz::QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); |
| 131 | 133 |
| 132 std::string message = jingle_client_->GetFullJid() + ' ' + time_str; | 134 std::string message = jingle_client_->GetFullJid() + ' ' + time_str; |
| 133 std::string signature(key_pair_.GetSignature(message)); | 135 std::string signature(key_pair_.GetSignature(message)); |
| 134 signature_tag->AddText(signature); | 136 signature_tag->AddText(signature); |
| 135 | 137 |
| 136 return signature_tag; | 138 return signature_tag; |
| 137 } | 139 } |
| 138 | 140 |
| 139 } // namespace remoting | 141 } // namespace remoting |
| OLD | NEW |