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..fe633d9a2aef5594cdcfdb524c6199fe6637e451 |
| --- /dev/null |
| +++ b/remoting/host/ack_or_timeout_reporter.h |
| @@ -0,0 +1,47 @@ |
| +// 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_forward.h" |
| +#include "base/sequenced_task_runner.h" |
| + |
| +namespace base { |
| +class TimeDelta; |
| +} |
| + |
| +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. |
|
Wez
2014/12/09 00:51:58
By acking, do you mean a completion callback?
Why
Łukasz Anforowicz
2014/12/09 18:47:07
I am not sure if I understand the question.
If by
|
| +// |
| +// 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( |
|
Wez
2014/12/09 00:51:58
This name doesn't seem very helpful/descriptive; t
Wez
2014/12/09 00:51:58
Why do you need this function at all? It seems it'
Łukasz Anforowicz
2014/12/09 18:47:07
I find it easier to unit test a generic ReportAckO
Łukasz Anforowicz
2014/12/09 18:47:07
I can rename (if we agree that having a ReportAckO
|
| + const base::Callback<void(const base::Closure& ack_callback)>& |
| + function_that_acks, |
|
Wez
2014/12/09 00:51:58
nit: typedef this to something like AsyncFunction?
Łukasz Anforowicz
2014/12/09 18:47:07
I like that the reader can see the signature of fu
|
| + const base::TimeDelta& timeout, |
| + scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner, |
|
Wez
2014/12/09 00:51:58
Why do you need this parameter, rather than using
Łukasz Anforowicz
2014/12/09 18:47:07
This way I can avoid unnecessarily constraining Re
Wez
2014/12/15 20:34:24
It's already constrained to be the same thread by
|
| + const base::Callback<void(AckOrTimeout ack_or_timeout)>& |
| + ack_or_timeout_callback); |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_HOST_ACK_OR_TIMEOUT_REPORTER_H_ |