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 #include "content/renderer/media/audio_ipc_factory.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/memory/ptr_util.h" | |
11 #include "content/renderer/media/mojo_audio_output_ipc.h" | |
12 | |
13 namespace content { | |
14 | |
15 AudioIPCFactory* AudioIPCFactory::instance_ = nullptr; | |
16 | |
17 AudioIPCFactory::AudioIPCFactory( | |
18 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | |
19 : io_task_runner_(io_task_runner) { | |
20 DCHECK(!instance_); | |
21 instance_ = this; | |
22 } | |
23 | |
24 AudioIPCFactory::~AudioIPCFactory() { | |
25 DCHECK(instance_); | |
o1ka
2017/04/20 10:35:59
DCHECK_EQ(instance_, this);
Max Morin
2017/05/05 13:10:58
Done.
| |
26 instance_ = nullptr; | |
27 } | |
28 | |
29 std::unique_ptr<media::AudioOutputIPC> AudioIPCFactory::CreateAudioOutputIPC( | |
30 int frame_id) const { | |
31 return base::MakeUnique<MojoAudioOutputIPC>(frame_id); | |
32 } | |
33 | |
34 void AudioIPCFactory::RegisterRemoteFactory( | |
35 int frame_id, | |
36 mojom::RendererAudioOutputStreamFactoryPtr factory_ptr) { | |
37 // PassInterface unbinds the message pipe from the current thread. This | |
38 // allows us to bind it to the IO thread. | |
39 // Unretained is safe because |this| is owned by the RenderThreadImpl, which | |
40 // outlives the io thread. | |
41 io_task_runner_->PostTask( | |
42 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 :).
| |
43 base::Unretained(this), frame_id, | |
44 base::Passed(factory_ptr.PassInterface()))); | |
45 } | |
46 | |
47 void AudioIPCFactory::DeregisterRemoteFactory(int frame_id) { | |
48 // Unretained is safe because |this| is owned by the RenderThreadImpl, which | |
49 // outlives the io thread. | |
50 io_task_runner_->PostTask( | |
51 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.
| |
52 base::Unretained(this), frame_id)); | |
53 } | |
54 | |
55 mojom::RendererAudioOutputStreamFactory* AudioIPCFactory::GetRemoteFactory( | |
56 int frame_id) { | |
57 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.
| |
58 return it == factory_ptrs_.end() ? nullptr : it->second.get(); | |
59 } | |
60 | |
61 void AudioIPCFactory::RegisterRemoteFactoryOnIOThread( | |
62 int frame_id, | |
63 mojom::RendererAudioOutputStreamFactoryPtrInfo factory_ptr_info) { | |
64 std::pair<StreamFactoryMap::iterator, bool> emplace_result = | |
65 factory_ptrs_.emplace(frame_id, | |
66 mojo::MakeProxy(std::move(factory_ptr_info))); | |
67 | |
68 DCHECK(emplace_result.second) << "Attempt to register a factory for a " | |
69 "frame which already has a factory " | |
70 "registered."; | |
71 | |
72 StreamFactoryMap::mapped_type& emplaced_factory = | |
73 emplace_result.first->second; | |
74 DCHECK(emplaced_factory.is_bound()) | |
75 << "Factory is not bound to a remote implementation."; | |
76 | |
77 // Unretained is safe because |this| owns the binding, so a connection error | |
78 // cannot trigger after destruction. | |
79 emplaced_factory.set_connection_error_handler( | |
80 base::Bind(&AudioIPCFactory::DeregisterRemoteFactoryOnIOThread, | |
81 base::Unretained(this), frame_id)); | |
82 } | |
83 | |
84 void AudioIPCFactory::DeregisterRemoteFactoryOnIOThread(int frame_id) { | |
85 factory_ptrs_.erase(frame_id); | |
86 } | |
87 | |
88 } // namespace content | |
OLD | NEW |