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 "chrome/browser/media/media_capture_devices_dispatcher.h" | 5 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/common/media_stream_request.h" | 33 #include "content/public/common/media_stream_request.h" |
| 34 #include "extensions/common/constants.h" | 34 #include "extensions/common/constants.h" |
| 35 #include "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
| 36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 37 #include "media/audio/audio_manager_base.h" | 37 #include "media/audio/audio_manager_base.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 39 | 39 |
| 40 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
| 41 #include "ash/shell.h" | 41 #include "ash/shell.h" |
| 42 #include "chromeos/display/output_configurator.h" | |
| 42 #endif // defined(OS_CHROMEOS) | 43 #endif // defined(OS_CHROMEOS) |
| 43 | 44 |
| 44 using content::BrowserThread; | 45 using content::BrowserThread; |
| 45 using content::MediaStreamDevices; | 46 using content::MediaStreamDevices; |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 | 49 |
| 49 // Finds a device in |devices| that has |device_id|, or NULL if not found. | 50 // Finds a device in |devices| that has |device_id|, or NULL if not found. |
| 50 const content::MediaStreamDevice* FindDeviceWithId( | 51 const content::MediaStreamDevice* FindDeviceWithId( |
| 51 const content::MediaStreamDevices& devices, | 52 const content::MediaStreamDevices& devices, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 MediaCaptureDevicesDispatcher::PendingAccessRequest::~PendingAccessRequest() {} | 164 MediaCaptureDevicesDispatcher::PendingAccessRequest::~PendingAccessRequest() {} |
| 164 | 165 |
| 165 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { | 166 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { |
| 166 return Singleton<MediaCaptureDevicesDispatcher>::get(); | 167 return Singleton<MediaCaptureDevicesDispatcher>::get(); |
| 167 } | 168 } |
| 168 | 169 |
| 169 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() | 170 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() |
| 170 : devices_enumerated_(false), | 171 : devices_enumerated_(false), |
| 171 is_device_enumeration_disabled_(false), | 172 is_device_enumeration_disabled_(false), |
| 172 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()), | 173 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()), |
| 173 audio_stream_indicator_(new AudioStreamIndicator()) { | 174 audio_stream_indicator_(new AudioStreamIndicator()), |
| 175 screen_sharing_count_(0) { | |
| 174 // MediaCaptureDevicesDispatcher is a singleton. It should be created on | 176 // MediaCaptureDevicesDispatcher is a singleton. It should be created on |
| 175 // UI thread. Otherwise, it will not receive | 177 // UI thread. Otherwise, it will not receive |
| 176 // content::NOTIFICATION_WEB_CONTENTS_DESTROYED, and that will result in | 178 // content::NOTIFICATION_WEB_CONTENTS_DESTROYED, and that will result in |
| 177 // possible use after free. | 179 // possible use after free. |
| 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 179 notifications_registrar_.Add( | 181 notifications_registrar_.Add( |
| 180 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 182 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 181 content::NotificationService::AllSources()); | 183 content::NotificationService::AllSources()); |
| 182 } | 184 } |
| 183 | 185 |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 if (it->render_process_id == render_process_id && | 729 if (it->render_process_id == render_process_id && |
| 728 it->render_view_id == render_view_id && | 730 it->render_view_id == render_view_id && |
| 729 it->page_request_id == page_request_id) { | 731 it->page_request_id == page_request_id) { |
| 730 desktop_capture_sessions_.erase(it); | 732 desktop_capture_sessions_.erase(it); |
| 731 break; | 733 break; |
| 732 } | 734 } |
| 733 } | 735 } |
| 734 } | 736 } |
| 735 } | 737 } |
| 736 | 738 |
| 739 // Updates count of screen sharing sessions. | |
| 740 if (device.type == content::MEDIA_TAB_VIDEO_CAPTURE || | |
| 741 device.type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { | |
| 742 if (state == content::MEDIA_REQUEST_STATE_DONE) { | |
| 743 ++screen_sharing_count_; | |
| 744 } else if (state == content::MEDIA_REQUEST_STATE_CLOSING) { | |
| 745 DCHECK_GT(screen_sharing_count_, 0); | |
| 746 --screen_sharing_count_; | |
| 747 } | |
| 748 #if defined(OS_CHROMEOS) | |
| 749 chromeos::OutputConfigurator* configurator = | |
|
Sergey Ulanov
2014/01/15 02:51:20
Can OutputConfigurator register to observe media s
hshi1
2014/01/15 19:43:24
Done.
| |
| 750 ash::Shell::GetInstance()->output_configurator(); | |
| 751 if (configurator) | |
|
Daniel Erat
2014/01/15 15:08:55
nit (maybe made obsolete by sergey's comment above
hshi1
2014/01/15 19:43:24
(this no longer applies)
| |
| 752 configurator->SetScreenSharingCount(screen_sharing_count_); | |
| 753 #endif | |
| 754 } | |
| 755 | |
| 737 // Cancel the request. | 756 // Cancel the request. |
| 738 if (state == content::MEDIA_REQUEST_STATE_CLOSING) { | 757 if (state == content::MEDIA_REQUEST_STATE_CLOSING) { |
| 739 bool found = false; | 758 bool found = false; |
| 740 for (RequestsQueues::iterator rqs_it = pending_requests_.begin(); | 759 for (RequestsQueues::iterator rqs_it = pending_requests_.begin(); |
| 741 rqs_it != pending_requests_.end(); ++rqs_it) { | 760 rqs_it != pending_requests_.end(); ++rqs_it) { |
| 742 RequestsQueue& queue = rqs_it->second; | 761 RequestsQueue& queue = rqs_it->second; |
| 743 for (RequestsQueue::iterator it = queue.begin(); | 762 for (RequestsQueue::iterator it = queue.begin(); |
| 744 it != queue.end(); ++it) { | 763 it != queue.end(); ++it) { |
| 745 if (it->request.render_process_id == render_process_id && | 764 if (it->request.render_process_id == render_process_id && |
| 746 it->request.render_view_id == render_view_id && | 765 it->request.render_view_id == render_view_id && |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 767 int render_view_id) { | 786 int render_view_id) { |
| 768 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 787 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 769 FOR_EACH_OBSERVER(Observer, observers_, | 788 FOR_EACH_OBSERVER(Observer, observers_, |
| 770 OnCreatingAudioStream(render_process_id, render_view_id)); | 789 OnCreatingAudioStream(render_process_id, render_view_id)); |
| 771 } | 790 } |
| 772 | 791 |
| 773 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { | 792 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { |
| 774 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 775 return desktop_capture_sessions_.size() > 0; | 794 return desktop_capture_sessions_.size() > 0; |
| 776 } | 795 } |
| OLD | NEW |