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

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: Removed ReportAckOrTimeout and ref-counting. Renamed MinimumHeartbeatSupporter to HostSignalingMan… 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..df0f28eec9d467def11eebd7db606393b45541d0 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,43 @@ bool HeartbeatSender::OnSignalStrategyIncomingStanza(
return false;
}
+// The StaticCallHostOfflineReasonAckCallback is just like
+// Callback<void(AckOrTimeout)::Run method except that the first (i.e. |this|)
+// argument is taken by value rather than by pointer. This is needed to make it
+// work with base::Bind inside CallHostOfflineReasonAckCallback below.
Wez 2014/12/18 00:46:20 This description is not very helpful; I think all
Łukasz Anforowicz 2014/12/18 19:02:32 N/A - this function goes away in patchset #18 (it
+static void StaticCallHostOfflineReasonAckCallback(
Lambros 2014/12/16 02:14:05 nit: Maybe just call it RunAckCallback(). nit: Mov
Łukasz Anforowicz 2014/12/17 18:02:04 Done (except I renamed to RunHostOfflineReasonAckC
Wez 2014/12/18 00:46:20 CallHostOfflineReasonAckCallback
Łukasz Anforowicz 2014/12/18 19:02:33 N/A as of patchset #18
+ base::Callback<void(HeartbeatSender::AckOrTimeout)> ack_callback,
+ HeartbeatSender::AckOrTimeout ack_or_timeout) {
+ ack_callback.Run(ack_or_timeout);
+}
+
+void HeartbeatSender::CallHostOfflineReasonAckCallback(
Wez 2014/12/18 00:46:20 PostHostOfflineReasonAckCallback
Łukasz Anforowicz 2014/12/18 19:02:33 Good point - thanks.
+ AckOrTimeout ack_or_timeout) {
+ // We go through PostTask (rather than directly calling Run),
Lambros 2014/12/16 02:14:05 I don't understand why you have to make this async
Łukasz Anforowicz 2014/12/17 18:02:04 RE: why Requiring the callers (and callers of the
+ // 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.
+ base::Closure fully_bound_ack_callback =
+ base::Bind(StaticCallHostOfflineReasonAckCallback,
Lambros 2014/12/16 02:14:04 Are you sure you really need this? It seems very s
Łukasz Anforowicz 2014/12/17 18:02:04 I tried passing the callback object by value - thi
+ host_offline_reason_ack_callback_, ack_or_timeout);
+ base::MessageLoop::current()->PostTask(FROM_HERE, fully_bound_ack_callback);
+
+ 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));
if (signal_strategy_->GetState() == SignalStrategy::CONNECTED) {
DoSendStanza();
}
@@ -231,10 +261,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();
+ CallHostOfflineReasonAckCallback(AckOrTimeout::Ack);
+ host_offline_reason_timeout_timer_.Stop();
Lambros 2014/12/16 02:14:04 Maybe stop the timer first?
Łukasz Anforowicz 2014/12/17 18:02:04 Done.
}
}
}

Powered by Google App Engine
This is Rietveld 408576698