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

Side by Side Diff: media/audio/audio_manager.cc

Issue 2668813002: Remove LazyInstance usage from media/ (Closed)
Patch Set: Fix presubmit comments. Created 3 years, 10 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
« no previous file with comments | « media/PRESUBMIT.py ('k') | media/audio/simple_sources.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/audio/audio_manager.h" 5 #include "media/audio/audio_manager.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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
13 #include "base/debug/crash_logging.h" 13 #include "base/debug/crash_logging.h"
14 #include "base/debug/dump_without_crashing.h" 14 #include "base/debug/dump_without_crashing.h"
15 #include "base/lazy_instance.h"
16 #include "base/logging.h" 15 #include "base/logging.h"
17 #include "base/macros.h" 16 #include "base/macros.h"
18 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
19 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
20 #include "base/power_monitor/power_monitor.h" 19 #include "base/power_monitor/power_monitor.h"
21 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
22 #include "build/build_config.h" 21 #include "build/build_config.h"
23 #include "media/audio/fake_audio_log_factory.h" 22 #include "media/audio/fake_audio_log_factory.h"
24 #include "media/base/media_switches.h" 23 #include "media/base/media_switches.h"
25 24
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 std::unique_ptr<base::win::ScopedCOMInitializer> com_initializer_for_testing_; 252 std::unique_ptr<base::win::ScopedCOMInitializer> com_initializer_for_testing_;
254 #endif 253 #endif
255 254
256 #if defined(OS_LINUX) 255 #if defined(OS_LINUX)
257 std::string app_name_; 256 std::string app_name_;
258 #endif 257 #endif
259 258
260 DISALLOW_COPY_AND_ASSIGN(AudioManagerHelper); 259 DISALLOW_COPY_AND_ASSIGN(AudioManagerHelper);
261 }; 260 };
262 261
263 base::LazyInstance<AudioManagerHelper>::Leaky g_helper = 262 AudioManagerHelper* GetHelper() {
264 LAZY_INSTANCE_INITIALIZER; 263 static AudioManagerHelper* helper = new AudioManagerHelper();
264 return helper;
265 }
265 266
266 } // namespace 267 } // namespace
267 268
268 void AudioManagerDeleter::operator()(const AudioManager* instance) const { 269 void AudioManagerDeleter::operator()(const AudioManager* instance) const {
269 CHECK(instance); 270 CHECK(instance);
270 // We reset g_last_created here instead of in the destructor of AudioManager 271 // We reset g_last_created here instead of in the destructor of AudioManager
271 // because the destructor runs on the audio thread. We want to always change 272 // because the destructor runs on the audio thread. We want to always change
272 // g_last_created from the main thread. 273 // g_last_created from the main thread.
273 if (g_last_created == instance) { 274 if (g_last_created == instance) {
274 g_last_created = nullptr; 275 g_last_created = nullptr;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 DCHECK(task_runner); 338 DCHECK(task_runner);
338 DCHECK(worker_task_runner); 339 DCHECK(worker_task_runner);
339 return CreateAudioManager(std::move(task_runner), 340 return CreateAudioManager(std::move(task_runner),
340 std::move(worker_task_runner), audio_log_factory); 341 std::move(worker_task_runner), audio_log_factory);
341 } 342 }
342 343
343 // static 344 // static
344 ScopedAudioManagerPtr AudioManager::CreateForTesting( 345 ScopedAudioManagerPtr AudioManager::CreateForTesting(
345 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 346 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
346 #if defined(OS_WIN) 347 #if defined(OS_WIN)
347 g_helper.Pointer()->InitializeCOMForTesting(); 348 GetHelper()->InitializeCOMForTesting();
348 #endif 349 #endif
349 return Create(task_runner, task_runner, 350 return Create(task_runner, task_runner, GetHelper()->fake_log_factory());
350 g_helper.Pointer()->fake_log_factory());
351 } 351 }
352 352
353 // static 353 // static
354 void AudioManager::StartHangMonitorIfNeeded( 354 void AudioManager::StartHangMonitorIfNeeded(
355 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 355 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
356 if (g_helper.Pointer()->monitor_task_runner()) 356 if (GetHelper()->monitor_task_runner())
357 return; 357 return;
358 358
359 DCHECK(AudioManager::Get()); 359 DCHECK(AudioManager::Get());
360 DCHECK(task_runner); 360 DCHECK(task_runner);
361 DCHECK_NE(task_runner, AudioManager::Get()->GetTaskRunner()); 361 DCHECK_NE(task_runner, AudioManager::Get()->GetTaskRunner());
362 362
363 g_helper.Pointer()->StartHangTimer(std::move(task_runner)); 363 GetHelper()->StartHangTimer(std::move(task_runner));
364 } 364 }
365 365
366 // static 366 // static
367 void AudioManager::EnableCrashKeyLoggingForAudioThreadHangs() { 367 void AudioManager::EnableCrashKeyLoggingForAudioThreadHangs() {
368 CHECK(!g_last_created); 368 CHECK(!g_last_created);
369 g_helper.Pointer()->enable_crash_key_logging(); 369 GetHelper()->enable_crash_key_logging();
370 } 370 }
371 371
372 #if defined(OS_LINUX) 372 #if defined(OS_LINUX)
373 // static 373 // static
374 void AudioManager::SetGlobalAppName(const std::string& app_name) { 374 void AudioManager::SetGlobalAppName(const std::string& app_name) {
375 g_helper.Pointer()->set_app_name(app_name); 375 GetHelper()->set_app_name(app_name);
376 } 376 }
377 377
378 // static 378 // static
379 const std::string& AudioManager::GetGlobalAppName() { 379 const std::string& AudioManager::GetGlobalAppName() {
380 return g_helper.Pointer()->app_name(); 380 return GetHelper()->app_name();
381 } 381 }
382 #endif 382 #endif
383 383
384 // static 384 // static
385 AudioManager* AudioManager::Get() { 385 AudioManager* AudioManager::Get() {
386 return g_last_created; 386 return g_last_created;
387 } 387 }
388 388
389 } // namespace media 389 } // namespace media
OLDNEW
« no previous file with comments | « media/PRESUBMIT.py ('k') | media/audio/simple_sources.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698