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.h" |
| 9 #include "base/sequenced_task_runner.h" |
| 10 #include "base/time/time.h" |
| 11 |
| 12 namespace remoting { |
| 13 |
| 14 enum AckOrTimeout { Ack, Timeout }; |
| 15 |
| 16 // ReportAckOrTimeout will call |ack_or_timeout_callback|, when either |
| 17 // |ack_callback| is called or when |timeout| has been reached. This |
| 18 // is helpful to add timeout functionality to a function that supports |
| 19 // acking, but doesn't support timeouts. |
| 20 // |
| 21 // As a consequence of using WeakPtr as an implementation detail, |
| 22 // ReportAckOrTimeout requires its caller to make sure that: |
| 23 // - ReportAckOfTimeout is called on |sequenced_task_runner| |
| 24 // - If called, then |ack_callback| will be called on |sequenced_task_runner| |
| 25 // |
| 26 // ReportAckOrTimeout guarantees that: |
| 27 // - |function_that_acks| will be called synchronously (i.e. caller |
| 28 // can destroy |function_that_acks| and/or its base::Unretained |
| 29 // arguments as soon as ReportAckOrTimeout returns). |
| 30 // - |ack_or_timeout_callback| will be called exactly once. |
| 31 // - |ack_or_timeout_callback| will be called via |sequenced_task_runner|. |
| 32 // - All references (i.e. ref-counted arguments) to |ack_or_timeout_callback| |
| 33 // will be dropped after it is called. |
| 34 void ReportAckOrTimeout( |
| 35 const base::Callback<void(const base::Closure& ack_callback)>& |
| 36 function_that_acks, |
| 37 const base::TimeDelta& timeout, |
| 38 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner, |
| 39 const base::Callback<void(AckOrTimeout ack_or_timeout)>& |
| 40 ack_or_timeout_callback); |
| 41 |
| 42 } // namespace remoting |
| 43 |
| 44 #endif // REMOTING_HOST_ACK_OR_TIMEOUT_REPORTER_H_ |
OLD | NEW |