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..6d3b0b1da3f68234339f5caebfb9d573db80d4c8 100644 |
| --- a/chrome/browser/media/media_stream_capture_indicator.cc |
| +++ b/chrome/browser/media/media_stream_capture_indicator.cc |
| @@ -114,11 +114,15 @@ 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 { |
| @@ -130,6 +134,7 @@ class MediaStreamCaptureIndicator::WebContentsDeviceUsage |
| int video_ref_count_; |
| int mirroring_ref_count_; |
| + base::Closure stop_callback_; |
| base::WeakPtrFactory<WebContentsDeviceUsage> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(WebContentsDeviceUsage); |
| @@ -161,7 +166,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 +184,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 (content::IsScreenCaptureMediaType(it->type)) { |
| ++mirroring_ref_count_; |
| } else if (content::IsAudioInputMediaType(it->type)) { |
| ++audio_ref_count_; |
| @@ -194,8 +199,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 +211,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 (IsScreenCaptureMediaType(it->type)) { |
| --mirroring_ref_count_; |
| } else if (content::IsAudioInputMediaType(it->type)) { |
| --audio_ref_count_; |
| @@ -224,6 +230,14 @@ 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(); |
| + } |
| +} |
| + |
| MediaStreamCaptureIndicator::MediaStreamCaptureIndicator() |
| : status_icon_(NULL), |
| mic_image_(NULL), |
| @@ -297,6 +311,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) |
|
Sergey Ulanov
2016/08/19 05:54:15
Should this be a DCHECK()?
braveyao
2016/08/23 21:18:54
Done.
|
| + usage->NotifyStopped(); |
| +} |
| + |
| void MediaStreamCaptureIndicator::UnregisterWebContents( |
| WebContents* web_contents) { |
| usage_map_.erase(web_contents); |