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

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

Issue 2869733005: Convert some audio code to OnceCallback. (Closed)
Patch Set: Rebase, comments on unretained. Created 3 years, 7 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
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 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 28 matching lines...) Expand all
39 UMA_HISTOGRAM_CUSTOM_TIMES("Media.Audio.OutputDeviceAuthorizationTime", 39 UMA_HISTOGRAM_CUSTOM_TIMES("Media.Audio.OutputDeviceAuthorizationTime",
40 base::TimeTicks::Now() - auth_start_time, 40 base::TimeTicks::Now() - auth_start_time,
41 base::TimeDelta::FromMilliseconds(1), 41 base::TimeDelta::FromMilliseconds(1),
42 base::TimeDelta::FromMilliseconds(5000), 50); 42 base::TimeDelta::FromMilliseconds(5000), 50);
43 } 43 }
44 44
45 // Check that the routing ID references a valid RenderFrameHost, and run 45 // Check that the routing ID references a valid RenderFrameHost, and run
46 // |callback| on the IO thread with true if the ID is valid. 46 // |callback| on the IO thread with true if the ID is valid.
47 void ValidateRenderFrameId(int render_process_id, 47 void ValidateRenderFrameId(int render_process_id,
48 int render_frame_id, 48 int render_frame_id,
49 const base::Callback<void(bool)>& callback) { 49 base::OnceCallback<void(bool)> callback) {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI); 50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
51 const bool frame_exists = 51 const bool frame_exists =
52 !!RenderFrameHost::FromID(render_process_id, render_frame_id); 52 !!RenderFrameHost::FromID(render_process_id, render_frame_id);
53 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 53 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
54 base::Bind(callback, frame_exists)); 54 base::BindOnce(std::move(callback), frame_exists));
55 } 55 }
56 56
57 } // namespace 57 } // namespace
58 58
59 /////////////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////////////
60 // AudioRendererHost implementations. 60 // AudioRendererHost implementations.
61 61
62 AudioRendererHost::AudioRendererHost(int render_process_id, 62 AudioRendererHost::AudioRendererHost(int render_process_id,
63 media::AudioManager* audio_manager, 63 media::AudioManager* audio_manager,
64 media::AudioSystem* audio_system, 64 media::AudioSystem* audio_system,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id)) 184 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id))
185 return; 185 return;
186 186
187 authorizations_.insert( 187 authorizations_.insert(
188 std::make_pair(stream_id, std::make_pair(false, std::string()))); 188 std::make_pair(stream_id, std::make_pair(false, std::string())));
189 189
190 // Unretained is ok here since |this| owns |authorization_handler_| and 190 // Unretained is ok here since |this| owns |authorization_handler_| and
191 // |authorization_handler_| owns the callback. 191 // |authorization_handler_| owns the callback.
192 authorization_handler_.RequestDeviceAuthorization( 192 authorization_handler_.RequestDeviceAuthorization(
193 render_frame_id, session_id, device_id, security_origin, 193 render_frame_id, session_id, device_id, security_origin,
194 base::Bind(&AudioRendererHost::AuthorizationCompleted, 194 base::BindOnce(&AudioRendererHost::AuthorizationCompleted,
195 base::Unretained(this), stream_id, security_origin, 195 base::Unretained(this), stream_id, security_origin,
196 auth_start_time)); 196 auth_start_time));
197 } 197 }
198 198
199 void AudioRendererHost::AuthorizationCompleted( 199 void AudioRendererHost::AuthorizationCompleted(
200 int stream_id, 200 int stream_id,
201 const url::Origin& security_origin, 201 const url::Origin& security_origin,
202 base::TimeTicks auth_start_time, 202 base::TimeTicks auth_start_time,
203 media::OutputDeviceStatus status, 203 media::OutputDeviceStatus status,
204 bool should_send_id, 204 bool should_send_id,
205 const media::AudioParameters& params, 205 const media::AudioParameters& params,
206 const std::string& raw_device_id) { 206 const std::string& raw_device_id) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 SendErrorMessage(stream_id); 272 SendErrorMessage(stream_id);
273 return; 273 return;
274 } 274 }
275 275
276 // Post a task to the UI thread to check that the |render_frame_id| references 276 // Post a task to the UI thread to check that the |render_frame_id| references
277 // a valid render frame. This validation is important for all the reasons 277 // a valid render frame. This validation is important for all the reasons
278 // stated in the comments above. This does not block stream creation, but will 278 // stated in the comments above. This does not block stream creation, but will
279 // force-close the stream later if validation fails. 279 // force-close the stream later if validation fails.
280 BrowserThread::PostTask( 280 BrowserThread::PostTask(
281 BrowserThread::UI, FROM_HERE, 281 BrowserThread::UI, FROM_HERE,
282 base::Bind(validate_render_frame_id_function_, render_process_id_, 282 base::BindOnce(validate_render_frame_id_function_, render_process_id_,
283 render_frame_id, 283 render_frame_id,
284 base::Bind(&AudioRendererHost::DidValidateRenderFrame, this, 284 base::BindOnce(&AudioRendererHost::DidValidateRenderFrame,
285 stream_id))); 285 this, stream_id)));
286 286
287 MediaObserver* const media_observer = 287 MediaObserver* const media_observer =
288 GetContentClient()->browser()->GetMediaObserver(); 288 GetContentClient()->browser()->GetMediaObserver();
289 289
290 MediaInternals* const media_internals = MediaInternals::GetInstance(); 290 MediaInternals* const media_internals = MediaInternals::GetInstance();
291 std::unique_ptr<media::AudioLog> audio_log = media_internals->CreateAudioLog( 291 std::unique_ptr<media::AudioLog> audio_log = media_internals->CreateAudioLog(
292 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER); 292 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER);
293 media_internals->SetWebContentsTitleForAudioLogEntry( 293 media_internals->SetWebContentsTitleForAudioLogEntry(
294 stream_id, render_process_id_, render_frame_id, audio_log.get()); 294 stream_id, render_process_id_, render_frame_id, audio_log.get());
295 delegates_.push_back( 295 delegates_.push_back(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 377
378 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { 378 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) {
379 DCHECK_CURRENTLY_ON(BrowserThread::IO); 379 DCHECK_CURRENTLY_ON(BrowserThread::IO);
380 return authorizations_.find(stream_id) != authorizations_.end(); 380 return authorizations_.find(stream_id) != authorizations_.end();
381 } 381 }
382 382
383 void AudioRendererHost::OverrideDevicePermissionsForTesting(bool has_access) { 383 void AudioRendererHost::OverrideDevicePermissionsForTesting(bool has_access) {
384 authorization_handler_.OverridePermissionsForTesting(has_access); 384 authorization_handler_.OverridePermissionsForTesting(has_access);
385 } 385 }
386 } // namespace content 386 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698