Chromium Code Reviews| Index: chromeos/audio/cras_audio_handler.h |
| diff --git a/chromeos/audio/cras_audio_handler.h b/chromeos/audio/cras_audio_handler.h |
| index 10c77a471da34484a652cd488124cccf26c5613d..be9a42001f1fcee625654edb4267dfcede486e70 100644 |
| --- a/chromeos/audio/cras_audio_handler.h |
| +++ b/chromeos/audio/cras_audio_handler.h |
| @@ -22,6 +22,10 @@ |
| class PrefRegistrySimple; |
| class PrefService; |
| +namespace media { |
| +class AudioManager; |
|
stevenjb
2015/07/01 21:11:53
Is this needed? I don't see any references to it b
|
| +} |
| + |
| namespace chromeos { |
| class AudioDevicesPrefHandler; |
| @@ -64,9 +68,38 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, |
| DISALLOW_COPY_AND_ASSIGN(AudioObserver); |
| }; |
| + // The wrapper for audio manager methods to be called from this class. |
| + // The detail of AudioManager is hidden from CrasAudioHandler. |
| + class AudioManagerWrapper { |
| + public: |
| + virtual ~AudioManagerWrapper(); |
| + virtual void SetHasInputDevices(bool has_input_devices) = 0; |
| + |
| + protected: |
| + AudioManagerWrapper(); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AudioManagerWrapper); |
| + }; |
| + |
| + // The implementation of AudioManagerWrapper for production code. |
| + class AudioManagerWrapperImpl : public AudioManagerWrapper { |
| + public: |
| + AudioManagerWrapperImpl(); |
| + ~AudioManagerWrapperImpl() override; |
| + void SetHasInputDevices(bool has_input_devices) override; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AudioManagerWrapperImpl); |
| + }; |
| + |
| // Sets the global instance. Must be called before any calls to Get(). |
| + // An implemantation of AudioManagerWrapper is passed to constructor |
| + // of CrasAudioHandler. It should be AudioManagerWrapperImpl |
| + // for production code. |
| static void Initialize( |
| - scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); |
| + scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler, |
| + scoped_ptr<AudioManagerWrapper> audio_manager); |
| // Sets the global instance for testing. |
| static void InitializeForTesting(); |
| @@ -199,13 +232,27 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, |
| bool force_rediscovering); |
| protected: |
| - explicit CrasAudioHandler( |
| - scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); |
| + CrasAudioHandler(scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler, |
| + scoped_ptr<AudioManagerWrapper> audio_manager); |
| ~CrasAudioHandler() override; |
| private: |
| friend class CrasAudioHandlerTest; |
| + // The implementation of AudioManagerWrapper for testing. |
| + // This implementation is used in unittest which needs CrasAudioHandler |
| + // while there is no AudioManagerCras, e.g.: running unittests related |
| + // to Cras on Linux. |
| + class AudioManagerWrapperForTesting : public AudioManagerWrapper { |
| + public: |
| + AudioManagerWrapperForTesting(); |
| + ~AudioManagerWrapperForTesting() override; |
| + void SetHasInputDevices(bool has_input_devices) override; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AudioManagerWrapperForTesting); |
| + }; |
| + |
| // CrasAudioClient::Observer overrides. |
| void AudioClientRestarted() override; |
| void NodesChanged() override; |
| @@ -291,6 +338,12 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, |
| void HandleGetNodesError(const std::string& error_name, |
| const std::string& error_msg); |
| + // Sets HasInputDevice in AudioManager based on the updated device list. |
| + void UpdateAudioManagerHasInputDevices(); |
| + |
| + // Sets HasInputDevice in AudioManager to true or false. |
| + void SetAudioManagerHasInputDevices(bool has_input_devices); |
| + |
| // Adds an active node. |
| // If there is no active node, |node_id| will be switched to become the |
| // primary active node. Otherwise, it will be added as an additional active |
| @@ -328,6 +381,10 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, |
| scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_; |
| base::ObserverList<AudioObserver> observers_; |
| + // audio_manager_ will hold an AudioManagerWrapperImpl object or |
| + // a mocked AudioManagerWrapper object for testing. |
| + scoped_ptr<CrasAudioHandler::AudioManagerWrapper> audio_manager_; |
| + |
| // Audio data and state. |
| AudioDeviceMap audio_devices_; |