OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/renderer_host/media/media_stream_ui_proxy.h" | 5 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 void MediaStreamUIProxy::Core::ProcessAccessRequestResponse( | 113 void MediaStreamUIProxy::Core::ProcessAccessRequestResponse( |
114 const MediaStreamDevices& devices, | 114 const MediaStreamDevices& devices, |
115 content::MediaStreamRequestResult result, | 115 content::MediaStreamRequestResult result, |
116 std::unique_ptr<MediaStreamUI> stream_ui) { | 116 std::unique_ptr<MediaStreamUI> stream_ui) { |
117 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 117 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
118 | 118 |
119 ui_ = std::move(stream_ui); | 119 ui_ = std::move(stream_ui); |
120 BrowserThread::PostTask( | 120 BrowserThread::PostTask( |
121 BrowserThread::IO, FROM_HERE, | 121 BrowserThread::IO, FROM_HERE, |
122 base::Bind(&MediaStreamUIProxy::ProcessAccessRequestResponse, | 122 base::BindOnce(&MediaStreamUIProxy::ProcessAccessRequestResponse, proxy_, |
123 proxy_, devices, result)); | 123 devices, result)); |
124 } | 124 } |
125 | 125 |
126 void MediaStreamUIProxy::Core::ProcessStopRequestFromUI() { | 126 void MediaStreamUIProxy::Core::ProcessStopRequestFromUI() { |
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 127 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
128 | 128 |
129 BrowserThread::PostTask( | 129 BrowserThread::PostTask( |
130 BrowserThread::IO, FROM_HERE, | 130 BrowserThread::IO, FROM_HERE, |
131 base::Bind(&MediaStreamUIProxy::ProcessStopRequestFromUI, proxy_)); | 131 base::BindOnce(&MediaStreamUIProxy::ProcessStopRequestFromUI, proxy_)); |
132 } | 132 } |
133 | 133 |
134 RenderFrameHostDelegate* MediaStreamUIProxy::Core::GetRenderFrameHostDelegate( | 134 RenderFrameHostDelegate* MediaStreamUIProxy::Core::GetRenderFrameHostDelegate( |
135 int render_process_id, | 135 int render_process_id, |
136 int render_frame_id) { | 136 int render_frame_id) { |
137 if (test_render_delegate_) | 137 if (test_render_delegate_) |
138 return test_render_delegate_; | 138 return test_render_delegate_; |
139 RenderFrameHostImpl* host = | 139 RenderFrameHostImpl* host = |
140 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 140 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
141 return host ? host->delegate() : NULL; | 141 return host ? host->delegate() : NULL; |
(...skipping 17 matching lines...) Expand all Loading... |
159 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 159 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
160 core_.reset(new Core(weak_factory_.GetWeakPtr(), test_render_delegate)); | 160 core_.reset(new Core(weak_factory_.GetWeakPtr(), test_render_delegate)); |
161 } | 161 } |
162 | 162 |
163 MediaStreamUIProxy::~MediaStreamUIProxy() { | 163 MediaStreamUIProxy::~MediaStreamUIProxy() { |
164 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 164 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
165 } | 165 } |
166 | 166 |
167 void MediaStreamUIProxy::RequestAccess( | 167 void MediaStreamUIProxy::RequestAccess( |
168 std::unique_ptr<MediaStreamRequest> request, | 168 std::unique_ptr<MediaStreamRequest> request, |
169 const ResponseCallback& response_callback) { | 169 ResponseCallback response_callback) { |
170 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 170 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
171 | 171 |
172 response_callback_ = response_callback; | 172 response_callback_ = std::move(response_callback); |
173 BrowserThread::PostTask( | 173 BrowserThread::PostTask( |
174 BrowserThread::UI, FROM_HERE, | 174 BrowserThread::UI, FROM_HERE, |
175 base::Bind(&Core::RequestAccess, base::Unretained(core_.get()), | 175 base::BindOnce(&Core::RequestAccess, base::Unretained(core_.get()), |
176 base::Passed(&request))); | 176 std::move(request))); |
177 } | 177 } |
178 | 178 |
179 void MediaStreamUIProxy::OnStarted(const base::Closure& stop_callback, | 179 void MediaStreamUIProxy::OnStarted(base::OnceClosure stop_callback, |
180 const WindowIdCallback& window_id_callback) { | 180 WindowIdCallback window_id_callback) { |
181 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 181 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
182 | 182 |
183 stop_callback_ = stop_callback; | 183 stop_callback_ = std::move(stop_callback); |
184 | 184 |
185 // Owned by the PostTaskAndReply callback. | 185 // Owned by the PostTaskAndReply callback. |
186 gfx::NativeViewId* window_id = new gfx::NativeViewId(0); | 186 gfx::NativeViewId* window_id = new gfx::NativeViewId(0); |
187 | 187 |
188 BrowserThread::PostTaskAndReply( | 188 BrowserThread::PostTaskAndReply( |
189 BrowserThread::UI, | 189 BrowserThread::UI, FROM_HERE, |
190 FROM_HERE, | 190 base::BindOnce(&Core::OnStarted, base::Unretained(core_.get()), |
191 base::Bind(&Core::OnStarted, base::Unretained(core_.get()), window_id), | 191 window_id), |
192 base::Bind(&MediaStreamUIProxy::OnWindowId, | 192 base::BindOnce(&MediaStreamUIProxy::OnWindowId, |
193 weak_factory_.GetWeakPtr(), | 193 weak_factory_.GetWeakPtr(), std::move(window_id_callback), |
194 window_id_callback, | 194 base::Owned(window_id))); |
195 base::Owned(window_id))); | |
196 } | 195 } |
197 | 196 |
198 void MediaStreamUIProxy::ProcessAccessRequestResponse( | 197 void MediaStreamUIProxy::ProcessAccessRequestResponse( |
199 const MediaStreamDevices& devices, | 198 const MediaStreamDevices& devices, |
200 content::MediaStreamRequestResult result) { | 199 content::MediaStreamRequestResult result) { |
201 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 200 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
202 DCHECK(!response_callback_.is_null()); | 201 DCHECK(!response_callback_.is_null()); |
203 | 202 |
204 ResponseCallback cb = response_callback_; | 203 base::ResetAndReturn(&response_callback_).Run(devices, result); |
205 response_callback_.Reset(); | |
206 cb.Run(devices, result); | |
207 } | 204 } |
208 | 205 |
209 void MediaStreamUIProxy::ProcessStopRequestFromUI() { | 206 void MediaStreamUIProxy::ProcessStopRequestFromUI() { |
210 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 207 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
211 DCHECK(!stop_callback_.is_null()); | 208 DCHECK(!stop_callback_.is_null()); |
212 | 209 |
213 base::Closure cb = stop_callback_; | 210 base::ResetAndReturn(&stop_callback_).Run(); |
214 stop_callback_.Reset(); | |
215 cb.Run(); | |
216 } | 211 } |
217 | 212 |
218 void MediaStreamUIProxy::OnWindowId(const WindowIdCallback& window_id_callback, | 213 void MediaStreamUIProxy::OnWindowId(WindowIdCallback window_id_callback, |
219 gfx::NativeViewId* window_id) { | 214 gfx::NativeViewId* window_id) { |
220 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 215 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
221 if (!window_id_callback.is_null()) | 216 if (!window_id_callback.is_null()) |
222 window_id_callback.Run(*window_id); | 217 std::move(window_id_callback).Run(*window_id); |
223 } | 218 } |
224 | 219 |
225 FakeMediaStreamUIProxy::FakeMediaStreamUIProxy() | 220 FakeMediaStreamUIProxy::FakeMediaStreamUIProxy() |
226 : MediaStreamUIProxy(NULL), | 221 : MediaStreamUIProxy(NULL), |
227 mic_access_(true), | 222 mic_access_(true), |
228 camera_access_(true) { | 223 camera_access_(true) { |
229 } | 224 } |
230 | 225 |
231 FakeMediaStreamUIProxy::~FakeMediaStreamUIProxy() {} | 226 FakeMediaStreamUIProxy::~FakeMediaStreamUIProxy() {} |
232 | 227 |
233 void FakeMediaStreamUIProxy::SetAvailableDevices( | 228 void FakeMediaStreamUIProxy::SetAvailableDevices( |
234 const MediaStreamDevices& devices) { | 229 const MediaStreamDevices& devices) { |
235 devices_ = devices; | 230 devices_ = devices; |
236 } | 231 } |
237 | 232 |
238 void FakeMediaStreamUIProxy::SetMicAccess(bool access) { | 233 void FakeMediaStreamUIProxy::SetMicAccess(bool access) { |
239 mic_access_ = access; | 234 mic_access_ = access; |
240 } | 235 } |
241 | 236 |
242 void FakeMediaStreamUIProxy::SetCameraAccess(bool access) { | 237 void FakeMediaStreamUIProxy::SetCameraAccess(bool access) { |
243 camera_access_ = access; | 238 camera_access_ = access; |
244 } | 239 } |
245 | 240 |
246 void FakeMediaStreamUIProxy::RequestAccess( | 241 void FakeMediaStreamUIProxy::RequestAccess( |
247 std::unique_ptr<MediaStreamRequest> request, | 242 std::unique_ptr<MediaStreamRequest> request, |
248 const ResponseCallback& response_callback) { | 243 ResponseCallback response_callback) { |
249 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 244 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
250 | 245 |
251 response_callback_ = response_callback; | 246 response_callback_ = std::move(response_callback); |
252 | 247 |
253 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 248 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
254 switches::kUseFakeUIForMediaStream) == "deny") { | 249 switches::kUseFakeUIForMediaStream) == "deny") { |
255 // Immediately deny the request. | 250 // Immediately deny the request. |
256 BrowserThread::PostTask( | 251 BrowserThread::PostTask( |
257 BrowserThread::IO, FROM_HERE, | 252 BrowserThread::IO, FROM_HERE, |
258 base::Bind(&MediaStreamUIProxy::ProcessAccessRequestResponse, | 253 base::BindOnce(&MediaStreamUIProxy::ProcessAccessRequestResponse, |
259 weak_factory_.GetWeakPtr(), | 254 weak_factory_.GetWeakPtr(), MediaStreamDevices(), |
260 MediaStreamDevices(), | 255 MEDIA_DEVICE_PERMISSION_DENIED)); |
261 MEDIA_DEVICE_PERMISSION_DENIED)); | |
262 return; | 256 return; |
263 } | 257 } |
264 | 258 |
265 MediaStreamDevices devices_to_use; | 259 MediaStreamDevices devices_to_use; |
266 bool accepted_audio = false; | 260 bool accepted_audio = false; |
267 bool accepted_video = false; | 261 bool accepted_video = false; |
268 | 262 |
269 // Use the first capture device of the same media type in the list for the | 263 // Use the first capture device of the same media type in the list for the |
270 // fake UI. | 264 // fake UI. |
271 for (MediaStreamDevices::const_iterator it = devices_.begin(); | 265 for (MediaStreamDevices::const_iterator it = devices_.begin(); |
(...skipping 16 matching lines...) Expand all Loading... |
288 } | 282 } |
289 | 283 |
290 // Fail the request if a device doesn't exist for the requested type. | 284 // Fail the request if a device doesn't exist for the requested type. |
291 if ((request->audio_type != MEDIA_NO_SERVICE && !accepted_audio) || | 285 if ((request->audio_type != MEDIA_NO_SERVICE && !accepted_audio) || |
292 (request->video_type != MEDIA_NO_SERVICE && !accepted_video)) { | 286 (request->video_type != MEDIA_NO_SERVICE && !accepted_video)) { |
293 devices_to_use.clear(); | 287 devices_to_use.clear(); |
294 } | 288 } |
295 | 289 |
296 BrowserThread::PostTask( | 290 BrowserThread::PostTask( |
297 BrowserThread::IO, FROM_HERE, | 291 BrowserThread::IO, FROM_HERE, |
298 base::Bind(&MediaStreamUIProxy::ProcessAccessRequestResponse, | 292 base::BindOnce( |
299 weak_factory_.GetWeakPtr(), | 293 &MediaStreamUIProxy::ProcessAccessRequestResponse, |
300 devices_to_use, | 294 weak_factory_.GetWeakPtr(), devices_to_use, |
301 devices_to_use.empty() ? | 295 devices_to_use.empty() ? MEDIA_DEVICE_NO_HARDWARE : MEDIA_DEVICE_OK)); |
302 MEDIA_DEVICE_NO_HARDWARE : | |
303 MEDIA_DEVICE_OK)); | |
304 } | 296 } |
305 | 297 |
306 void FakeMediaStreamUIProxy::OnStarted( | 298 void FakeMediaStreamUIProxy::OnStarted(base::OnceClosure stop_callback, |
307 const base::Closure& stop_callback, | 299 WindowIdCallback window_id_callback) {} |
308 const WindowIdCallback& window_id_callback) {} | |
309 | 300 |
310 } // namespace content | 301 } // namespace content |
OLD | NEW |