Introduce AudioIPCFactory.

AudioIPCFactory is introduced to manage RendererAudioOutputStreamFactory
pointers, which is needed for various reasons.
* When processing an authorization request, it is not safe to use other
  threads than the IO thread, as they may be blocked waiting for the
  response. Thus, AudioIPCFactory is introduced to hold a mapping
  (frame id->remote factory) on the IO thread. This also means we have
  to create/destruct the RendererAudioOutputStreamFactoryPtr with the
  RenderFrameImpl instead of the preferrable way of doing it lazily.
  This should be revisited if we stop blocking while waiting for
  authorization (crbug.com/668275).
* For running browser tests with this, the browser-side glue code is
  needed. I have verified that the browser tests pass. As the pepper
  code doesn't seem well covered by tests, I also manually verified
  that flash sound output works.
* There's a class diagram at https://docs.google.com/drawings/d/1U1e-0gH3WVSV9Td9ZCEcPDBMC7WWWeh58sRYAdXbrn8/edit?usp=sharing

BUG=425368

Review-Url: https://codereview.chromium.org/2890753003
Cr-Commit-Position: refs/heads/master@{#476612}
diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h
index 5d57ec6..ecf995c 100644
--- a/content/renderer/render_thread_impl.h
+++ b/content/renderer/render_thread_impl.h
@@ -8,9 +8,11 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#include <map>
 #include <memory>
 #include <set>
 #include <string>
+#include <utility>
 #include <vector>
 
 #include "base/cancelable_callback.h"
@@ -21,6 +23,7 @@
 #include "base/metrics/field_trial.h"
 #include "base/metrics/user_metrics_action.h"
 #include "base/observer_list.h"
+#include "base/optional.h"
 #include "base/strings/string16.h"
 #include "base/threading/thread_checker.h"
 #include "base/time/time.h"
@@ -41,6 +44,7 @@
 #include "content/public/renderer/render_thread.h"
 #include "content/renderer/gpu/compositor_dependencies.h"
 #include "content/renderer/layout_test_dependencies.h"
+#include "content/renderer/media/audio_ipc_factory.h"
 #include "gpu/ipc/client/gpu_channel_host.h"
 #include "media/media_features.h"
 #include "mojo/public/cpp/bindings/associated_binding.h"
@@ -319,10 +323,6 @@
     return audio_input_message_filter_.get();
   }
 
-  AudioMessageFilter* audio_message_filter() {
-    return audio_message_filter_.get();
-  }
-
   MidiMessageFilter* midi_message_filter() {
     return midi_message_filter_.get();
   }
@@ -619,7 +619,6 @@
   scoped_refptr<BlobMessageFilter> blob_message_filter_;
   scoped_refptr<DBMessageFilter> db_message_filter_;
   scoped_refptr<AudioInputMessageFilter> audio_input_message_filter_;
-  scoped_refptr<AudioMessageFilter> audio_message_filter_;
   scoped_refptr<MidiMessageFilter> midi_message_filter_;
   scoped_refptr<DevToolsAgentFilter> devtools_agent_message_filter_;
 
@@ -642,6 +641,11 @@
   scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_;
 #endif
 
+  // Provides AudioOutputIPC objects for audio output devices. It either uses
+  // an AudioMessageFilter for this or provides MojoAudioOutputIPC objects.
+  // Initialized in Init.
+  base::Optional<AudioIPCFactory> audio_ipc_factory_;
+
   // Used on the render thread.
   std::unique_ptr<VideoCaptureImplManager> vc_manager_;