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

Unified Diff: media/blink/webaudiosourceprovider_impl.cc

Issue 2539773003: Merge M56: "Remove unnecessary lock on setClient()." (Closed)
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/webaudiosourceprovider_impl.cc
diff --git a/media/blink/webaudiosourceprovider_impl.cc b/media/blink/webaudiosourceprovider_impl.cc
index e54dbc81aa1f4e9d37989d16385b47f8707dae10..9b135356f3514a78e704f6869bb66291b0a1a270 100644
--- a/media/blink/webaudiosourceprovider_impl.cc
+++ b/media/blink/webaudiosourceprovider_impl.cc
@@ -105,8 +105,13 @@ WebAudioSourceProviderImpl::~WebAudioSourceProviderImpl() {
void WebAudioSourceProviderImpl::setClient(
blink::WebAudioSourceProviderClient* client) {
+ // Skip taking the lock if unnecessary. This function is the only setter for
+ // |client_| so it's safe to check |client_| outside of the lock.
+ if (client_ == client)
+ return;
+
base::AutoLock auto_lock(sink_lock_);
- if (client && client != client_) {
+ if (client) {
// Detach the audio renderer from normal playback.
sink_->Stop();
@@ -122,15 +127,16 @@ void WebAudioSourceProviderImpl::setClient(
// ensures we have the same locking order when calling into |client_|.
if (tee_filter_->IsInitialized())
base::ResetAndReturn(&set_format_cb_).Run();
- } else if (!client && client_) {
- // Restore normal playback.
- client_ = nullptr;
- sink_->SetVolume(volume_);
- if (state_ >= kStarted)
- sink_->Start();
- if (state_ >= kPlaying)
- sink_->Play();
+ return;
}
+
+ // Restore normal playback.
+ client_ = nullptr;
+ sink_->SetVolume(volume_);
+ if (state_ >= kStarted)
+ sink_->Start();
+ if (state_ >= kPlaying)
+ sink_->Play();
}
void WebAudioSourceProviderImpl::provideInput(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698