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

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

Issue 10834033: Move AudioDevice and AudioInputDevice to media. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and fixed a few lint issues Created 8 years, 4 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
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(
11 const scoped_refptr<base::MessageLoopProxy>& loop)
12 : loop_(loop) {
13 ObserveLoopDestruction(true, NULL);
14 }
15
16 ScopedLoopObserver::~ScopedLoopObserver() {
17 ObserveLoopDestruction(false, NULL);
18 }
19
20 void ScopedLoopObserver::ObserveLoopDestruction(bool enable,
21 base::WaitableEvent* done) {
22 // Note: |done| may be NULL.
23 if (loop_->BelongsToCurrentThread()) {
24 MessageLoop* loop = MessageLoop::current();
25 if (enable) {
26 loop->AddDestructionObserver(this);
27 } else {
28 loop->RemoveDestructionObserver(this);
29 }
30 } else {
31 base::WaitableEvent event(false, false);
32 if (loop_->PostTask(FROM_HERE,
33 base::Bind(&ScopedLoopObserver::ObserveLoopDestruction,
34 base::Unretained(this), enable, &event))) {
35 event.Wait();
36 } else {
37 // The message loop's thread has already terminated, so no need to wait.
38 }
39 }
40
41 if (done)
42 done->Signal();
43 }
OLDNEW
« no previous file with comments | « content/renderer/media/scoped_loop_observer.h ('k') | content/renderer/media/webrtc_audio_device_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698