Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/browser/renderer_host/media/media_stream_device_settings.h" | 5 #include "content/browser/renderer_host/media/media_stream_device_settings.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 DeviceMap devices_full; | 105 DeviceMap devices_full; |
| 106 // Whether or not a task was posted to make the call to | 106 // Whether or not a task was posted to make the call to |
| 107 // RequestMediaAccessPermission, to make sure that we never post twice to it. | 107 // RequestMediaAccessPermission, to make sure that we never post twice to it. |
| 108 bool posted_task; | 108 bool posted_task; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 namespace { | 111 namespace { |
| 112 | 112 |
| 113 // Sends the request to the appropriate WebContents. | 113 // Sends the request to the appropriate WebContents. |
| 114 void DoDeviceRequest( | 114 void DoDeviceRequest( |
| 115 const MediaStreamDeviceSettingsRequest* request, | 115 const MediaStreamDeviceSettingsRequest& request, |
| 116 const content::MediaResponseCallback& callback) { | 116 const content::MediaResponseCallback& callback) { |
| 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 118 | 118 |
| 119 // Send the permission request to the web contents. | 119 // Send the permission request to the web contents. |
| 120 content::RenderViewHostImpl* host = | 120 content::RenderViewHostImpl* host = |
| 121 content::RenderViewHostImpl::FromID(request->render_process_id, | 121 content::RenderViewHostImpl::FromID(request.render_process_id, |
| 122 request->render_view_id); | 122 request.render_view_id); |
| 123 | 123 |
| 124 // Tab may have gone away. | 124 // Tab may have gone away. |
| 125 if (!host || !host->GetDelegate()) { | 125 if (!host || !host->GetDelegate()) { |
| 126 callback.Run(content::MediaStreamDevices()); | 126 callback.Run(content::MediaStreamDevices()); |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 host->GetDelegate()->RequestMediaAccessPermission(request, callback); | 130 host->GetDelegate()->RequestMediaAccessPermission(&request, callback); |
|
tommi (sloooow) - chröme
2012/07/12 08:38:53
Thanks for the quick fix - qq - should we also cha
| |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace | 133 } // namespace |
| 134 | 134 |
| 135 MediaStreamDeviceSettings::MediaStreamDeviceSettings( | 135 MediaStreamDeviceSettings::MediaStreamDeviceSettings( |
| 136 SettingsRequester* requester) | 136 SettingsRequester* requester) |
| 137 : requester_(requester), | 137 : requester_(requester), |
| 138 use_fake_ui_(false) { | 138 use_fake_ui_(false) { |
| 139 DCHECK(requester_); | 139 DCHECK(requester_); |
| 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 159 requests_.insert(std::make_pair(label, new MediaStreamDeviceSettingsRequest( | 159 requests_.insert(std::make_pair(label, new MediaStreamDeviceSettingsRequest( |
| 160 render_process_id, render_view_id, security_origin, request_options))); | 160 render_process_id, render_view_id, security_origin, request_options))); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void MediaStreamDeviceSettings::RemovePendingCaptureRequest( | 163 void MediaStreamDeviceSettings::RemovePendingCaptureRequest( |
| 164 const std::string& label) { | 164 const std::string& label) { |
| 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 166 | 166 |
| 167 SettingsRequests::iterator request_it = requests_.find(label); | 167 SettingsRequests::iterator request_it = requests_.find(label); |
| 168 if (request_it != requests_.end()) { | 168 if (request_it != requests_.end()) { |
| 169 // Proceed the next pending request for the same page. | |
| 169 MediaStreamDeviceSettingsRequest* request = request_it->second; | 170 MediaStreamDeviceSettingsRequest* request = request_it->second; |
| 171 std::string new_label = FindReadyRequestForView(request->render_view_id, | |
| 172 request->render_process_id); | |
| 173 if (!new_label.empty()) { | |
| 174 PostRequestToUi(new_label); | |
| 175 } | |
| 176 | |
| 177 // TODO(xians): Post a cancel request on UI thread to dismiss the infobar | |
| 178 // if request has been sent to the UI. | |
| 179 // Remove the request from the queue. | |
| 170 requests_.erase(request_it); | 180 requests_.erase(request_it); |
| 171 delete request; | 181 delete request; |
| 172 } | 182 } |
| 173 } | 183 } |
| 174 | 184 |
| 175 void MediaStreamDeviceSettings::AvailableDevices( | 185 void MediaStreamDeviceSettings::AvailableDevices( |
| 176 const std::string& label, | 186 const std::string& label, |
| 177 MediaStreamType stream_type, | 187 MediaStreamType stream_type, |
| 178 const StreamDeviceInfoArray& devices) { | 188 const StreamDeviceInfoArray& devices) { |
| 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 } | 255 } |
| 246 } | 256 } |
| 247 } | 257 } |
| 248 | 258 |
| 249 void MediaStreamDeviceSettings::PostResponse( | 259 void MediaStreamDeviceSettings::PostResponse( |
| 250 const std::string& label, | 260 const std::string& label, |
| 251 const content::MediaStreamDevices& devices) { | 261 const content::MediaStreamDevices& devices) { |
| 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 253 | 263 |
| 254 SettingsRequests::iterator req = requests_.find(label); | 264 SettingsRequests::iterator req = requests_.find(label); |
| 265 // Return if the request has been removed. | |
| 266 if (req == requests_.end()) | |
| 267 return; | |
| 268 | |
| 255 DCHECK(req != requests_.end()) << "Invalid request label."; | 269 DCHECK(req != requests_.end()) << "Invalid request label."; |
| 256 DCHECK(requester_); | 270 DCHECK(requester_); |
| 257 MediaStreamDeviceSettingsRequest* request = req->second; | 271 MediaStreamDeviceSettingsRequest* request = req->second; |
| 258 requests_.erase(req); | 272 requests_.erase(req); |
| 259 | 273 |
| 260 // Look for queued requests for the same view. If there is a pending request, | 274 // Look for queued requests for the same view. If there is a pending request, |
| 261 // post it for user approval. | 275 // post it for user approval. |
| 262 std::string new_label = FindReadyRequestForView(request->render_view_id, | 276 std::string new_label = FindReadyRequestForView(request->render_view_id, |
| 263 request->render_process_id); | 277 request->render_process_id); |
| 264 if (!new_label.empty()) { | 278 if (!new_label.empty()) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 } | 363 } |
| 350 | 364 |
| 351 scoped_refptr<ResponseCallbackHelper> helper = | 365 scoped_refptr<ResponseCallbackHelper> helper = |
| 352 new ResponseCallbackHelper(AsWeakPtr()); | 366 new ResponseCallbackHelper(AsWeakPtr()); |
| 353 content::MediaResponseCallback callback = | 367 content::MediaResponseCallback callback = |
| 354 base::Bind(&ResponseCallbackHelper::PostResponse, | 368 base::Bind(&ResponseCallbackHelper::PostResponse, |
| 355 helper.get(), label); | 369 helper.get(), label); |
| 356 | 370 |
| 357 BrowserThread::PostTask( | 371 BrowserThread::PostTask( |
| 358 BrowserThread::UI, FROM_HERE, | 372 BrowserThread::UI, FROM_HERE, |
| 359 base::Bind(&DoDeviceRequest, request, callback)); | 373 base::Bind(&DoDeviceRequest, *request, callback)); |
| 360 } | 374 } |
| 361 | 375 |
| 362 } // namespace media_stream | 376 } // namespace media_stream |
| OLD | NEW |