OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef REMOTING_HOST_ACK_OR_TIMEOUT_REPORTER_H_ | |
6 #define REMOTING_HOST_ACK_OR_TIMEOUT_REPORTER_H_ | |
7 | |
8 #include "base/callback_forward.h" | |
9 #include "base/sequenced_task_runner.h" | |
10 | |
11 namespace base { | |
12 class TimeDelta; | |
13 } | |
14 | |
15 namespace remoting { | |
16 | |
17 enum AckOrTimeout { Ack, Timeout }; | |
18 | |
19 // ReportAckOrTimeout will call |ack_or_timeout_callback|, when either | |
20 // |ack_callback| is called or when |timeout| has been reached. This | |
21 // is helpful to add timeout functionality to a function that supports | |
22 // 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
| |
23 // | |
24 // As a consequence of using WeakPtr as an implementation detail, | |
25 // ReportAckOrTimeout requires its caller to make sure that: | |
26 // - ReportAckOfTimeout is called on |sequenced_task_runner| | |
27 // - If called, then |ack_callback| will be called on |sequenced_task_runner| | |
28 // | |
29 // ReportAckOrTimeout guarantees that: | |
30 // - |function_that_acks| will be called synchronously (i.e. caller | |
31 // can destroy |function_that_acks| and/or its base::Unretained | |
32 // arguments as soon as ReportAckOrTimeout returns). | |
33 // - |ack_or_timeout_callback| will be called exactly once. | |
34 // - |ack_or_timeout_callback| will be called via |sequenced_task_runner|. | |
35 // - All references (i.e. ref-counted arguments) to |ack_or_timeout_callback| | |
36 // will be dropped after it is called. | |
37 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
| |
38 const base::Callback<void(const base::Closure& ack_callback)>& | |
39 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
| |
40 const base::TimeDelta& timeout, | |
41 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
| |
42 const base::Callback<void(AckOrTimeout ack_or_timeout)>& | |
43 ack_or_timeout_callback); | |
44 | |
45 } // namespace remoting | |
46 | |
47 #endif // REMOTING_HOST_ACK_OR_TIMEOUT_REPORTER_H_ | |
OLD | NEW |