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

Side by Side Diff: content/renderer/media/scoped_loop_observer.cc

Issue 9104043: Monitor the IO message loop in the AudioDevice classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indent Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/media/scoped_loop_observer.h ('k') | media/audio/audio_manager_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/renderer/media/scoped_loop_observer.h"
6
7 #include "base/bind.h"
8 #include "base/synchronization/waitable_event.h"
9
10 ScopedLoopObserver::ScopedLoopObserver(MessageLoop* loop)
11 : loop_(loop->message_loop_proxy()) {
12 ObserveLoopDestruction(true, NULL);
13 }
14
15 ScopedLoopObserver::~ScopedLoopObserver() {
16 ObserveLoopDestruction(false, NULL);
17 }
18
19 void ScopedLoopObserver::ObserveLoopDestruction(bool enable,
20 base::WaitableEvent* done) {
21 // Note: |done| may be NULL.
22 if (loop_->BelongsToCurrentThread()) {
23 MessageLoop* loop = MessageLoop::current();
24 if (enable) {
25 loop->AddDestructionObserver(this);
26 } else {
27 loop->RemoveDestructionObserver(this);
28 }
29 } else {
30 base::WaitableEvent event(false, false);
31 if (loop_->PostTask(FROM_HERE,
32 base::Bind(&ScopedLoopObserver::ObserveLoopDestruction,
33 base::Unretained(this), enable, &event))) {
34 event.Wait();
35 } else {
36 // The message loop's thread has already terminated, so no need to wait.
37 }
38 }
39
40 if (done)
41 done->Signal();
42 }
OLDNEW
« no previous file with comments | « content/renderer/media/scoped_loop_observer.h ('k') | media/audio/audio_manager_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698