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(scoped_refptr<AudioMessageFilter> audio_message_filter, |
| 43 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
| 44 ~AudioIPCFactory(); |
| 45 |
| 46 static AudioIPCFactory* get() { return instance_; } |
| 47 |
| 48 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner() const { |
| 49 return io_task_runner_; |
| 50 } |
| 51 |
| 52 // Enables |this| to create MojoAudioOutputIPCs for the specified frame. |
| 53 // Does nothing if not using mojo factories. |
| 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 |
| 59 // the frame is destroyed. Does nothing if not using mojo factories. |
| 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 void MaybeDeregisterRemoteFactoryOnIOThread(int frame_id); |
| 77 |
| 78 // Indicates whether mojo factories are used. |
| 79 bool UsingMojoFactories() const; |
| 80 |
| 81 // Maps frame id to the corresponding factory. |
| 82 StreamFactoryMap factory_ptrs_; |
| 83 |
| 84 // If this is non-null, it will be used rather than using mojo implementation. |
| 85 const scoped_refptr<AudioMessageFilter> audio_message_filter_; |
| 86 |
| 87 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 88 |
| 89 // Global instance, set in constructor and unset in destructor. |
| 90 static AudioIPCFactory* instance_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(AudioIPCFactory); |
| 93 }; |
| 94 |
| 95 } // namespace content |
| 96 |
| 97 #endif // CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_ |
OLD | NEW |