| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/register_support_host_request.h" | 5 #include "remoting/host/register_support_host_request.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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 const char kSignatureTimeAttr[] = "time"; | 29 const char kSignatureTimeAttr[] = "time"; |
| 30 | 30 |
| 31 // Strings used to parse responses received from the bot. | 31 // Strings used to parse responses received from the bot. |
| 32 const char kRegisterQueryResultTag[] = "register-support-host-result"; | 32 const char kRegisterQueryResultTag[] = "register-support-host-result"; |
| 33 const char kSupportIdTag[] = "support-id"; | 33 const char kSupportIdTag[] = "support-id"; |
| 34 const char kSupportIdLifetimeTag[] = "support-id-lifetime"; | 34 const char kSupportIdLifetimeTag[] = "support-id-lifetime"; |
| 35 } | 35 } |
| 36 | 36 |
| 37 RegisterSupportHostRequest::RegisterSupportHostRequest( | 37 RegisterSupportHostRequest::RegisterSupportHostRequest( |
| 38 SignalStrategy* signal_strategy, | 38 SignalStrategy* signal_strategy, |
| 39 HostKeyPair* key_pair, | 39 scoped_refptr<RsaKeyPair> key_pair, |
| 40 const std::string& directory_bot_jid, | 40 const std::string& directory_bot_jid, |
| 41 const RegisterCallback& callback) | 41 const RegisterCallback& callback) |
| 42 : signal_strategy_(signal_strategy), | 42 : signal_strategy_(signal_strategy), |
| 43 key_pair_(key_pair), | 43 key_pair_(key_pair), |
| 44 directory_bot_jid_(directory_bot_jid), | 44 directory_bot_jid_(directory_bot_jid), |
| 45 callback_(callback) { | 45 callback_(callback) { |
| 46 DCHECK(signal_strategy_); | 46 DCHECK(signal_strategy_); |
| 47 DCHECK(key_pair_); | 47 DCHECK(key_pair_); |
| 48 signal_strategy_->AddListener(this); | 48 signal_strategy_->AddListener(this); |
| 49 iq_sender_.reset(new IqSender(signal_strategy_)); | 49 iq_sender_.reset(new IqSender(signal_strategy_)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 const std::string& jid) { | 91 const std::string& jid) { |
| 92 scoped_ptr<XmlElement> signature_tag(new XmlElement( | 92 scoped_ptr<XmlElement> signature_tag(new XmlElement( |
| 93 QName(kChromotingXmlNamespace, kSignatureTag))); | 93 QName(kChromotingXmlNamespace, kSignatureTag))); |
| 94 | 94 |
| 95 int64 time = static_cast<int64>(base::Time::Now().ToDoubleT()); | 95 int64 time = static_cast<int64>(base::Time::Now().ToDoubleT()); |
| 96 std::string time_str(base::Int64ToString(time)); | 96 std::string time_str(base::Int64ToString(time)); |
| 97 signature_tag->AddAttr( | 97 signature_tag->AddAttr( |
| 98 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); | 98 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); |
| 99 | 99 |
| 100 std::string message = jid + ' ' + time_str; | 100 std::string message = jid + ' ' + time_str; |
| 101 std::string signature(key_pair_->GetSignature(message)); | 101 std::string signature(key_pair_->SignMessage(message)); |
| 102 signature_tag->AddText(signature); | 102 signature_tag->AddText(signature); |
| 103 | 103 |
| 104 return signature_tag.Pass(); | 104 return signature_tag.Pass(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool RegisterSupportHostRequest::ParseResponse(const XmlElement* response, | 107 bool RegisterSupportHostRequest::ParseResponse(const XmlElement* response, |
| 108 std::string* support_id, | 108 std::string* support_id, |
| 109 base::TimeDelta* lifetime) { | 109 base::TimeDelta* lifetime) { |
| 110 std::string type = response->Attr(buzz::QN_TYPE); | 110 std::string type = response->Attr(buzz::QN_TYPE); |
| 111 if (type == buzz::STR_ERROR) { | 111 if (type == buzz::STR_ERROR) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 iq_sender_.reset(); | 177 iq_sender_.reset(); |
| 178 signal_strategy_->RemoveListener(this); | 178 signal_strategy_->RemoveListener(this); |
| 179 signal_strategy_ = NULL; | 179 signal_strategy_ = NULL; |
| 180 | 180 |
| 181 RegisterCallback callback = callback_; | 181 RegisterCallback callback = callback_; |
| 182 callback_.Reset(); | 182 callback_.Reset(); |
| 183 callback.Run(success, support_id, lifetime); | 183 callback.Run(success, support_id, lifetime); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace remoting | 186 } // namespace remoting |
| OLD | NEW |