Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2276)

Unified Diff: content/renderer/media/audio_ipc_factory.cc

Issue 2821203005: Add a mojo implementation of AudioOutputIPC. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/audio_ipc_factory.cc
diff --git a/content/renderer/media/audio_ipc_factory.cc b/content/renderer/media/audio_ipc_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b832b320eb63927d1188b8f3ba18226a116779f9
--- /dev/null
+++ b/content/renderer/media/audio_ipc_factory.cc
@@ -0,0 +1,88 @@
+// 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.
+
+#include "content/renderer/media/audio_ipc_factory.h"
+
+#include <utility>
+
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "content/renderer/media/mojo_audio_output_ipc.h"
+
+namespace content {
+
+AudioIPCFactory* AudioIPCFactory::instance_ = nullptr;
+
+AudioIPCFactory::AudioIPCFactory(
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
+ : io_task_runner_(io_task_runner) {
+ DCHECK(!instance_);
+ instance_ = this;
+}
+
+AudioIPCFactory::~AudioIPCFactory() {
+ DCHECK(instance_);
o1ka 2017/04/20 10:35:59 DCHECK_EQ(instance_, this);
Max Morin 2017/05/05 13:10:58 Done.
+ instance_ = nullptr;
+}
+
+std::unique_ptr<media::AudioOutputIPC> AudioIPCFactory::CreateAudioOutputIPC(
+ int frame_id) const {
+ return base::MakeUnique<MojoAudioOutputIPC>(frame_id);
+}
+
+void AudioIPCFactory::RegisterRemoteFactory(
+ int frame_id,
+ mojom::RendererAudioOutputStreamFactoryPtr factory_ptr) {
+ // PassInterface unbinds the message pipe from the current thread. This
+ // allows us to bind it to the IO thread.
+ // Unretained is safe because |this| is owned by the RenderThreadImpl, which
+ // outlives the io thread.
+ io_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&AudioIPCFactory::RegisterRemoteFactoryOnIOThread,
o1ka 2017/04/20 10:35:59 Just post RegisterRemoteFactory() to IO thread if
Max Morin 2017/05/05 13:10:58 The functions have different signatures :).
+ base::Unretained(this), frame_id,
+ base::Passed(factory_ptr.PassInterface())));
+}
+
+void AudioIPCFactory::DeregisterRemoteFactory(int frame_id) {
+ // Unretained is safe because |this| is owned by the RenderThreadImpl, which
+ // outlives the io thread.
+ io_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&AudioIPCFactory::DeregisterRemoteFactoryOnIOThread,
o1ka 2017/04/20 10:35:59 Same here
Max Morin 2017/05/05 13:10:58 Changed it here.
+ base::Unretained(this), frame_id));
+}
+
+mojom::RendererAudioOutputStreamFactory* AudioIPCFactory::GetRemoteFactory(
+ int frame_id) {
+ auto it = factory_ptrs_.find(frame_id);
o1ka 2017/04/20 10:35:59 Thread check?
Max Morin 2017/05/05 13:10:58 Done.
+ return it == factory_ptrs_.end() ? nullptr : it->second.get();
+}
+
+void AudioIPCFactory::RegisterRemoteFactoryOnIOThread(
+ int frame_id,
+ mojom::RendererAudioOutputStreamFactoryPtrInfo factory_ptr_info) {
+ std::pair<StreamFactoryMap::iterator, bool> emplace_result =
+ factory_ptrs_.emplace(frame_id,
+ mojo::MakeProxy(std::move(factory_ptr_info)));
+
+ DCHECK(emplace_result.second) << "Attempt to register a factory for a "
+ "frame which already has a factory "
+ "registered.";
+
+ StreamFactoryMap::mapped_type& emplaced_factory =
+ emplace_result.first->second;
+ DCHECK(emplaced_factory.is_bound())
+ << "Factory is not bound to a remote implementation.";
+
+ // Unretained is safe because |this| owns the binding, so a connection error
+ // cannot trigger after destruction.
+ emplaced_factory.set_connection_error_handler(
+ base::Bind(&AudioIPCFactory::DeregisterRemoteFactoryOnIOThread,
+ base::Unretained(this), frame_id));
+}
+
+void AudioIPCFactory::DeregisterRemoteFactoryOnIOThread(int frame_id) {
+ factory_ptrs_.erase(frame_id);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698