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

Side by Side Diff: remoting/host/register_support_host_request.cc

Issue 2925733003: Report signling errors for register-support-host requests. (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringize_macros.h" 14 #include "base/strings/stringize_macros.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "remoting/base/constants.h" 16 #include "remoting/base/constants.h"
17 #include "remoting/host/host_config.h" 17 #include "remoting/host/host_config.h"
18 #include "remoting/host/host_details.h" 18 #include "remoting/host/host_details.h"
19 #include "remoting/protocol/errors.h"
19 #include "remoting/signaling/iq_sender.h" 20 #include "remoting/signaling/iq_sender.h"
20 #include "remoting/signaling/jid_util.h" 21 #include "remoting/signaling/jid_util.h"
21 #include "remoting/signaling/signal_strategy.h" 22 #include "remoting/signaling/signal_strategy.h"
22 #include "remoting/signaling/signaling_address.h" 23 #include "remoting/signaling/signaling_address.h"
23 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" 24 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
24 #include "third_party/libjingle_xmpp/xmpp/constants.h" 25 #include "third_party/libjingle_xmpp/xmpp/constants.h"
25 26
26 using buzz::QName; 27 using buzz::QName;
27 using buzz::XmlElement; 28 using buzz::XmlElement;
28 29
29 namespace remoting { 30 namespace remoting {
30 31
31 namespace { 32 namespace {
32 // Strings used in the request message we send to the bot. 33 // Strings used in the request message we send to the bot.
33 const char kRegisterQueryTag[] = "register-support-host"; 34 const char kRegisterQueryTag[] = "register-support-host";
34 const char kPublicKeyTag[] = "public-key"; 35 const char kPublicKeyTag[] = "public-key";
35 const char kSignatureTag[] = "signature"; 36 const char kSignatureTag[] = "signature";
36 const char kSignatureTimeAttr[] = "time"; 37 const char kSignatureTimeAttr[] = "time";
37 const char kHostVersionTag[] = "host-version"; 38 const char kHostVersionTag[] = "host-version";
38 const char kHostOsNameTag[] = "host-os-name"; 39 const char kHostOsNameTag[] = "host-os-name";
39 const char kHostOsVersionTag[] = "host-os-version"; 40 const char kHostOsVersionTag[] = "host-os-version";
40 41
41 // Strings used to parse responses received from the bot. 42 // Strings used to parse responses received from the bot.
42 const char kRegisterQueryResultTag[] = "register-support-host-result"; 43 const char kRegisterQueryResultTag[] = "register-support-host-result";
43 const char kSupportIdTag[] = "support-id"; 44 const char kSupportIdTag[] = "support-id";
44 const char kSupportIdLifetimeTag[] = "support-id-lifetime"; 45 const char kSupportIdLifetimeTag[] = "support-id-lifetime";
46
47 // The signaling timeout for register support host requests.
48 const int kRegisterRequestTimeoutInSeconds = 10;
Sergey Ulanov 2017/06/07 06:41:30 nit: use constexpr base::TimeDelta: constexpr ba
kelvinp 2017/06/12 21:31:26 Done.
45 } 49 }
46 50
47 RegisterSupportHostRequest::RegisterSupportHostRequest( 51 RegisterSupportHostRequest::RegisterSupportHostRequest(
48 SignalStrategy* signal_strategy, 52 SignalStrategy* signal_strategy,
49 scoped_refptr<RsaKeyPair> key_pair, 53 scoped_refptr<RsaKeyPair> key_pair,
50 const std::string& directory_bot_jid, 54 const std::string& directory_bot_jid,
51 const RegisterCallback& callback) 55 const RegisterCallback& callback)
52 : signal_strategy_(signal_strategy), 56 : signal_strategy_(signal_strategy),
53 key_pair_(key_pair), 57 key_pair_(key_pair),
54 directory_bot_jid_(directory_bot_jid), 58 directory_bot_jid_(directory_bot_jid),
55 callback_(callback) { 59 callback_(callback) {
56 DCHECK(signal_strategy_); 60 DCHECK(signal_strategy_);
57 DCHECK(key_pair_.get()); 61 DCHECK(key_pair_.get());
58 signal_strategy_->AddListener(this); 62 signal_strategy_->AddListener(this);
59 iq_sender_.reset(new IqSender(signal_strategy_)); 63 iq_sender_.reset(new IqSender(signal_strategy_));
60 } 64 }
61 65
62 RegisterSupportHostRequest::~RegisterSupportHostRequest() { 66 RegisterSupportHostRequest::~RegisterSupportHostRequest() {
63 if (signal_strategy_) 67 if (signal_strategy_)
64 signal_strategy_->RemoveListener(this); 68 signal_strategy_->RemoveListener(this);
65 } 69 }
66 70
67 void RegisterSupportHostRequest::OnSignalStrategyStateChange( 71 void RegisterSupportHostRequest::OnSignalStrategyStateChange(
68 SignalStrategy::State state) { 72 SignalStrategy::State state) {
69 if (state == SignalStrategy::CONNECTED) { 73 if (state == SignalStrategy::CONNECTED) {
70 DCHECK(!callback_.is_null()); 74 DCHECK(!callback_.is_null());
71
72 request_ = iq_sender_->SendIq( 75 request_ = iq_sender_->SendIq(
73 buzz::STR_SET, directory_bot_jid_, 76 buzz::STR_SET, directory_bot_jid_,
74 CreateRegistrationRequest(signal_strategy_->GetLocalAddress().jid()), 77 CreateRegistrationRequest(signal_strategy_->GetLocalAddress().jid()),
75 base::Bind(&RegisterSupportHostRequest::ProcessResponse, 78 base::Bind(&RegisterSupportHostRequest::ProcessResponse,
76 base::Unretained(this))); 79 base::Unretained(this)));
80 if (!request_.get()) {
Sergey Ulanov 2017/06/07 06:41:29 nit: don't need .get()
kelvinp 2017/06/12 21:31:25 Done.
81 std::string error_message =
82 protocol::ErrorCodeToString(protocol::ErrorCode::SIGNALING_ERROR);
Sergey Ulanov 2017/06/07 06:41:29 error_message should a human-readable message that
kelvinp 2017/06/12 21:31:26 Done.
83 LOG(ERROR) << error_message;
84 CallCallback(std::string(), base::TimeDelta(), error_message);
85 return;
86 }
87
88 request_->SetTimeout(
89 base::TimeDelta::FromSeconds(kRegisterRequestTimeoutInSeconds));
90
77 } else if (state == SignalStrategy::DISCONNECTED) { 91 } else if (state == SignalStrategy::DISCONNECTED) {
78 // We will reach here if signaling fails to connect. 92 // We will reach here if signaling fails to connect.
79 std::string error_message = "Signal strategy disconnected."; 93 std::string error_message = "Signal strategy disconnected.";
80 LOG(ERROR) << error_message; 94 LOG(ERROR) << error_message;
81 CallCallback(std::string(), base::TimeDelta(), error_message); 95 CallCallback(std::string(), base::TimeDelta(), error_message);
82 } 96 }
83 } 97 }
84 98
85 bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza( 99 bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza(
86 const buzz::XmlElement* stanza) { 100 const buzz::XmlElement* stanza) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 150
137 return signature_tag; 151 return signature_tag;
138 } 152 }
139 153
140 void RegisterSupportHostRequest::ParseResponse(const XmlElement* response, 154 void RegisterSupportHostRequest::ParseResponse(const XmlElement* response,
141 std::string* support_id, 155 std::string* support_id,
142 base::TimeDelta* lifetime, 156 base::TimeDelta* lifetime,
143 std::string* error_message) { 157 std::string* error_message) {
144 std::ostringstream error; 158 std::ostringstream error;
145 159
160 if (!response) {
161 *error_message =
162 protocol::ErrorCodeToString(protocol::ErrorCode::SIGNALING_TIMEOUT);
Sergey Ulanov 2017/06/07 06:41:30 same here. Use a readable message please.
kelvinp 2017/06/12 21:31:25 Done.
163 LOG(ERROR) << *error_message;
Sergey Ulanov 2017/06/07 06:41:30 I don't think we need to log the message here. Or
kelvinp 2017/06/12 21:31:25 We log the error message in all other branches of
164 return;
165 }
166
146 std::string type = response->Attr(buzz::QN_TYPE); 167 std::string type = response->Attr(buzz::QN_TYPE);
147 if (type == buzz::STR_ERROR) { 168 if (type == buzz::STR_ERROR) {
148 error << "Received error in response to heartbeat: " << response->Str(); 169 error << "Received error in response to heartbeat: " << response->Str();
149 *error_message = error.str(); 170 *error_message = error.str();
150 LOG(ERROR) << *error_message; 171 LOG(ERROR) << *error_message;
151 return; 172 return;
152 } 173 }
153 174
154 // This method must only be called for error or result stanzas. 175 // This method must only be called for error or result stanzas.
155 if (type != buzz::STR_RESULT) { 176 if (type != buzz::STR_RESULT) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // Cleanup state before calling the callback. 246 // Cleanup state before calling the callback.
226 request_.reset(); 247 request_.reset();
227 iq_sender_.reset(); 248 iq_sender_.reset();
228 signal_strategy_->RemoveListener(this); 249 signal_strategy_->RemoveListener(this);
229 signal_strategy_ = nullptr; 250 signal_strategy_ = nullptr;
230 251
231 base::ResetAndReturn(&callback_).Run(support_id, lifetime, error_message); 252 base::ResetAndReturn(&callback_).Run(support_id, lifetime, error_message);
232 } 253 }
233 254
234 } // namespace remoting 255 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698