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

Side by Side Diff: content/renderer/pepper/pepper_audio_input_host.cc

Issue 231883002: Refactor some ResourceMessageReply usages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/pepper_audio_input_host.h" 5 #include "content/renderer/pepper/pepper_audio_input_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/renderer/pepper/pepper_media_device_manager.h" 9 #include "content/renderer/pepper/pepper_media_device_manager.h"
10 #include "content/renderer/pepper/pepper_platform_audio_input.h" 10 #include "content/renderer/pepper/pepper_platform_audio_input.h"
(...skipping 27 matching lines...) Expand all
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 PepperAudioInputHost::PepperAudioInputHost( 42 PepperAudioInputHost::PepperAudioInputHost(
43 RendererPpapiHostImpl* host, 43 RendererPpapiHostImpl* host,
44 PP_Instance instance, 44 PP_Instance instance,
45 PP_Resource resource) 45 PP_Resource resource)
46 : ResourceHost(host->GetPpapiHost(), instance, resource), 46 : ResourceHost(host->GetPpapiHost(), instance, resource),
47 renderer_ppapi_host_(host), 47 renderer_ppapi_host_(host),
48 open_pending_(false),
48 audio_input_(NULL), 49 audio_input_(NULL),
49 enumeration_helper_( 50 enumeration_helper_(
50 this, 51 this,
51 PepperMediaDeviceManager::GetForRenderView( 52 PepperMediaDeviceManager::GetForRenderView(
52 host->GetRenderViewForInstance(pp_instance())), 53 host->GetRenderViewForInstance(pp_instance())),
53 PP_DEVICETYPE_DEV_AUDIOCAPTURE, 54 PP_DEVICETYPE_DEV_AUDIOCAPTURE,
54 host->GetDocumentURL(instance)) { 55 host->GetDocumentURL(instance)) {
55 } 56 }
56 57
57 PepperAudioInputHost::~PepperAudioInputHost() { 58 PepperAudioInputHost::~PepperAudioInputHost() {
(...skipping 27 matching lines...) Expand all
85 void PepperAudioInputHost::StreamCreationFailed() { 86 void PepperAudioInputHost::StreamCreationFailed() {
86 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0, 87 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0,
87 base::SyncSocket::kInvalidHandle); 88 base::SyncSocket::kInvalidHandle);
88 } 89 }
89 90
90 int32_t PepperAudioInputHost::OnOpen( 91 int32_t PepperAudioInputHost::OnOpen(
91 ppapi::host::HostMessageContext* context, 92 ppapi::host::HostMessageContext* context,
92 const std::string& device_id, 93 const std::string& device_id,
93 PP_AudioSampleRate sample_rate, 94 PP_AudioSampleRate sample_rate,
94 uint32_t sample_frame_count) { 95 uint32_t sample_frame_count) {
95 if (open_context_) 96 if (open_pending_)
96 return PP_ERROR_INPROGRESS; 97 return PP_ERROR_INPROGRESS;
97 if (audio_input_) 98 if (audio_input_)
98 return PP_ERROR_FAILED; 99 return PP_ERROR_FAILED;
99 100
100 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); 101 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance());
101 if (!document_url.is_valid()) 102 if (!document_url.is_valid())
102 return PP_ERROR_FAILED; 103 return PP_ERROR_FAILED;
103 104
104 // When it is done, we'll get called back on StreamCreated() or 105 // When it is done, we'll get called back on StreamCreated() or
105 // StreamCreationFailed(). 106 // StreamCreationFailed().
106 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( 107 RenderViewImpl* render_view = static_cast<RenderViewImpl*>(
107 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance())); 108 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()));
108 109
109 audio_input_ = PepperPlatformAudioInput::Create( 110 audio_input_ = PepperPlatformAudioInput::Create(
110 render_view->AsWeakPtr(), device_id, 111 render_view->AsWeakPtr(), device_id,
111 document_url, 112 document_url,
112 static_cast<int>(sample_rate), 113 static_cast<int>(sample_rate),
113 static_cast<int>(sample_frame_count), this); 114 static_cast<int>(sample_frame_count), this);
114 if (audio_input_) { 115 if (audio_input_) {
115 open_context_.reset(new ppapi::host::ReplyMessageContext( 116 open_context_ = context->MakeReplyMessageContext();
116 context->MakeReplyMessageContext())); 117 open_pending_ = true;
117 return PP_OK_COMPLETIONPENDING; 118 return PP_OK_COMPLETIONPENDING;
118 } else { 119 } else {
119 return PP_ERROR_FAILED; 120 return PP_ERROR_FAILED;
120 } 121 }
121 } 122 }
122 123
123 int32_t PepperAudioInputHost::OnStartOrStop( 124 int32_t PepperAudioInputHost::OnStartOrStop(
124 ppapi::host::HostMessageContext* /* context */, 125 ppapi::host::HostMessageContext* /* context */,
125 bool capture) { 126 bool capture) {
126 if (!audio_input_) 127 if (!audio_input_)
(...skipping 13 matching lines...) Expand all
140 141
141 void PepperAudioInputHost::OnOpenComplete( 142 void PepperAudioInputHost::OnOpenComplete(
142 int32_t result, 143 int32_t result,
143 base::SharedMemoryHandle shared_memory_handle, 144 base::SharedMemoryHandle shared_memory_handle,
144 size_t shared_memory_size, 145 size_t shared_memory_size,
145 base::SyncSocket::Handle socket_handle) { 146 base::SyncSocket::Handle socket_handle) {
146 // Make sure the handles are cleaned up. 147 // Make sure the handles are cleaned up.
147 base::SyncSocket scoped_socket(socket_handle); 148 base::SyncSocket scoped_socket(socket_handle);
148 base::SharedMemory scoped_shared_memory(shared_memory_handle, false); 149 base::SharedMemory scoped_shared_memory(shared_memory_handle, false);
149 150
150 if (!open_context_) { 151 if (!open_pending_) {
151 NOTREACHED(); 152 NOTREACHED();
152 return; 153 return;
153 } 154 }
154 155
155 ppapi::proxy::SerializedHandle serialized_socket_handle( 156 ppapi::proxy::SerializedHandle serialized_socket_handle(
156 ppapi::proxy::SerializedHandle::SOCKET); 157 ppapi::proxy::SerializedHandle::SOCKET);
157 ppapi::proxy::SerializedHandle serialized_shared_memory_handle( 158 ppapi::proxy::SerializedHandle serialized_shared_memory_handle(
158 ppapi::proxy::SerializedHandle::SHARED_MEMORY); 159 ppapi::proxy::SerializedHandle::SHARED_MEMORY);
159 160
160 if (result == PP_OK) { 161 if (result == PP_OK) {
161 IPC::PlatformFileForTransit temp_socket = 162 IPC::PlatformFileForTransit temp_socket =
162 IPC::InvalidPlatformFileForTransit(); 163 IPC::InvalidPlatformFileForTransit();
163 base::SharedMemoryHandle temp_shmem = base::SharedMemory::NULLHandle(); 164 base::SharedMemoryHandle temp_shmem = base::SharedMemory::NULLHandle();
164 result = GetRemoteHandles( 165 result = GetRemoteHandles(
165 scoped_socket, scoped_shared_memory, &temp_socket, &temp_shmem); 166 scoped_socket, scoped_shared_memory, &temp_socket, &temp_shmem);
166 167
167 serialized_socket_handle.set_socket(temp_socket); 168 serialized_socket_handle.set_socket(temp_socket);
168 serialized_shared_memory_handle.set_shmem(temp_shmem, shared_memory_size); 169 serialized_shared_memory_handle.set_shmem(temp_shmem, shared_memory_size);
169 } 170 }
170 171
171 // Send all the values, even on error. This simplifies some of our cleanup 172 // Send all the values, even on error. This simplifies some of our cleanup
172 // code since the handles will be in the other process and could be 173 // code since the handles will be in the other process and could be
173 // inconvenient to clean up. Our IPC code will automatically handle this for 174 // inconvenient to clean up. Our IPC code will automatically handle this for
174 // us, as long as the remote side always closes the handles it receives, even 175 // us, as long as the remote side always closes the handles it receives, even
175 // in the failure case. 176 // in the failure case.
176 open_context_->params.set_result(result); 177 open_context_.params.AppendHandle(serialized_socket_handle);
177 open_context_->params.AppendHandle(serialized_socket_handle); 178 open_context_.params.AppendHandle(serialized_shared_memory_handle);
dmichael (off chromium) 2014/04/11 18:11:23 What about adding an is_valid to the ReplyMessageC
bbudge 2014/04/11 20:41:19 I thought about this. I think it's a great idea so
178 open_context_->params.AppendHandle(serialized_shared_memory_handle); 179 SendOpenReply(result);
179
180 host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply());
181 open_context_.reset();
182 } 180 }
183 181
184 int32_t PepperAudioInputHost::GetRemoteHandles( 182 int32_t PepperAudioInputHost::GetRemoteHandles(
185 const base::SyncSocket& socket, 183 const base::SyncSocket& socket,
186 const base::SharedMemory& shared_memory, 184 const base::SharedMemory& shared_memory,
187 IPC::PlatformFileForTransit* remote_socket_handle, 185 IPC::PlatformFileForTransit* remote_socket_handle,
188 base::SharedMemoryHandle* remote_shared_memory_handle) { 186 base::SharedMemoryHandle* remote_shared_memory_handle) {
189 *remote_socket_handle = renderer_ppapi_host_->ShareHandleWithRemote( 187 *remote_socket_handle = renderer_ppapi_host_->ShareHandleWithRemote(
190 ConvertSyncSocketHandle(socket), false); 188 ConvertSyncSocketHandle(socket), false);
191 if (*remote_socket_handle == IPC::InvalidPlatformFileForTransit()) 189 if (*remote_socket_handle == IPC::InvalidPlatformFileForTransit())
192 return PP_ERROR_FAILED; 190 return PP_ERROR_FAILED;
193 191
194 *remote_shared_memory_handle = renderer_ppapi_host_->ShareHandleWithRemote( 192 *remote_shared_memory_handle = renderer_ppapi_host_->ShareHandleWithRemote(
195 ConvertSharedMemoryHandle(shared_memory), false); 193 ConvertSharedMemoryHandle(shared_memory), false);
196 if (*remote_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) 194 if (*remote_shared_memory_handle == IPC::InvalidPlatformFileForTransit())
197 return PP_ERROR_FAILED; 195 return PP_ERROR_FAILED;
198 196
199 return PP_OK; 197 return PP_OK;
200 } 198 }
201 199
202 void PepperAudioInputHost::Close() { 200 void PepperAudioInputHost::Close() {
203 if (!audio_input_) 201 if (!audio_input_)
204 return; 202 return;
205 203
206 audio_input_->ShutDown(); 204 audio_input_->ShutDown();
207 audio_input_ = NULL; 205 audio_input_ = NULL;
208 206
209 if (open_context_) { 207 if (open_pending_)
210 open_context_->params.set_result(PP_ERROR_ABORTED); 208 SendOpenReply(PP_ERROR_ABORTED);
211 host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply()); 209 }
212 open_context_.reset(); 210
213 } 211 void PepperAudioInputHost::SendOpenReply(int32_t result) {
212 open_context_.params.set_result(result);
213 host()->SendReply(open_context_, PpapiPluginMsg_AudioInput_OpenReply());
214 open_context_ = ppapi::host::ReplyMessageContext();
215 open_pending_ = false;
214 } 216 }
215 217
216 } // namespace content 218 } // namespace content
217 219
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698