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

Side by Side Diff: chrome/browser/chromeos/audio/audio_mixer_cras.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/audio/audio_mixer_cras.h" 5 #include "chrome/browser/chromeos/audio/audio_mixer_cras.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <cras_client.h> 8 #include <cras_client.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 26 matching lines...) Expand all
37 is_muted_(false), 37 is_muted_(false),
38 is_mute_locked_(false), 38 is_mute_locked_(false),
39 is_capture_muted_(false), 39 is_capture_muted_(false),
40 is_capture_mute_locked_(false), 40 is_capture_mute_locked_(false),
41 apply_is_pending_(true) { 41 apply_is_pending_(true) {
42 } 42 }
43 43
44 AudioMixerCras::~AudioMixerCras() { 44 AudioMixerCras::~AudioMixerCras() {
45 if (!thread_.get()) 45 if (!thread_.get())
46 return; 46 return;
47 DCHECK(MessageLoop::current() != thread_->message_loop()); 47 DCHECK(base::MessageLoop::current() != thread_->message_loop());
48 48
49 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; 49 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join;
50 thread_->Stop(); 50 thread_->Stop();
51 thread_.reset(); 51 thread_.reset();
52 52
53 cras_client_destroy(client_); 53 cras_client_destroy(client_);
54 } 54 }
55 55
56 void AudioMixerCras::Init() { 56 void AudioMixerCras::Init() {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 132 }
133 133
134 void AudioMixerCras::SetCaptureMuteLocked(bool locked) { 134 void AudioMixerCras::SetCaptureMuteLocked(bool locked) {
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
136 base::AutoLock lock(lock_); 136 base::AutoLock lock(lock_);
137 is_capture_mute_locked_ = locked; 137 is_capture_mute_locked_ = locked;
138 ApplyStateIfNeeded(); 138 ApplyStateIfNeeded();
139 } 139 }
140 140
141 void AudioMixerCras::Connect() { 141 void AudioMixerCras::Connect() {
142 DCHECK(MessageLoop::current() == thread_->message_loop()); 142 DCHECK(base::MessageLoop::current() == thread_->message_loop());
143 143
144 // Create the client structure. 144 // Create the client structure.
145 if (client_ == NULL && cras_client_create(&client_) < 0) { 145 if (client_ == NULL && cras_client_create(&client_) < 0) {
146 LOG(DFATAL) << "cras_client_create() failed"; 146 LOG(DFATAL) << "cras_client_create() failed";
147 return; // TODO(dgreid) change interface so this can return an error. 147 return; // TODO(dgreid) change interface so this can return an error.
148 } 148 }
149 149
150 if (cras_client_connect(client_) != 0) { 150 if (cras_client_connect(client_) != 0) {
151 thread_->message_loop()->PostDelayedTask(FROM_HERE, 151 thread_->message_loop()->PostDelayedTask(FROM_HERE,
152 base::Bind(&AudioMixerCras::Connect, base::Unretained(this)), 152 base::Bind(&AudioMixerCras::Connect, base::Unretained(this)),
153 base::TimeDelta::FromSeconds(kConnectionRetrySleepSec)); 153 base::TimeDelta::FromSeconds(kConnectionRetrySleepSec));
154 return; 154 return;
155 } 155 }
156 client_connected_ = true; 156 client_connected_ = true;
157 157
158 ApplyState(); 158 ApplyState();
159 } 159 }
160 160
161 void AudioMixerCras::ApplyState() { 161 void AudioMixerCras::ApplyState() {
162 DCHECK(MessageLoop::current() == thread_->message_loop()); 162 DCHECK(base::MessageLoop::current() == thread_->message_loop());
163 if (!client_connected_) 163 if (!client_connected_)
164 return; 164 return;
165 165
166 bool should_mute = false; 166 bool should_mute = false;
167 bool should_lock_mute = false; 167 bool should_lock_mute = false;
168 bool should_mute_capture = false; 168 bool should_mute_capture = false;
169 bool should_lock_capture_mute = false; 169 bool should_lock_capture_mute = false;
170 size_t new_volume = 0; 170 size_t new_volume = 0;
171 { 171 {
172 base::AutoLock lock(lock_); 172 base::AutoLock lock(lock_);
(...skipping 21 matching lines...) Expand all
194 void AudioMixerCras::ApplyStateIfNeeded() { 194 void AudioMixerCras::ApplyStateIfNeeded() {
195 lock_.AssertAcquired(); 195 lock_.AssertAcquired();
196 if (client_connected_ && !apply_is_pending_) { 196 if (client_connected_ && !apply_is_pending_) {
197 thread_->message_loop()->PostTask( 197 thread_->message_loop()->PostTask(
198 FROM_HERE, 198 FROM_HERE,
199 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this))); 199 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this)));
200 } 200 }
201 } 201 }
202 202
203 } // namespace chromeos 203 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/audio/audio_mixer_alsa.cc ('k') | chrome/browser/chromeos/chrome_browser_main_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698