buffet: XmppChannel listens for connectivity changes
ShillClent provides notifications for network changes.
XmppChannel issue XMPP ping on every network change and restart if
failed. Only exception is soon scheduled upcoming reconnect.
BUG=brillo:1139
TEST=register device, disconnect network, wait device is offline in
GCD dashboard, connect network.
Dashboard should show device as online in less then 60 seconds.
Change-Id: I73dffc54400777b2325c26fb8aaf259b515174ce
Reviewed-on: https://chromium-review.googlesource.com/281413
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/notification/xmpp_iq_stanza_handler.cc b/buffet/notification/xmpp_iq_stanza_handler.cc
index e3a14c0..fada014 100644
--- a/buffet/notification/xmpp_iq_stanza_handler.cc
+++ b/buffet/notification/xmpp_iq_stanza_handler.cc
@@ -58,16 +58,30 @@
const std::string& body,
const ResponseCallback& response_callback,
const TimeoutCallback& timeout_callback) {
+ return SendRequestWithCustomTimeout(
+ type, from, to, body,
+ base::TimeDelta::FromSeconds(kTimeoutIntervalSeconds), response_callback,
+ timeout_callback);
+}
+
+void IqStanzaHandler::SendRequestWithCustomTimeout(
+ const std::string& type,
+ const std::string& from,
+ const std::string& to,
+ const std::string& body,
+ base::TimeDelta timeout,
+ const ResponseCallback& response_callback,
+ const TimeoutCallback& timeout_callback) {
// Remember the response callback to call later.
requests_.emplace(++last_request_id_, response_callback);
// Schedule a time-out callback for this request.
- task_runner_->PostDelayedTask(
- FROM_HERE,
- base::Bind(&IqStanzaHandler::OnTimeOut,
- weak_ptr_factory_.GetWeakPtr(),
- last_request_id_,
- timeout_callback),
- base::TimeDelta::FromSeconds(kTimeoutIntervalSeconds));
+ if (timeout < base::TimeDelta::Max()) {
+ task_runner_->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&IqStanzaHandler::OnTimeOut, weak_ptr_factory_.GetWeakPtr(),
+ last_request_id_, timeout_callback),
+ timeout);
+ }
std::string message = BuildIqStanza(std::to_string(last_request_id_),
type, to, from, body);