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/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 signal_strategy_->RemoveListener(this); | 56 signal_strategy_->RemoveListener(this); |
57 } | 57 } |
58 | 58 |
59 void RegisterSupportHostRequest::OnSignalStrategyStateChange( | 59 void RegisterSupportHostRequest::OnSignalStrategyStateChange( |
60 SignalStrategy::State state) { | 60 SignalStrategy::State state) { |
61 if (state == SignalStrategy::CONNECTED) { | 61 if (state == SignalStrategy::CONNECTED) { |
62 DCHECK(!callback_.is_null()); | 62 DCHECK(!callback_.is_null()); |
63 | 63 |
64 request_ = iq_sender_->SendIq( | 64 request_ = iq_sender_->SendIq( |
65 buzz::STR_SET, directory_bot_jid_, | 65 buzz::STR_SET, directory_bot_jid_, |
66 CreateRegistrationRequest(signal_strategy_->GetLocalJid()).Pass(), | 66 CreateRegistrationRequest(signal_strategy_->GetLocalJid()), |
67 base::Bind(&RegisterSupportHostRequest::ProcessResponse, | 67 base::Bind(&RegisterSupportHostRequest::ProcessResponse, |
68 base::Unretained(this))); | 68 base::Unretained(this))); |
69 } else if (state == SignalStrategy::DISCONNECTED) { | 69 } else if (state == SignalStrategy::DISCONNECTED) { |
70 // We will reach here if signaling fails to connect. | 70 // We will reach here if signaling fails to connect. |
71 std::string error_message = "Signal strategy disconnected."; | 71 std::string error_message = "Signal strategy disconnected."; |
72 LOG(ERROR) << error_message; | 72 LOG(ERROR) << error_message; |
73 CallCallback(std::string(), base::TimeDelta(), error_message); | 73 CallCallback(std::string(), base::TimeDelta(), error_message); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza( | 77 bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza( |
78 const buzz::XmlElement* stanza) { | 78 const buzz::XmlElement* stanza) { |
79 return false; | 79 return false; |
80 } | 80 } |
81 | 81 |
82 scoped_ptr<XmlElement> RegisterSupportHostRequest::CreateRegistrationRequest( | 82 scoped_ptr<XmlElement> RegisterSupportHostRequest::CreateRegistrationRequest( |
83 const std::string& jid) { | 83 const std::string& jid) { |
84 scoped_ptr<XmlElement> query(new XmlElement( | 84 scoped_ptr<XmlElement> query(new XmlElement( |
85 QName(kChromotingXmlNamespace, kRegisterQueryTag))); | 85 QName(kChromotingXmlNamespace, kRegisterQueryTag))); |
86 XmlElement* public_key = new XmlElement( | 86 XmlElement* public_key = new XmlElement( |
87 QName(kChromotingXmlNamespace, kPublicKeyTag)); | 87 QName(kChromotingXmlNamespace, kPublicKeyTag)); |
88 public_key->AddText(key_pair_->GetPublicKey()); | 88 public_key->AddText(key_pair_->GetPublicKey()); |
89 query->AddElement(public_key); | 89 query->AddElement(public_key); |
90 query->AddElement(CreateSignature(jid).release()); | 90 query->AddElement(CreateSignature(jid).release()); |
91 return query.Pass(); | 91 return query; |
92 } | 92 } |
93 | 93 |
94 scoped_ptr<XmlElement> RegisterSupportHostRequest::CreateSignature( | 94 scoped_ptr<XmlElement> RegisterSupportHostRequest::CreateSignature( |
95 const std::string& jid) { | 95 const std::string& jid) { |
96 scoped_ptr<XmlElement> signature_tag(new XmlElement( | 96 scoped_ptr<XmlElement> signature_tag(new XmlElement( |
97 QName(kChromotingXmlNamespace, kSignatureTag))); | 97 QName(kChromotingXmlNamespace, kSignatureTag))); |
98 | 98 |
99 int64 time = static_cast<int64>(base::Time::Now().ToDoubleT()); | 99 int64 time = static_cast<int64>(base::Time::Now().ToDoubleT()); |
100 std::string time_str(base::Int64ToString(time)); | 100 std::string time_str(base::Int64ToString(time)); |
101 signature_tag->AddAttr( | 101 signature_tag->AddAttr( |
102 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); | 102 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); |
103 | 103 |
104 std::string message = NormalizeJid(jid) + ' ' + time_str; | 104 std::string message = NormalizeJid(jid) + ' ' + time_str; |
105 std::string signature(key_pair_->SignMessage(message)); | 105 std::string signature(key_pair_->SignMessage(message)); |
106 signature_tag->AddText(signature); | 106 signature_tag->AddText(signature); |
107 | 107 |
108 return signature_tag.Pass(); | 108 return signature_tag; |
109 } | 109 } |
110 | 110 |
111 void RegisterSupportHostRequest::ParseResponse(const XmlElement* response, | 111 void RegisterSupportHostRequest::ParseResponse(const XmlElement* response, |
112 std::string* support_id, | 112 std::string* support_id, |
113 base::TimeDelta* lifetime, | 113 base::TimeDelta* lifetime, |
114 std::string* error_message) { | 114 std::string* error_message) { |
115 std::ostringstream error; | 115 std::ostringstream error; |
116 | 116 |
117 std::string type = response->Attr(buzz::QN_TYPE); | 117 std::string type = response->Attr(buzz::QN_TYPE); |
118 if (type == buzz::STR_ERROR) { | 118 if (type == buzz::STR_ERROR) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // Cleanup state before calling the callback. | 196 // Cleanup state before calling the callback. |
197 request_.reset(); | 197 request_.reset(); |
198 iq_sender_.reset(); | 198 iq_sender_.reset(); |
199 signal_strategy_->RemoveListener(this); | 199 signal_strategy_->RemoveListener(this); |
200 signal_strategy_ = nullptr; | 200 signal_strategy_ = nullptr; |
201 | 201 |
202 base::ResetAndReturn(&callback_).Run(support_id, lifetime, error_message); | 202 base::ResetAndReturn(&callback_).Run(support_id, lifetime, error_message); |
203 } | 203 } |
204 | 204 |
205 } // namespace remoting | 205 } // namespace remoting |
OLD | NEW |