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

Side by Side Diff: media/audio/scoped_loop_observer.cc

Issue 66183002: Replace MessageLoopProxy with SingleThreadTaskRunner for the rest of media/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "media/audio/scoped_loop_observer.h"
6
7 #include "base/bind.h"
8 #include "base/synchronization/waitable_event.h"
9
10 namespace media {
11
12 ScopedLoopObserver::ScopedLoopObserver(
13 const scoped_refptr<base::MessageLoopProxy>& loop)
14 : loop_(loop) {
15 ObserveLoopDestruction(true, NULL);
16 }
17
18 ScopedLoopObserver::~ScopedLoopObserver() {
19 ObserveLoopDestruction(false, NULL);
20 }
21
22 void ScopedLoopObserver::ObserveLoopDestruction(bool enable,
23 base::WaitableEvent* done) {
24 // Note: |done| may be NULL.
25 if (loop_->BelongsToCurrentThread()) {
26 base::MessageLoop* loop = base::MessageLoop::current();
27 if (enable) {
28 loop->AddDestructionObserver(this);
29 } else {
30 loop->RemoveDestructionObserver(this);
31 }
32 } else {
33 base::WaitableEvent event(false, false);
34 if (loop_->PostTask(FROM_HERE,
35 base::Bind(&ScopedLoopObserver::ObserveLoopDestruction,
36 base::Unretained(this), enable, &event))) {
37 event.Wait();
38 } else {
39 // The message loop's thread has already terminated, so no need to wait.
40 }
41 }
42
43 if (done)
44 done->Signal();
45 }
46
47 } // namespace media.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698