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

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.cc

Issue 2529853002: Fix shutdown crash in AudioOutputAuthorizationHandler. (Closed)
Patch Set: . Created 4 years 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
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 "content/browser/renderer_host/media/audio_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_renderer_host.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 26 matching lines...) Expand all
37 37
38 namespace content { 38 namespace content {
39 39
40 namespace { 40 namespace {
41 41
42 // Tracks the maximum number of simultaneous output streams browser-wide. 42 // Tracks the maximum number of simultaneous output streams browser-wide.
43 // Accessed on IO thread. 43 // Accessed on IO thread.
44 base::LazyInstance<media::AudioStreamsTracker> g_audio_streams_tracker = 44 base::LazyInstance<media::AudioStreamsTracker> g_audio_streams_tracker =
45 LAZY_INSTANCE_INITIALIZER; 45 LAZY_INSTANCE_INITIALIZER;
46 46
47 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData(
48 int stream_id,
49 bool authorized,
50 const std::string& device_unique_id) {
51 return std::make_pair(stream_id,
52 std::make_pair(authorized, device_unique_id));
53 }
54
55
56 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { 47 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) {
57 DCHECK_CURRENTLY_ON(BrowserThread::UI); 48 DCHECK_CURRENTLY_ON(BrowserThread::UI);
58 49
59 RenderProcessHost* render_process_host = 50 RenderProcessHost* render_process_host =
60 RenderProcessHost::FromID(render_process_id); 51 RenderProcessHost::FromID(render_process_id);
61 52
62 if (render_process_host) 53 if (render_process_host)
63 render_process_host->AudioStateChanged(); 54 render_process_host->AudioStateChanged();
64 } 55 }
65 56
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 : BrowserMessageFilter(AudioMsgStart), 183 : BrowserMessageFilter(AudioMsgStart),
193 render_process_id_(render_process_id), 184 render_process_id_(render_process_id),
194 audio_manager_(audio_manager), 185 audio_manager_(audio_manager),
195 mirroring_manager_(mirroring_manager), 186 mirroring_manager_(mirroring_manager),
196 audio_log_(media_internals->CreateAudioLog( 187 audio_log_(media_internals->CreateAudioLog(
197 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER)), 188 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER)),
198 num_playing_streams_(0), 189 num_playing_streams_(0),
199 salt_(salt), 190 salt_(salt),
200 validate_render_frame_id_function_(&ValidateRenderFrameId), 191 validate_render_frame_id_function_(&ValidateRenderFrameId),
201 max_simultaneous_streams_(0), 192 max_simultaneous_streams_(0),
202 authorization_handler_(media_stream_manager, render_process_id_, salt) { 193 authorization_handler_(audio_manager_,
194 media_stream_manager,
195 render_process_id_,
196 salt) {
203 DCHECK(audio_manager_); 197 DCHECK(audio_manager_);
204 } 198 }
205 199
206 AudioRendererHost::~AudioRendererHost() { 200 AudioRendererHost::~AudioRendererHost() {
207 DCHECK_CURRENTLY_ON(BrowserThread::IO); 201 DCHECK_CURRENTLY_ON(BrowserThread::IO);
208 CHECK(audio_entries_.empty()); 202 CHECK(audio_entries_.empty());
209 203
210 // If we had any streams, report UMA stats for the maximum number of 204 // If we had any streams, report UMA stats for the maximum number of
211 // simultaneous streams for this render process and for the whole browser 205 // simultaneous streams for this render process and for the whole browser
212 // process since last reported. 206 // process since last reported.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 const url::Origin& security_origin) { 374 const url::Origin& security_origin) {
381 DCHECK_CURRENTLY_ON(BrowserThread::IO); 375 DCHECK_CURRENTLY_ON(BrowserThread::IO);
382 const base::TimeTicks auth_start_time = base::TimeTicks::Now(); 376 const base::TimeTicks auth_start_time = base::TimeTicks::Now();
383 DVLOG(1) << "AudioRendererHost@" << this << "::OnRequestDeviceAuthorization" 377 DVLOG(1) << "AudioRendererHost@" << this << "::OnRequestDeviceAuthorization"
384 << "(stream_id=" << stream_id 378 << "(stream_id=" << stream_id
385 << ", render_frame_id=" << render_frame_id 379 << ", render_frame_id=" << render_frame_id
386 << ", session_id=" << session_id << ", device_id=" << device_id 380 << ", session_id=" << session_id << ", device_id=" << device_id
387 << ", security_origin=" << security_origin << ")"; 381 << ", security_origin=" << security_origin << ")";
388 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id)) 382 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id))
389 return; 383 return;
390 authorizations_.insert(MakeAuthorizationData(stream_id, false, device_id)); 384
385 authorizations_.insert(
386 std::make_pair(stream_id, std::make_pair(false, std::string())));
387
391 // Unretained is ok here since |this| owns |authorization_handler_| and 388 // Unretained is ok here since |this| owns |authorization_handler_| and
392 // |authorization_handler_| owns the callback. 389 // |authorization_handler_| owns the callback.
393 authorization_handler_.RequestDeviceAuthorization( 390 authorization_handler_.RequestDeviceAuthorization(
394 render_frame_id, session_id, device_id, security_origin, 391 render_frame_id, session_id, device_id, security_origin,
395 base::Bind(&AudioRendererHost::AuthorizationCompleted, 392 base::Bind(&AudioRendererHost::AuthorizationCompleted,
396 base::Unretained(this), stream_id, security_origin, 393 base::Unretained(this), stream_id, security_origin,
397 auth_start_time)); 394 auth_start_time));
398 } 395 }
399 396
400 void AudioRendererHost::AuthorizationCompleted( 397 void AudioRendererHost::AuthorizationCompleted(
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 } 647 }
651 648
652 bool AudioRendererHost::HasActiveAudio() { 649 bool AudioRendererHost::HasActiveAudio() {
653 return !base::AtomicRefCountIsZero(&num_playing_streams_); 650 return !base::AtomicRefCountIsZero(&num_playing_streams_);
654 } 651 }
655 652
656 void AudioRendererHost::OverrideDevicePermissionsForTesting(bool has_access) { 653 void AudioRendererHost::OverrideDevicePermissionsForTesting(bool has_access) {
657 authorization_handler_.OverridePermissionsForTesting(has_access); 654 authorization_handler_.OverridePermissionsForTesting(has_access);
658 } 655 }
659 } // namespace content 656 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698