Chromium Code Reviews| Index: content/renderer/media/audio_ipc_factory.h |
| diff --git a/content/renderer/media/audio_ipc_factory.h b/content/renderer/media/audio_ipc_factory.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..edbc3c5ab74053d635cfa8cce7d738d2e4f5a0c2 |
| --- /dev/null |
| +++ b/content/renderer/media/audio_ipc_factory.h |
| @@ -0,0 +1,95 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_ |
| +#define CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_ |
| + |
| +#include <memory> |
| + |
| +#include "base/containers/flat_map.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "content/common/content_export.h" |
| +#include "content/common/media/renderer_audio_output_stream_factory.mojom.h" |
| +#include "content/renderer/media/audio_message_filter.h" |
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| +} |
| + |
| +namespace media { |
| +class AudioOutputIPC; |
| +} |
| + |
| +namespace service_manager { |
| +class InterfaceProvider; |
| +} |
| + |
| +namespace content { |
| + |
| +// This is a factory for AudioOutputIPC objects. It has two modes, using either |
| +// AudioMessageFilter or Mojo RendererAudioOutputStreamFactory objects. It is |
| +// threadsafe. This class is designed to be leaked at shutdown, as it posts |
| +// tasks to itself using base::Unretained and also hands out references to |
| +// itself in the AudioOutputIPCs it creates, but in the case where the owner is |
| +// sure that there are no outstanding references (such as in a unit test), the |
| +// class can be destructed. |
| +// TODO(maxmorin): Registering the factories for each frame will become |
| +// unnecessary when crbug.com/668275 is fixed. When that is done, this class can |
| +// be greatly simplified. |
| +class CONTENT_EXPORT AudioIPCFactory { |
| + public: |
| + AudioIPCFactory( |
| + const scoped_refptr<AudioMessageFilter>& audio_message_filter, |
|
DaleCurtis
2017/05/31 20:48:09
No const&.
Max Morin
2017/06/01 13:58:43
Done.
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| + ~AudioIPCFactory(); |
| + |
| + static AudioIPCFactory* get() { return instance_; } |
| + |
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner() const { |
|
DaleCurtis
2017/05/31 20:48:09
Ditto.
Max Morin
2017/06/01 13:58:43
Done.
|
| + return io_task_runner_; |
| + } |
| + |
| + // Enables |this| to create MojoAudioOutputIPCs for the specified frame. |
|
DaleCurtis
2017/05/31 20:48:09
Comment needs to qualify why this is labeled Maybe
Max Morin
2017/06/01 13:58:43
Done.
|
| + void MaybeRegisterRemoteFactory( |
| + int frame_id, |
| + service_manager::InterfaceProvider* interface_provider); |
| + |
| + // Every call to the above method must be matched by a call to this one when |
|
DaleCurtis
2017/05/31 20:48:09
Ditto.
Max Morin
2017/06/01 13:58:43
Done.
|
| + // the frame is destroyed. |
| + void MaybeDeregisterRemoteFactory(int frame_id); |
| + |
| + // The returned object may only be used on |io_task_runner()|. |
| + std::unique_ptr<media::AudioOutputIPC> CreateAudioOutputIPC( |
| + int frame_id) const; |
| + |
| + private: |
| + using StreamFactoryMap = |
| + base::flat_map<int, mojom::RendererAudioOutputStreamFactoryPtr>; |
| + |
| + mojom::RendererAudioOutputStreamFactory* GetRemoteFactory(int frame_id) const; |
| + |
| + void RegisterRemoteFactoryOnIOThread( |
| + int frame_id, |
| + mojom::RendererAudioOutputStreamFactoryPtrInfo factory_ptr_info); |
| + |
| + // Indicates whether mojo factories are used. |
| + bool UsingMojoFactories() const; |
| + |
| + // Maps frame id to the corresponding factory. |
| + StreamFactoryMap factory_ptrs_; |
| + |
| + // If this is non-null, it will be used rather than using mojo implementation. |
| + const scoped_refptr<AudioMessageFilter> audio_message_filter_; |
| + |
| + const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| + |
| + // Global instance, set in constructor and unset in destructor. |
| + static AudioIPCFactory* instance_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioIPCFactory); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_ |