forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
barrier_builder.h
52 lines (42 loc) · 1.54 KB
/
barrier_builder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2018 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 CONTENT_TEST_BARRIER_BUILDER_H_
#define CONTENT_TEST_BARRIER_BUILDER_H_
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
namespace content {
// A BarrierBuilder helps create a barrier for a large, complex, or variable
// number of steps.
//
// Example usage:
//
// base::RunLoop loop;
// {
// BarrierBuilder barrier(loop.QuitClosure());
// AsyncMethod(barrier.AddClosure());
// AsyncMethod(barrier.AddClosure());
// }
// loop.Run();
//
// Once all closures returned by AddClosure AND the BarrierBuilder object are
// all destroyed, the |done_closure| is called. The |done_closure| will
// be invoked on the thread that calls the last step closure, or on the thread
// where BarrierBuilder goes out of scope (if that happens after all closures
// are called).
class BarrierBuilder {
public:
explicit BarrierBuilder(base::OnceClosure done_closure);
~BarrierBuilder();
// Returns a closure that can be used in the same way that a barrier closure
// would be used. Furthermore, each callback returned by AddClosure() should
// eventually be run, or else 'done_closure' will never be run.
base::OnceClosure AddClosure();
private:
class InternalBarrierBuilder;
scoped_refptr<InternalBarrierBuilder> internal_barrier_;
DISALLOW_COPY_AND_ASSIGN(BarrierBuilder);
};
} // namespace content
#endif // CONTENT_TEST_BARRIER_BUILDER_H_