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

Unified Diff: remoting/host/heartbeat_sender.cc

Issue 719983002: Reporting of policy errors via host-offline-reason: part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hor-nohoststatussender
Patch Set: Better callback currying. Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/heartbeat_sender.cc
diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc
index c64f2f49cf1c6b536afa13481ebde83f6dea8882..248057cca11e11405b33aedc471b136696ed1ece 100644
--- a/remoting/host/heartbeat_sender.cc
+++ b/remoting/host/heartbeat_sender.cc
@@ -54,7 +54,7 @@ HeartbeatSender::HeartbeatSender(
const base::Closure& on_unknown_host_id_error,
const std::string& host_id,
SignalStrategy* signal_strategy,
- scoped_refptr<RsaKeyPair> key_pair,
+ const scoped_refptr<const RsaKeyPair>& key_pair,
const std::string& directory_bot_jid)
: on_heartbeat_successful_callback_(on_heartbeat_successful_callback),
on_unknown_host_id_error_(on_unknown_host_id_error),
@@ -102,13 +102,32 @@ bool HeartbeatSender::OnSignalStrategyIncomingStanza(
return false;
}
+void HeartbeatSender::CallHostOfflineReasonAckCallback(
+ AckOrTimeout ack_or_timeout) {
+ // We go through PostTask (rather than directly calling Run),
+ // to unwind frames with |this| pointer from the stack.
+ // While Run invocation can be the last statement in this
+ // particular method, we don't want to force maintainers
+ // of our callers to ensure that they call us last.
Wez 2014/12/18 00:46:20 This is a common pattern, so doesn't need such a l
Łukasz Anforowicz 2014/12/18 19:02:33 I tried to shorten the comment following your sugg
Wez 2014/12/19 22:05:36 Acknowledged.
+ base::Closure fully_bound_ack_callback =
Lambros 2014/12/17 23:44:34 nit: Don't need the temporary. We do PostTask(FROM
Łukasz Anforowicz 2014/12/18 00:03:41 Acknowledged.
+ base::Bind(host_offline_reason_ack_callback_, ack_or_timeout);
+ base::MessageLoop::current()->PostTask(FROM_HERE, fully_bound_ack_callback);
Wez 2014/12/18 00:46:20 nit: Use ThreadTaskRunnerHandle::Get() here.
Łukasz Anforowicz 2014/12/18 19:02:33 Done. Can you please give more details / help me
Wez 2014/12/19 22:05:36 In using the current MessageLoop's TaskRunner you'
+
+ host_offline_reason_ack_callback_.Reset();
+}
+
void HeartbeatSender::SetHostOfflineReason(
const std::string& host_offline_reason,
- const base::Closure& ack_callback) {
+ const base::TimeDelta& timeout,
+ const base::Callback<void(AckOrTimeout)>& ack_callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(host_offline_reason_ack_callback_.is_null());
host_offline_reason_ = host_offline_reason;
host_offline_reason_ack_callback_ = ack_callback;
+ host_offline_reason_timeout_timer_.Start(
+ FROM_HERE, timeout,
+ base::Bind(&HeartbeatSender::CallHostOfflineReasonAckCallback,
+ base::Unretained(this), AckOrTimeout::Timeout));
Wez 2014/12/18 00:46:20 Re-using CallHostOfflineReasonAckCallback here rea
Łukasz Anforowicz 2014/12/18 19:02:33 Good point. Done. This also helped keep the time
if (signal_strategy_->GetState() == SignalStrategy::CONNECTED) {
DoSendStanza();
}
@@ -231,10 +250,8 @@ void HeartbeatSender::ProcessResponse(
// Notify caller of SetHostOfflineReason that we got an ack.
if (is_offline_heartbeat_response) {
if (!host_offline_reason_ack_callback_.is_null()) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- host_offline_reason_ack_callback_);
- host_offline_reason_ack_callback_.Reset();
+ host_offline_reason_timeout_timer_.Stop();
Wez 2014/12/18 00:46:20 This seems wrong - surely you want to stop the tim
Łukasz Anforowicz 2014/12/18 19:02:33 In this case the timer is already stopped.
+ CallHostOfflineReasonAckCallback(AckOrTimeout::Ack);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698