Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_ | |
| 6 #define CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/containers/flat_map.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "content/common/content_export.h" | |
| 13 #include "content/common/media/renderer_audio_output_stream_factory.mojom.h" | |
| 14 #include "content/renderer/media/audio_message_filter.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class SingleThreadTaskRunner; | |
| 18 } | |
| 19 | |
| 20 namespace media { | |
| 21 class AudioOutputIPC; | |
| 22 } | |
| 23 | |
| 24 namespace service_manager { | |
| 25 class InterfaceProvider; | |
| 26 } | |
| 27 | |
| 28 namespace content { | |
| 29 | |
| 30 // This is a factory for AudioOutputIPC objects. It has two modes, using either | |
| 31 // AudioMessageFilter or Mojo RendererAudioOutputStreamFactory objects. It is | |
| 32 // threadsafe. This class is designed to be leaked at shutdown, as it posts | |
| 33 // tasks to itself using base::Unretained and also hands out references to | |
| 34 // itself in the AudioOutputIPCs it creates, but in the case where the owner is | |
| 35 // sure that there are no outstanding references (such as in a unit test), the | |
| 36 // class can be destructed. | |
| 37 // TODO(maxmorin): Registering the factories for each frame will become | |
| 38 // unnecessary when crbug.com/668275 is fixed. When that is done, this class can | |
| 39 // be greatly simplified. | |
| 40 class CONTENT_EXPORT AudioIPCFactory { | |
| 41 public: | |
| 42 AudioIPCFactory( | |
| 43 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.
| |
| 44 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
| 45 ~AudioIPCFactory(); | |
| 46 | |
| 47 static AudioIPCFactory* get() { return instance_; } | |
| 48 | |
| 49 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.
| |
| 50 return io_task_runner_; | |
| 51 } | |
| 52 | |
| 53 // 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.
| |
| 54 void MaybeRegisterRemoteFactory( | |
| 55 int frame_id, | |
| 56 service_manager::InterfaceProvider* interface_provider); | |
| 57 | |
| 58 // 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.
| |
| 59 // the frame is destroyed. | |
| 60 void MaybeDeregisterRemoteFactory(int frame_id); | |
| 61 | |
| 62 // The returned object may only be used on |io_task_runner()|. | |
| 63 std::unique_ptr<media::AudioOutputIPC> CreateAudioOutputIPC( | |
| 64 int frame_id) const; | |
| 65 | |
| 66 private: | |
| 67 using StreamFactoryMap = | |
| 68 base::flat_map<int, mojom::RendererAudioOutputStreamFactoryPtr>; | |
| 69 | |
| 70 mojom::RendererAudioOutputStreamFactory* GetRemoteFactory(int frame_id) const; | |
| 71 | |
| 72 void RegisterRemoteFactoryOnIOThread( | |
| 73 int frame_id, | |
| 74 mojom::RendererAudioOutputStreamFactoryPtrInfo factory_ptr_info); | |
| 75 | |
| 76 // Indicates whether mojo factories are used. | |
| 77 bool UsingMojoFactories() const; | |
| 78 | |
| 79 // Maps frame id to the corresponding factory. | |
| 80 StreamFactoryMap factory_ptrs_; | |
| 81 | |
| 82 // If this is non-null, it will be used rather than using mojo implementation. | |
| 83 const scoped_refptr<AudioMessageFilter> audio_message_filter_; | |
| 84 | |
| 85 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
| 86 | |
| 87 // Global instance, set in constructor and unset in destructor. | |
| 88 static AudioIPCFactory* instance_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(AudioIPCFactory); | |
| 91 }; | |
| 92 | |
| 93 } // namespace content | |
| 94 | |
| 95 #endif // CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_ | |
| OLD | NEW |