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 "content/browser/renderer_host/render_view_host_delegate.h" | 7 #include "content/browser/renderer_host/render_view_host_delegate.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "media/video/capture/fake_video_capture_device.h" | 10 #include "media/video/capture/fake_video_capture_device.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 class MediaStreamUIProxy::Core { | 14 class MediaStreamUIProxy::Core { |
15 public: | 15 public: |
16 explicit Core(const base::WeakPtr<MediaStreamUIProxy>& proxy, | 16 explicit Core(const base::WeakPtr<MediaStreamUIProxy>& proxy, |
17 RenderViewHostDelegate* test_render_delegate); | 17 RenderViewHostDelegate* test_render_delegate); |
18 ~Core(); | 18 ~Core(); |
19 | 19 |
20 void RequestAccess(const MediaStreamRequest& request); | 20 void RequestAccess(const MediaStreamRequest& request); |
21 void OnStarted(); | 21 void OnStarted(); |
22 | 22 |
23 private: | 23 private: |
24 void ProcessAccessRequestResponse(const MediaStreamDevices& devices, | 24 void ProcessAccessRequestResponse(const MediaStreamDevices& devices, |
| 25 content::MediaStreamRequestResult result, |
25 scoped_ptr<MediaStreamUI> stream_ui); | 26 scoped_ptr<MediaStreamUI> stream_ui); |
26 void ProcessStopRequestFromUI(); | 27 void ProcessStopRequestFromUI(); |
27 | 28 |
28 base::WeakPtr<MediaStreamUIProxy> proxy_; | 29 base::WeakPtr<MediaStreamUIProxy> proxy_; |
29 scoped_ptr<MediaStreamUI> ui_; | 30 scoped_ptr<MediaStreamUI> ui_; |
30 | 31 |
31 RenderViewHostDelegate* const test_render_delegate_; | 32 RenderViewHostDelegate* const test_render_delegate_; |
32 | 33 |
33 // WeakPtr<> is used to RequestMediaAccessPermission() because there is no way | 34 // WeakPtr<> is used to RequestMediaAccessPermission() because there is no way |
34 // cancel media requests. | 35 // cancel media requests. |
(...skipping 21 matching lines...) Expand all Loading... |
56 | 57 |
57 if (test_render_delegate_) { | 58 if (test_render_delegate_) { |
58 render_delegate = test_render_delegate_; | 59 render_delegate = test_render_delegate_; |
59 } else { | 60 } else { |
60 RenderViewHostImpl* host = RenderViewHostImpl::FromID( | 61 RenderViewHostImpl* host = RenderViewHostImpl::FromID( |
61 request.render_process_id, request.render_view_id); | 62 request.render_process_id, request.render_view_id); |
62 | 63 |
63 // Tab may have gone away. | 64 // Tab may have gone away. |
64 if (!host || !host->GetDelegate()) { | 65 if (!host || !host->GetDelegate()) { |
65 ProcessAccessRequestResponse( | 66 ProcessAccessRequestResponse( |
66 MediaStreamDevices(), scoped_ptr<MediaStreamUI>()); | 67 MediaStreamDevices(), |
| 68 MEDIA_DEVICE_INVALID_STATE, |
| 69 scoped_ptr<MediaStreamUI>()); |
67 return; | 70 return; |
68 } | 71 } |
69 | 72 |
70 render_delegate = host->GetDelegate(); | 73 render_delegate = host->GetDelegate(); |
71 } | 74 } |
72 | 75 |
73 render_delegate->RequestMediaAccessPermission( | 76 render_delegate->RequestMediaAccessPermission( |
74 request, base::Bind(&Core::ProcessAccessRequestResponse, | 77 request, base::Bind(&Core::ProcessAccessRequestResponse, |
75 weak_factory_.GetWeakPtr())); | 78 weak_factory_.GetWeakPtr())); |
76 } | 79 } |
77 | 80 |
78 void MediaStreamUIProxy::Core::OnStarted() { | 81 void MediaStreamUIProxy::Core::OnStarted() { |
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
80 if (ui_) { | 83 if (ui_) { |
81 ui_->OnStarted(base::Bind(&Core::ProcessStopRequestFromUI, | 84 ui_->OnStarted(base::Bind(&Core::ProcessStopRequestFromUI, |
82 base::Unretained(this))); | 85 base::Unretained(this))); |
83 } | 86 } |
84 } | 87 } |
85 | 88 |
86 void MediaStreamUIProxy::Core::ProcessAccessRequestResponse( | 89 void MediaStreamUIProxy::Core::ProcessAccessRequestResponse( |
87 const MediaStreamDevices& devices, | 90 const MediaStreamDevices& devices, |
| 91 content::MediaStreamRequestResult result, |
88 scoped_ptr<MediaStreamUI> stream_ui) { | 92 scoped_ptr<MediaStreamUI> stream_ui) { |
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
90 | 94 |
91 ui_ = stream_ui.Pass(); | 95 ui_ = stream_ui.Pass(); |
92 BrowserThread::PostTask( | 96 BrowserThread::PostTask( |
93 BrowserThread::IO, FROM_HERE, | 97 BrowserThread::IO, FROM_HERE, |
94 base::Bind(&MediaStreamUIProxy::ProcessAccessRequestResponse, | 98 base::Bind(&MediaStreamUIProxy::ProcessAccessRequestResponse, |
95 proxy_, devices)); | 99 proxy_, devices, result)); |
96 } | 100 } |
97 | 101 |
98 void MediaStreamUIProxy::Core::ProcessStopRequestFromUI() { | 102 void MediaStreamUIProxy::Core::ProcessStopRequestFromUI() { |
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
100 | 104 |
101 BrowserThread::PostTask( | 105 BrowserThread::PostTask( |
102 BrowserThread::IO, FROM_HERE, | 106 BrowserThread::IO, FROM_HERE, |
103 base::Bind(&MediaStreamUIProxy::ProcessStopRequestFromUI, proxy_)); | 107 base::Bind(&MediaStreamUIProxy::ProcessStopRequestFromUI, proxy_)); |
104 } | 108 } |
105 | 109 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 void MediaStreamUIProxy::OnStarted(const base::Closure& stop_callback) { | 145 void MediaStreamUIProxy::OnStarted(const base::Closure& stop_callback) { |
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
143 | 147 |
144 stop_callback_ = stop_callback; | 148 stop_callback_ = stop_callback; |
145 BrowserThread::PostTask( | 149 BrowserThread::PostTask( |
146 BrowserThread::UI, FROM_HERE, | 150 BrowserThread::UI, FROM_HERE, |
147 base::Bind(&Core::OnStarted, base::Unretained(core_.get()))); | 151 base::Bind(&Core::OnStarted, base::Unretained(core_.get()))); |
148 } | 152 } |
149 | 153 |
150 void MediaStreamUIProxy::ProcessAccessRequestResponse( | 154 void MediaStreamUIProxy::ProcessAccessRequestResponse( |
151 const MediaStreamDevices& devices) { | 155 const MediaStreamDevices& devices, |
| 156 content::MediaStreamRequestResult result) { |
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
153 DCHECK(!response_callback_.is_null()); | 158 DCHECK(!response_callback_.is_null()); |
154 | 159 |
155 ResponseCallback cb = response_callback_; | 160 ResponseCallback cb = response_callback_; |
156 response_callback_.Reset(); | 161 response_callback_.Reset(); |
157 cb.Run(devices); | 162 cb.Run(devices, result); |
158 } | 163 } |
159 | 164 |
160 void MediaStreamUIProxy::ProcessStopRequestFromUI() { | 165 void MediaStreamUIProxy::ProcessStopRequestFromUI() { |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
162 DCHECK(!stop_callback_.is_null()); | 167 DCHECK(!stop_callback_.is_null()); |
163 | 168 |
164 base::Closure cb = stop_callback_; | 169 base::Closure cb = stop_callback_; |
165 stop_callback_.Reset(); | 170 stop_callback_.Reset(); |
166 cb.Run(); | 171 cb.Run(); |
167 } | 172 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 (request.requested_video_device_id.empty() || | 209 (request.requested_video_device_id.empty() || |
205 request.requested_video_device_id == it->id)) { | 210 request.requested_video_device_id == it->id)) { |
206 devices_to_use.push_back(*it); | 211 devices_to_use.push_back(*it); |
207 accepted_video = true; | 212 accepted_video = true; |
208 } | 213 } |
209 } | 214 } |
210 | 215 |
211 BrowserThread::PostTask( | 216 BrowserThread::PostTask( |
212 BrowserThread::IO, FROM_HERE, | 217 BrowserThread::IO, FROM_HERE, |
213 base::Bind(&MediaStreamUIProxy::ProcessAccessRequestResponse, | 218 base::Bind(&MediaStreamUIProxy::ProcessAccessRequestResponse, |
214 weak_factory_.GetWeakPtr(), devices_to_use)); | 219 weak_factory_.GetWeakPtr(), |
| 220 devices_to_use, |
| 221 devices_to_use.empty() ? |
| 222 MEDIA_DEVICE_NO_HARDWARE : |
| 223 MEDIA_DEVICE_OK)); |
215 } | 224 } |
216 | 225 |
217 void FakeMediaStreamUIProxy::OnStarted(const base::Closure& stop_callback) { | 226 void FakeMediaStreamUIProxy::OnStarted(const base::Closure& stop_callback) { |
218 } | 227 } |
219 | 228 |
220 } // namespace content | 229 } // namespace content |
OLD | NEW |