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

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.cc

Issue 185863003: [Media] Add user gesture reporting for API calls to midi and media streams. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 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/browser/renderer_host/media/media_stream_manager.h" 5 #include "content/browser/renderer_host/media/media_stream_manager.h"
6 6
7 #include <list> 7 #include <list>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // several subclasses of DeviceRequest and move some of the responsibility of 159 // several subclasses of DeviceRequest and move some of the responsibility of
160 // the MediaStreamManager to the subclasses to get rid of the way too many if 160 // the MediaStreamManager to the subclasses to get rid of the way too many if
161 // statements in MediaStreamManager. 161 // statements in MediaStreamManager.
162 class MediaStreamManager::DeviceRequest { 162 class MediaStreamManager::DeviceRequest {
163 public: 163 public:
164 DeviceRequest(MediaStreamRequester* requester, 164 DeviceRequest(MediaStreamRequester* requester,
165 int requesting_process_id, 165 int requesting_process_id,
166 int requesting_view_id, 166 int requesting_view_id,
167 int page_request_id, 167 int page_request_id,
168 const GURL& security_origin, 168 const GURL& security_origin,
169 bool user_gesture,
169 MediaStreamRequestType request_type, 170 MediaStreamRequestType request_type,
170 const StreamOptions& options, 171 const StreamOptions& options,
171 const ResourceContext::SaltCallback& salt_callback) 172 const ResourceContext::SaltCallback& salt_callback)
172 : requester(requester), 173 : requester(requester),
173 requesting_process_id(requesting_process_id), 174 requesting_process_id(requesting_process_id),
174 requesting_view_id(requesting_view_id), 175 requesting_view_id(requesting_view_id),
175 page_request_id(page_request_id), 176 page_request_id(page_request_id),
176 security_origin(security_origin), 177 security_origin(security_origin),
178 user_gesture(user_gesture),
177 request_type(request_type), 179 request_type(request_type),
178 options(options), 180 options(options),
179 salt_callback(salt_callback), 181 salt_callback(salt_callback),
180 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), 182 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED),
181 audio_type_(MEDIA_NO_SERVICE), 183 audio_type_(MEDIA_NO_SERVICE),
182 video_type_(MEDIA_NO_SERVICE) { 184 video_type_(MEDIA_NO_SERVICE) {
183 } 185 }
184 186
185 ~DeviceRequest() {} 187 ~DeviceRequest() {}
186 188
(...skipping 13 matching lines...) Expand all
200 202
201 // Creates a MediaStreamRequest object that is used by this request when UI 203 // Creates a MediaStreamRequest object that is used by this request when UI
202 // is asked for permission and device selection. 204 // is asked for permission and device selection.
203 void CreateUIRequest(const std::string& requested_audio_device_id, 205 void CreateUIRequest(const std::string& requested_audio_device_id,
204 const std::string& requested_video_device_id) { 206 const std::string& requested_video_device_id) {
205 DCHECK(!ui_request_); 207 DCHECK(!ui_request_);
206 ui_request_.reset(new MediaStreamRequest(requesting_process_id, 208 ui_request_.reset(new MediaStreamRequest(requesting_process_id,
207 requesting_view_id, 209 requesting_view_id,
208 page_request_id, 210 page_request_id,
209 security_origin, 211 security_origin,
212 user_gesture,
210 request_type, 213 request_type,
211 requested_audio_device_id, 214 requested_audio_device_id,
212 requested_video_device_id, 215 requested_video_device_id,
213 audio_type_, 216 audio_type_,
214 video_type_)); 217 video_type_));
215 } 218 }
216 219
217 // Creates a tab capture specific MediaStreamRequest object that is used by 220 // Creates a tab capture specific MediaStreamRequest object that is used by
218 // this request when UI is asked for permission and device selection. 221 // this request when UI is asked for permission and device selection.
219 void CreateTabCatureUIRequest(int target_render_process_id, 222 void CreateTabCatureUIRequest(int target_render_process_id,
220 int target_render_view_id, 223 int target_render_view_id,
221 const std::string& tab_capture_id) { 224 const std::string& tab_capture_id) {
222 DCHECK(!ui_request_); 225 DCHECK(!ui_request_);
223 ui_request_.reset(new MediaStreamRequest(target_render_process_id, 226 ui_request_.reset(new MediaStreamRequest(target_render_process_id,
224 target_render_view_id, 227 target_render_view_id,
225 page_request_id, 228 page_request_id,
226 security_origin, 229 security_origin,
230 user_gesture,
227 request_type, 231 request_type,
228 "", 232 "",
229 "", 233 "",
230 audio_type_, 234 audio_type_,
231 video_type_)); 235 video_type_));
232 ui_request_->tab_capture_device_id = tab_capture_id; 236 ui_request_->tab_capture_device_id = tab_capture_id;
233 } 237 }
234 238
235 const MediaStreamRequest* UIRequest() const { return ui_request_.get(); } 239 const MediaStreamRequest* UIRequest() const { return ui_request_.get(); }
236 240
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // will receive a handle to the MediaStream. This may be different from 289 // will receive a handle to the MediaStream. This may be different from
286 // MediaStreamRequest::render_view_id which in the tab capture case 290 // MediaStreamRequest::render_view_id which in the tab capture case
287 // specifies the target renderer from which audio and video is captured. 291 // specifies the target renderer from which audio and video is captured.
288 const int requesting_view_id; 292 const int requesting_view_id;
289 293
290 // An ID the render view provided to identify this request. 294 // An ID the render view provided to identify this request.
291 const int page_request_id; 295 const int page_request_id;
292 296
293 const GURL security_origin; 297 const GURL security_origin;
294 298
299 const bool user_gesture;
300
295 const MediaStreamRequestType request_type; 301 const MediaStreamRequestType request_type;
296 302
297 const StreamOptions options; 303 const StreamOptions options;
298 304
299 ResourceContext::SaltCallback salt_callback; 305 ResourceContext::SaltCallback salt_callback;
300 306
301 StreamDeviceInfoArray devices; 307 StreamDeviceInfoArray devices;
302 308
303 // Callback to the requester which audio/video devices have been selected. 309 // Callback to the requester which audio/video devices have been selected.
304 // It can be null if the requester has no interest to know the result. 310 // It can be null if the requester has no interest to know the result.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 const MediaRequestResponseCallback& callback) { 381 const MediaRequestResponseCallback& callback) {
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
377 383
378 // TODO(perkj): The argument list with NULL parameters to DeviceRequest 384 // TODO(perkj): The argument list with NULL parameters to DeviceRequest
379 // suggests that this is the wrong design. Can this be refactored? 385 // suggests that this is the wrong design. Can this be refactored?
380 DeviceRequest* request = new DeviceRequest(NULL, 386 DeviceRequest* request = new DeviceRequest(NULL,
381 render_process_id, 387 render_process_id,
382 render_view_id, 388 render_view_id,
383 page_request_id, 389 page_request_id,
384 security_origin, 390 security_origin,
391 false, // user gesture
385 MEDIA_DEVICE_ACCESS, 392 MEDIA_DEVICE_ACCESS,
386 options, 393 options,
387 base::Bind(&ReturnEmptySalt)); 394 base::Bind(&ReturnEmptySalt));
388 395
389 const std::string& label = AddRequest(request); 396 const std::string& label = AddRequest(request);
390 397
391 request->callback = callback; 398 request->callback = callback;
392 // Post a task and handle the request asynchronously. The reason is that the 399 // Post a task and handle the request asynchronously. The reason is that the
393 // requester won't have a label for the request until this function returns 400 // requester won't have a label for the request until this function returns
394 // and thus can not handle a response. Using base::Unretained is safe since 401 // and thus can not handle a response. Using base::Unretained is safe since
395 // MediaStreamManager is deleted on the UI thread, after the IO thread has 402 // MediaStreamManager is deleted on the UI thread, after the IO thread has
396 // been stopped. 403 // been stopped.
397 BrowserThread::PostTask( 404 BrowserThread::PostTask(
398 BrowserThread::IO, FROM_HERE, 405 BrowserThread::IO, FROM_HERE,
399 base::Bind(&MediaStreamManager::SetupRequest, 406 base::Bind(&MediaStreamManager::SetupRequest,
400 base::Unretained(this), label)); 407 base::Unretained(this), label));
401 return label; 408 return label;
402 } 409 }
403 410
404 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, 411 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester,
405 int render_process_id, 412 int render_process_id,
406 int render_view_id, 413 int render_view_id,
407 const ResourceContext::SaltCallback& sc, 414 const ResourceContext::SaltCallback& sc,
408 int page_request_id, 415 int page_request_id,
409 const StreamOptions& options, 416 const StreamOptions& options,
410 const GURL& security_origin) { 417 const GURL& security_origin,
418 bool user_gesture) {
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
412 DVLOG(1) << "GenerateStream()"; 420 DVLOG(1) << "GenerateStream()";
413 if (CommandLine::ForCurrentProcess()->HasSwitch( 421 if (CommandLine::ForCurrentProcess()->HasSwitch(
414 switches::kUseFakeUIForMediaStream)) { 422 switches::kUseFakeUIForMediaStream)) {
415 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); 423 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>());
416 } 424 }
417 425
418 DeviceRequest* request = new DeviceRequest(requester, 426 DeviceRequest* request = new DeviceRequest(requester,
419 render_process_id, 427 render_process_id,
420 render_view_id, 428 render_view_id,
421 page_request_id, 429 page_request_id,
422 security_origin, 430 security_origin,
431 user_gesture,
423 MEDIA_GENERATE_STREAM, 432 MEDIA_GENERATE_STREAM,
424 options, 433 options,
425 sc); 434 sc);
426 435
427 const std::string& label = AddRequest(request); 436 const std::string& label = AddRequest(request);
428 437
429 // Post a task and handle the request asynchronously. The reason is that the 438 // Post a task and handle the request asynchronously. The reason is that the
430 // requester won't have a label for the request until this function returns 439 // requester won't have a label for the request until this function returns
431 // and thus can not handle a response. Using base::Unretained is safe since 440 // and thus can not handle a response. Using base::Unretained is safe since
432 // MediaStreamManager is deleted on the UI thread, after the IO thread has 441 // MediaStreamManager is deleted on the UI thread, after the IO thread has
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
606 DCHECK(requester); 615 DCHECK(requester);
607 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || 616 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
608 type == MEDIA_DEVICE_VIDEO_CAPTURE); 617 type == MEDIA_DEVICE_VIDEO_CAPTURE);
609 618
610 DeviceRequest* request = new DeviceRequest(requester, 619 DeviceRequest* request = new DeviceRequest(requester,
611 render_process_id, 620 render_process_id,
612 render_view_id, 621 render_view_id,
613 page_request_id, 622 page_request_id,
614 security_origin, 623 security_origin,
624 false, // user gesture
615 MEDIA_ENUMERATE_DEVICES, 625 MEDIA_ENUMERATE_DEVICES,
616 StreamOptions(), 626 StreamOptions(),
617 sc); 627 sc);
618 if (IsAudioMediaType(type)) 628 if (IsAudioMediaType(type))
619 request->SetAudioType(type); 629 request->SetAudioType(type);
620 else if (IsVideoMediaType(type)) 630 else if (IsVideoMediaType(type))
621 request->SetVideoType(type); 631 request->SetVideoType(type);
622 632
623 const std::string& label = AddRequest(request); 633 const std::string& label = AddRequest(request);
624 // Post a task and handle the request asynchronously. The reason is that the 634 // Post a task and handle the request asynchronously. The reason is that the
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 options.mandatory_video.push_back( 694 options.mandatory_video.push_back(
685 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); 695 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id));
686 } else { 696 } else {
687 NOTREACHED(); 697 NOTREACHED();
688 } 698 }
689 DeviceRequest* request = new DeviceRequest(requester, 699 DeviceRequest* request = new DeviceRequest(requester,
690 render_process_id, 700 render_process_id,
691 render_view_id, 701 render_view_id,
692 page_request_id, 702 page_request_id,
693 security_origin, 703 security_origin,
704 false, // user gesture
694 MEDIA_OPEN_DEVICE, 705 MEDIA_OPEN_DEVICE,
695 options, 706 options,
696 sc); 707 sc);
697 708
698 const std::string& label = AddRequest(request); 709 const std::string& label = AddRequest(request);
699 // Post a task and handle the request asynchronously. The reason is that the 710 // Post a task and handle the request asynchronously. The reason is that the
700 // requester won't have a label for the request until this function returns 711 // requester won't have a label for the request until this function returns
701 // and thus can not handle a response. Using base::Unretained is safe since 712 // and thus can not handle a response. Using base::Unretained is safe since
702 // MediaStreamManager is deleted on the UI thread, after the IO thread has 713 // MediaStreamManager is deleted on the UI thread, after the IO thread has
703 // been stopped. 714 // been stopped.
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 } 1827 }
1817 1828
1818 // Always do enumeration even though some enumeration is in progress, 1829 // Always do enumeration even though some enumeration is in progress,
1819 // because those enumeration commands could be sent before these devices 1830 // because those enumeration commands could be sent before these devices
1820 // change. 1831 // change.
1821 ++active_enumeration_ref_count_[stream_type]; 1832 ++active_enumeration_ref_count_[stream_type];
1822 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); 1833 GetDeviceManager(stream_type)->EnumerateDevices(stream_type);
1823 } 1834 }
1824 1835
1825 } // namespace content 1836 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698