Chromium Code Reviews| Index: remoting/host/ack_or_timeout_reporter.h |
| diff --git a/remoting/host/ack_or_timeout_reporter.h b/remoting/host/ack_or_timeout_reporter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a810e5c97a823b0e83254ad1a2ef2a11552ff691 |
| --- /dev/null |
| +++ b/remoting/host/ack_or_timeout_reporter.h |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef REMOTING_HOST_ACK_OR_TIMEOUT_REPORTER_H_ |
| +#define REMOTING_HOST_ACK_OR_TIMEOUT_REPORTER_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/sequenced_task_runner.h" |
| +#include "base/time/time.h" |
|
Lambros
2014/12/05 22:19:48
nit: Remove this and forward-declare base::TimeDel
Łukasz Anforowicz
2014/12/05 23:59:28
Done for TimeDelta and Callback/Closure.
|
| + |
| +namespace remoting { |
| + |
| +enum AckOrTimeout { Ack, Timeout }; |
| + |
| +// ReportAckOrTimeout will call |ack_or_timeout_callback|, when either |
| +// |ack_callback| is called or when |timeout| has been reached. This |
| +// is helpful to add timeout functionality to a function that supports |
| +// acking, but doesn't support timeouts. |
| +// |
| +// As a consequence of using WeakPtr as an implementation detail, |
| +// ReportAckOrTimeout requires its caller to make sure that: |
| +// - ReportAckOfTimeout is called on |sequenced_task_runner| |
| +// - If called, then |ack_callback| will be called on |sequenced_task_runner| |
| +// |
| +// ReportAckOrTimeout guarantees that: |
| +// - |function_that_acks| will be called synchronously (i.e. caller |
| +// can destroy |function_that_acks| and/or its base::Unretained |
| +// arguments as soon as ReportAckOrTimeout returns). |
| +// - |ack_or_timeout_callback| will be called exactly once. |
| +// - |ack_or_timeout_callback| will be called via |sequenced_task_runner|. |
| +// - All references (i.e. ref-counted arguments) to |ack_or_timeout_callback| |
| +// will be dropped after it is called. |
| +void ReportAckOrTimeout( |
| + const base::Callback<void(const base::Closure& ack_callback)>& |
| + function_that_acks, |
| + const base::TimeDelta& timeout, |
| + scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner, |
| + const base::Callback<void(AckOrTimeout ack_or_timeout)>& |
| + ack_or_timeout_callback); |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_HOST_ACK_OR_TIMEOUT_REPORTER_H_ |