Chromium Code Reviews| Index: chrome/browser/media/media_stream_capture_indicator.cc |
| diff --git a/chrome/browser/media/media_stream_capture_indicator.cc b/chrome/browser/media/media_stream_capture_indicator.cc |
| index 883de4833d8e33ffed9da120aac8a7cc54594fd7..c0dac2671d977f5d2f902344e8d934eb33ac7666 100644 |
| --- a/chrome/browser/media/media_stream_capture_indicator.cc |
| +++ b/chrome/browser/media/media_stream_capture_indicator.cc |
| @@ -114,22 +114,28 @@ class MediaStreamCaptureIndicator::WebContentsDeviceUsage |
| const content::MediaStreamDevices& devices); |
| // Increment ref-counts up based on the type of each device provided. |
| - void AddDevices(const content::MediaStreamDevices& devices); |
| + void AddDevices(const content::MediaStreamDevices& devices, |
| + const base::Closure& close_callback); |
| // Decrement ref-counts up based on the type of each device provided. |
| void RemoveDevices(const content::MediaStreamDevices& devices); |
| + // Helper to call |stop_callback_|. |
| + void NotifyStopped(); |
| + |
| private: |
| // content::WebContentsObserver overrides. |
| void WebContentsDestroyed() override { |
| indicator_->UnregisterWebContents(web_contents()); |
| } |
| + bool IsMirroringType(content::MediaStreamType type); |
| scoped_refptr<MediaStreamCaptureIndicator> indicator_; |
| int audio_ref_count_; |
| int video_ref_count_; |
| int mirroring_ref_count_; |
| + base::Closure stop_callback_; |
| base::WeakPtrFactory<WebContentsDeviceUsage> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(WebContentsDeviceUsage); |
| @@ -161,7 +167,7 @@ class MediaStreamCaptureIndicator::UIDelegate : public content::MediaStreamUI { |
| DCHECK(!started_); |
| started_ = true; |
| if (device_usage_.get()) |
| - device_usage_->AddDevices(devices_); |
| + device_usage_->AddDevices(devices_, close_callback); |
| return 0; |
| } |
| @@ -179,11 +185,11 @@ MediaStreamCaptureIndicator::WebContentsDeviceUsage::RegisterMediaStream( |
| } |
| void MediaStreamCaptureIndicator::WebContentsDeviceUsage::AddDevices( |
| - const content::MediaStreamDevices& devices) { |
| + const content::MediaStreamDevices& devices, |
| + const base::Closure& close_callback) { |
| for (content::MediaStreamDevices::const_iterator it = devices.begin(); |
| it != devices.end(); ++it) { |
| - if (it->type == content::MEDIA_TAB_AUDIO_CAPTURE || |
| - it->type == content::MEDIA_TAB_VIDEO_CAPTURE) { |
| + if (IsMirroringType(it->type)) { |
|
miu
2016/07/14 22:25:52
Not sure if it's safe/correct to start mixing-in d
|
| ++mirroring_ref_count_; |
| } else if (content::IsAudioInputMediaType(it->type)) { |
| ++audio_ref_count_; |
| @@ -194,8 +200,10 @@ void MediaStreamCaptureIndicator::WebContentsDeviceUsage::AddDevices( |
| } |
| } |
| - if (web_contents()) |
| + if (web_contents()) { |
| + stop_callback_ = close_callback; |
| web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| + } |
| indicator_->UpdateNotificationUserInterface(); |
| } |
| @@ -204,8 +212,7 @@ void MediaStreamCaptureIndicator::WebContentsDeviceUsage::RemoveDevices( |
| const content::MediaStreamDevices& devices) { |
| for (content::MediaStreamDevices::const_iterator it = devices.begin(); |
| it != devices.end(); ++it) { |
| - if (it->type == content::MEDIA_TAB_AUDIO_CAPTURE || |
| - it->type == content::MEDIA_TAB_VIDEO_CAPTURE) { |
| + if (IsMirroringType(it->type)) { |
| --mirroring_ref_count_; |
| } else if (content::IsAudioInputMediaType(it->type)) { |
| --audio_ref_count_; |
| @@ -224,6 +231,26 @@ void MediaStreamCaptureIndicator::WebContentsDeviceUsage::RemoveDevices( |
| indicator_->UpdateNotificationUserInterface(); |
| } |
| +void MediaStreamCaptureIndicator::WebContentsDeviceUsage::NotifyStopped() { |
| + if (!stop_callback_.is_null()) { |
| + base::Closure callback = stop_callback_; |
| + stop_callback_.Reset(); |
| + callback.Run(); |
| + } |
| +} |
| + |
| +bool MediaStreamCaptureIndicator::WebContentsDeviceUsage::IsMirroringType( |
|
miu
2016/07/14 22:25:52
This belongs here: https://cs.chromium.org/chromiu
braveyao
2016/07/18 20:46:31
Done.
|
| + content::MediaStreamType type) { |
| +#if defined(OS_ANDROID) |
| + return type == content::MEDIA_TAB_AUDIO_CAPTURE || |
| + type == content::MEDIA_TAB_VIDEO_CAPTURE || |
| + type == content::MEDIA_DESKTOP_VIDEO_CAPTURE; |
| +#else |
| + return type == content::MEDIA_TAB_AUDIO_CAPTURE || |
| + type == content::MEDIA_TAB_VIDEO_CAPTURE; |
| +#endif |
| +} |
| + |
| MediaStreamCaptureIndicator::MediaStreamCaptureIndicator() |
| : status_icon_(NULL), |
| mic_image_(NULL), |
| @@ -297,6 +324,15 @@ bool MediaStreamCaptureIndicator::IsBeingMirrored( |
| return usage && usage->IsMirroring(); |
| } |
| +void MediaStreamCaptureIndicator::NotifyStopped( |
| + content::WebContents* web_contents) const { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + WebContentsDeviceUsage* usage = usage_map_.get(web_contents); |
| + if (usage) |
| + usage->NotifyStopped(); |
| +} |
| + |
| void MediaStreamCaptureIndicator::UnregisterWebContents( |
| WebContents* web_contents) { |
| usage_map_.erase(web_contents); |