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

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: Rebase after great git cl format event. 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 OnOpenComplete(PP_ERROR_FAILED, 80 OnOpenComplete(PP_ERROR_FAILED,
81 base::SharedMemory::NULLHandle(), 81 base::SharedMemory::NULLHandle(),
82 0, 82 0,
83 base::SyncSocket::kInvalidHandle); 83 base::SyncSocket::kInvalidHandle);
84 } 84 }
85 85
86 int32_t PepperAudioInputHost::OnOpen(ppapi::host::HostMessageContext* context, 86 int32_t PepperAudioInputHost::OnOpen(ppapi::host::HostMessageContext* context,
87 const std::string& device_id, 87 const std::string& device_id,
88 PP_AudioSampleRate sample_rate, 88 PP_AudioSampleRate sample_rate,
89 uint32_t sample_frame_count) { 89 uint32_t sample_frame_count) {
90 if (open_context_) 90 if (open_context_.is_valid())
91 return PP_ERROR_INPROGRESS; 91 return PP_ERROR_INPROGRESS;
92 if (audio_input_) 92 if (audio_input_)
93 return PP_ERROR_FAILED; 93 return PP_ERROR_FAILED;
94 94
95 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); 95 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance());
96 if (!document_url.is_valid()) 96 if (!document_url.is_valid())
97 return PP_ERROR_FAILED; 97 return PP_ERROR_FAILED;
98 98
99 // When it is done, we'll get called back on StreamCreated() or 99 // When it is done, we'll get called back on StreamCreated() or
100 // StreamCreationFailed(). 100 // StreamCreationFailed().
101 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( 101 RenderViewImpl* render_view = static_cast<RenderViewImpl*>(
102 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance())); 102 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()));
103 103
104 audio_input_ = 104 audio_input_ =
105 PepperPlatformAudioInput::Create(render_view->AsWeakPtr(), 105 PepperPlatformAudioInput::Create(render_view->AsWeakPtr(),
106 device_id, 106 device_id,
107 document_url, 107 document_url,
108 static_cast<int>(sample_rate), 108 static_cast<int>(sample_rate),
109 static_cast<int>(sample_frame_count), 109 static_cast<int>(sample_frame_count),
110 this); 110 this);
111 if (audio_input_) { 111 if (audio_input_) {
112 open_context_.reset(new ppapi::host::ReplyMessageContext( 112 open_context_ = context->MakeReplyMessageContext();
113 context->MakeReplyMessageContext()));
114 return PP_OK_COMPLETIONPENDING; 113 return PP_OK_COMPLETIONPENDING;
115 } else { 114 } else {
116 return PP_ERROR_FAILED; 115 return PP_ERROR_FAILED;
117 } 116 }
118 } 117 }
119 118
120 int32_t PepperAudioInputHost::OnStartOrStop( 119 int32_t PepperAudioInputHost::OnStartOrStop(
121 ppapi::host::HostMessageContext* /* context */, 120 ppapi::host::HostMessageContext* /* context */,
122 bool capture) { 121 bool capture) {
123 if (!audio_input_) 122 if (!audio_input_)
(...skipping 13 matching lines...) Expand all
137 136
138 void PepperAudioInputHost::OnOpenComplete( 137 void PepperAudioInputHost::OnOpenComplete(
139 int32_t result, 138 int32_t result,
140 base::SharedMemoryHandle shared_memory_handle, 139 base::SharedMemoryHandle shared_memory_handle,
141 size_t shared_memory_size, 140 size_t shared_memory_size,
142 base::SyncSocket::Handle socket_handle) { 141 base::SyncSocket::Handle socket_handle) {
143 // Make sure the handles are cleaned up. 142 // Make sure the handles are cleaned up.
144 base::SyncSocket scoped_socket(socket_handle); 143 base::SyncSocket scoped_socket(socket_handle);
145 base::SharedMemory scoped_shared_memory(shared_memory_handle, false); 144 base::SharedMemory scoped_shared_memory(shared_memory_handle, false);
146 145
147 if (!open_context_) { 146 if (!open_context_.is_valid()) {
148 NOTREACHED(); 147 NOTREACHED();
149 return; 148 return;
150 } 149 }
151 150
152 ppapi::proxy::SerializedHandle serialized_socket_handle( 151 ppapi::proxy::SerializedHandle serialized_socket_handle(
153 ppapi::proxy::SerializedHandle::SOCKET); 152 ppapi::proxy::SerializedHandle::SOCKET);
154 ppapi::proxy::SerializedHandle serialized_shared_memory_handle( 153 ppapi::proxy::SerializedHandle serialized_shared_memory_handle(
155 ppapi::proxy::SerializedHandle::SHARED_MEMORY); 154 ppapi::proxy::SerializedHandle::SHARED_MEMORY);
156 155
157 if (result == PP_OK) { 156 if (result == PP_OK) {
158 IPC::PlatformFileForTransit temp_socket = 157 IPC::PlatformFileForTransit temp_socket =
159 IPC::InvalidPlatformFileForTransit(); 158 IPC::InvalidPlatformFileForTransit();
160 base::SharedMemoryHandle temp_shmem = base::SharedMemory::NULLHandle(); 159 base::SharedMemoryHandle temp_shmem = base::SharedMemory::NULLHandle();
161 result = GetRemoteHandles( 160 result = GetRemoteHandles(
162 scoped_socket, scoped_shared_memory, &temp_socket, &temp_shmem); 161 scoped_socket, scoped_shared_memory, &temp_socket, &temp_shmem);
163 162
164 serialized_socket_handle.set_socket(temp_socket); 163 serialized_socket_handle.set_socket(temp_socket);
165 serialized_shared_memory_handle.set_shmem(temp_shmem, shared_memory_size); 164 serialized_shared_memory_handle.set_shmem(temp_shmem, shared_memory_size);
166 } 165 }
167 166
168 // Send all the values, even on error. This simplifies some of our cleanup 167 // Send all the values, even on error. This simplifies some of our cleanup
169 // code since the handles will be in the other process and could be 168 // code since the handles will be in the other process and could be
170 // inconvenient to clean up. Our IPC code will automatically handle this for 169 // inconvenient to clean up. Our IPC code will automatically handle this for
171 // us, as long as the remote side always closes the handles it receives, even 170 // us, as long as the remote side always closes the handles it receives, even
172 // in the failure case. 171 // in the failure case.
173 open_context_->params.set_result(result); 172 open_context_.params.AppendHandle(serialized_socket_handle);
174 open_context_->params.AppendHandle(serialized_socket_handle); 173 open_context_.params.AppendHandle(serialized_shared_memory_handle);
175 open_context_->params.AppendHandle(serialized_shared_memory_handle); 174 SendOpenReply(result);
176
177 host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply());
178 open_context_.reset();
179 } 175 }
180 176
181 int32_t PepperAudioInputHost::GetRemoteHandles( 177 int32_t PepperAudioInputHost::GetRemoteHandles(
182 const base::SyncSocket& socket, 178 const base::SyncSocket& socket,
183 const base::SharedMemory& shared_memory, 179 const base::SharedMemory& shared_memory,
184 IPC::PlatformFileForTransit* remote_socket_handle, 180 IPC::PlatformFileForTransit* remote_socket_handle,
185 base::SharedMemoryHandle* remote_shared_memory_handle) { 181 base::SharedMemoryHandle* remote_shared_memory_handle) {
186 *remote_socket_handle = renderer_ppapi_host_->ShareHandleWithRemote( 182 *remote_socket_handle = renderer_ppapi_host_->ShareHandleWithRemote(
187 ConvertSyncSocketHandle(socket), false); 183 ConvertSyncSocketHandle(socket), false);
188 if (*remote_socket_handle == IPC::InvalidPlatformFileForTransit()) 184 if (*remote_socket_handle == IPC::InvalidPlatformFileForTransit())
189 return PP_ERROR_FAILED; 185 return PP_ERROR_FAILED;
190 186
191 *remote_shared_memory_handle = renderer_ppapi_host_->ShareHandleWithRemote( 187 *remote_shared_memory_handle = renderer_ppapi_host_->ShareHandleWithRemote(
192 ConvertSharedMemoryHandle(shared_memory), false); 188 ConvertSharedMemoryHandle(shared_memory), false);
193 if (*remote_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) 189 if (*remote_shared_memory_handle == IPC::InvalidPlatformFileForTransit())
194 return PP_ERROR_FAILED; 190 return PP_ERROR_FAILED;
195 191
196 return PP_OK; 192 return PP_OK;
197 } 193 }
198 194
199 void PepperAudioInputHost::Close() { 195 void PepperAudioInputHost::Close() {
200 if (!audio_input_) 196 if (!audio_input_)
201 return; 197 return;
202 198
203 audio_input_->ShutDown(); 199 audio_input_->ShutDown();
204 audio_input_ = NULL; 200 audio_input_ = NULL;
205 201
206 if (open_context_) { 202 if (open_context_.is_valid())
207 open_context_->params.set_result(PP_ERROR_ABORTED); 203 SendOpenReply(PP_ERROR_ABORTED);
208 host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply()); 204 }
209 open_context_.reset(); 205
210 } 206 void PepperAudioInputHost::SendOpenReply(int32_t result) {
207 open_context_.params.set_result(result);
208 host()->SendReply(open_context_, PpapiPluginMsg_AudioInput_OpenReply());
209 open_context_ = ppapi::host::ReplyMessageContext();
211 } 210 }
212 211
213 } // namespace content 212 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_audio_input_host.h ('k') | content/renderer/pepper/pepper_device_enumeration_host_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698