Home | History | Annotate | Download | only in audio
      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
      3 // found in the LICENSE file.
      4 
      5 #include "media/audio/audio_manager.h"
      6 
      7 #include "base/bind.h"
      8 #include "base/bind_helpers.h"
      9 #include "base/lazy_instance.h"
     10 #include "base/logging.h"
     11 #include "base/message_loop/message_loop.h"
     12 #include "media/audio/fake_audio_log_factory.h"
     13 
     14 namespace media {
     15 namespace {
     16 AudioManager* g_last_created = NULL;
     17 }
     18 
     19 // Forward declaration of the platform specific AudioManager factory function.
     20 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory);
     21 
     22 AudioManager::AudioManager() {}
     23 
     24 AudioManager::~AudioManager() {
     25   CHECK(!g_last_created || g_last_created == this);
     26   g_last_created = NULL;
     27 }
     28 
     29 // static
     30 AudioManager* AudioManager::Create(AudioLogFactory* audio_log_factory) {
     31   CHECK(!g_last_created);
     32   g_last_created = CreateAudioManager(audio_log_factory);
     33   return g_last_created;
     34 }
     35 
     36 // static
     37 AudioManager* AudioManager::CreateForTesting() {
     38   static base::LazyInstance<FakeAudioLogFactory>::Leaky fake_log_factory =
     39       LAZY_INSTANCE_INITIALIZER;
     40   return Create(fake_log_factory.Pointer());
     41 }
     42 
     43 // static
     44 AudioManager* AudioManager::Get() {
     45   return g_last_created;
     46 }
     47 
     48 }  // namespace media
     49