Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: services/media/framework/util/incident.cc

Issue 2024953003: Motown: Move framework/util/incident* so other services can use it (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 #include "services/media/framework/util/incident.h"
6
7 namespace mojo {
8 namespace media {
9
10 Incident::Incident() {}
11
12 Incident::~Incident() {}
13
14 void Incident::Occur() {
15 if (occurred_) {
16 return;
17 }
18
19 occurred_ = true;
20
21 // Swap out consequences_ in case one of the callbacks deletes this.
22 std::vector<std::function<void()>> consequences;
23 consequences_.swap(consequences);
24
25 for (const std::function<void()>& consequence : consequences) {
26 consequence();
27 }
28 }
29
30 ThreadsafeIncident::ThreadsafeIncident() {}
31
32 ThreadsafeIncident::~ThreadsafeIncident() {}
33
34 void ThreadsafeIncident::Occur() {
35 std::vector<std::function<void()>> consequences;
36
37 {
38 base::AutoLock lock(consequences_lock_);
39
40 if (occurred_) {
41 return;
42 }
43
44 occurred_ = true;
45 consequences_.swap(consequences);
46 }
47
48 for (const std::function<void()>& consequence : consequences) {
49 consequence();
50 }
51 }
52
53 } // namespace media
54 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698