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 6cc6b5323e0502019e87b08d80edc5f69aaba0a4..aac45c99c6c1660305b384eebd934a22dc5d3c9b 100644 |
| --- a/chrome/browser/media/media_stream_capture_indicator.cc |
| +++ b/chrome/browser/media/media_stream_capture_indicator.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/bind.h" |
| #include "base/i18n/rtl.h" |
| #include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/browser_process.h" |
| @@ -19,28 +20,24 @@ |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/invalidate_type.h" |
| -#include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_delegate.h" |
| -#include "content/public/common/media_stream_request.h" |
| #include "grit/chromium_strings.h" |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources.h" |
| #include "net/base/net_util.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| +#include "ui/gfx/image/image_skia.h" |
| using content::BrowserThread; |
| using content::WebContents; |
| namespace { |
| -const extensions::Extension* GetExtension(int render_process_id, |
| - int render_view_id) { |
| +const extensions::Extension* GetExtension(WebContents* web_contents) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - WebContents* web_contents = tab_util::GetWebContentsByID( |
| - render_process_id, render_view_id); |
| if (!web_contents) |
| return NULL; |
| @@ -59,14 +56,13 @@ const extensions::Extension* GetExtension(int render_process_id, |
| // Gets the security originator of the tab. It returns a string with no '/' |
| // at the end to display in the UI. |
| -string16 GetSecurityOrigin(int render_process_id, int render_view_id) { |
| +string16 GetSecurityOrigin(WebContents* web_contents) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - WebContents* tab_content = tab_util::GetWebContentsByID( |
| - render_process_id, render_view_id); |
| - if (!tab_content) |
| + |
| + if (!web_contents) |
| return string16(); |
| - std::string security_origin = tab_content->GetURL().GetOrigin().spec(); |
| + std::string security_origin = web_contents->GetURL().GetOrigin().spec(); |
| // Remove the last character if it is a '/'. |
| if (!security_origin.empty()) { |
| @@ -78,50 +74,85 @@ string16 GetSecurityOrigin(int render_process_id, int render_view_id) { |
| return UTF8ToUTF16(security_origin); |
| } |
| -string16 GetTitle(int render_process_id, int render_view_id) { |
| +string16 GetTitle(WebContents* web_contents) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - const extensions::Extension* extension = |
| - GetExtension(render_process_id, render_view_id); |
| + if (!web_contents) |
| + return string16(); |
| + |
| + const extensions::Extension* const extension = GetExtension(web_contents); |
| if (extension) |
| return UTF8ToUTF16(extension->name()); |
| - WebContents* tab_content = tab_util::GetWebContentsByID( |
| - render_process_id, render_view_id); |
| - if (!tab_content) |
| - return string16(); |
| - |
| - string16 tab_title = tab_content->GetTitle(); |
| + string16 tab_title = web_contents->GetTitle(); |
| if (tab_title.empty()) { |
| // If the page's title is empty use its security originator. |
| - tab_title = GetSecurityOrigin(render_process_id, render_view_id); |
| + tab_title = GetSecurityOrigin(web_contents); |
| } else { |
| // If the page's title matches its URL, use its security originator. |
| std::string languages = |
| content::GetContentClient()->browser()->GetAcceptLangs( |
| - tab_content->GetBrowserContext()); |
| - if (tab_title == net::FormatUrl(tab_content->GetURL(), languages)) |
| - tab_title = GetSecurityOrigin(render_process_id, render_view_id); |
| + web_contents->GetBrowserContext()); |
| + if (tab_title == net::FormatUrl(web_contents->GetURL(), languages)) |
| + tab_title = GetSecurityOrigin(web_contents); |
| } |
| return tab_title; |
| } |
| +void CountDevices(const content::MediaStreamDevices& devices, |
| + int* num_audio, int* num_video, int* num_mirroring) { |
| + *num_audio = 0; |
| + *num_video = 0; |
| + *num_mirroring = 0; |
| + 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) { |
| + ++(*num_mirroring); |
| + } else if (content::IsAudioMediaType(it->type)) { |
| + ++(*num_audio); |
| + } else if (content::IsVideoMediaType(it->type)) { |
| + ++(*num_video); |
| + } else { |
| + NOTIMPLEMENTED(); |
| + } |
| + } |
| +} |
| + |
| } // namespace |
| -MediaStreamCaptureIndicator::TabEquals::TabEquals(WebContents* web_contents, |
| - int render_process_id, |
| - int render_view_id) |
| - : web_contents_(web_contents), |
| - render_process_id_(render_process_id), |
| - render_view_id_(render_view_id) {} |
| - |
| -bool MediaStreamCaptureIndicator::TabEquals::operator() ( |
| - const MediaStreamCaptureIndicator::CaptureDeviceTab& tab) { |
| - return (web_contents_ == tab.web_contents || |
| - (render_process_id_ == tab.render_process_id && |
| - render_view_id_ == tab.render_view_id)); |
| +// Stores usage counts for all the capture devices associated with a single |
| +// WebContents instance. |
| +class MediaStreamCaptureIndicator::CaptureDeviceUsage { |
| + public: |
| + CaptureDeviceUsage(); |
| + |
| + bool IsCapturingAudio() const { return audio_ref_count_ > 0; } |
| + bool IsCapturingVideo() const { return video_ref_count_ > 0; } |
| + bool IsMirroring() const { return mirroring_ref_count_ > 0; } |
| + |
| + void TallyUsage(int num_audio, int num_video, int num_mirroring); |
| + |
| + private: |
| + int audio_ref_count_; |
| + int video_ref_count_; |
| + int mirroring_ref_count_; |
| +}; |
| + |
| +MediaStreamCaptureIndicator::CaptureDeviceUsage::CaptureDeviceUsage() |
| + : audio_ref_count_(0), video_ref_count_(0), mirroring_ref_count_(0) { |
| +} |
| + |
| +void MediaStreamCaptureIndicator::CaptureDeviceUsage::TallyUsage( |
| + int num_audio, int num_video, int num_mirroring) { |
| + audio_ref_count_ += num_audio; |
| + DCHECK_LE(0, audio_ref_count_); |
| + video_ref_count_ += num_video; |
| + DCHECK_LE(0, video_ref_count_); |
| + mirroring_ref_count_ += num_mirroring; |
| + DCHECK_LE(0, mirroring_ref_count_); |
| } |
| MediaStreamCaptureIndicator::MediaStreamCaptureIndicator() |
| @@ -133,8 +164,9 @@ MediaStreamCaptureIndicator::MediaStreamCaptureIndicator() |
| } |
| MediaStreamCaptureIndicator::~MediaStreamCaptureIndicator() { |
| - // The user is responsible for cleaning up by closing all the opened devices. |
| - DCHECK(tabs_.empty()); |
| + // The user is responsible for cleaning up by reporting the closure of any |
| + // opened devices. |
| + DCHECK(usage_map_.empty()); |
| } |
| bool MediaStreamCaptureIndicator::IsCommandIdChecked( |
| @@ -156,18 +188,18 @@ bool MediaStreamCaptureIndicator::GetAcceleratorForCommandId( |
| void MediaStreamCaptureIndicator::ExecuteCommand(int command_id) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - DCHECK(command_id >= IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST && |
|
justinlin
2013/01/23 19:30:43
nit: This previous DCHECK seems more clear to me?
miu
2013/01/23 20:33:28
They're different. The old DCHECK just checks whe
|
| - command_id <= IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_LAST); |
| - int index = command_id - IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST; |
| - WebContents* web_content = tab_util::GetWebContentsByID( |
| - tabs_[index].render_process_id, tabs_[index].render_view_id); |
| - DCHECK(web_content); |
| - if (!web_content) { |
| + |
| + const int index = |
| + command_id - IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST; |
| + DCHECK_LE(0, index); |
| + DCHECK_GT(static_cast<int>(command_map_.size()), index); |
| + WebContents* const web_contents = command_map_[index]; |
| + if (!web_contents) { |
| NOTREACHED(); |
| return; |
| } |
| - web_content->GetDelegate()->ActivateContents(web_content); |
| + web_contents->GetDelegate()->ActivateContents(web_contents); |
| } |
| void MediaStreamCaptureIndicator::CaptureDevicesOpened( |
| @@ -202,9 +234,7 @@ void MediaStreamCaptureIndicator::DoDevicesOpenedOnUIThread( |
| const content::MediaStreamDevices& devices) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - CreateStatusTray(); |
|
justinlin
2013/01/23 19:30:43
Did you mean to remove this?
miu
2013/01/23 20:33:28
Yes. Two things happening here:
1. I renamed the
justinlin
2013/01/24 07:04:44
OK. I'm probably nitpicking too much, but could we
miu
2013/01/28 19:36:51
I'm not sure. I'll have to try this out to see wh
justinlin
2013/01/28 22:31:21
I meant in that case, we don't have a web_contents
|
| - |
| - AddCaptureDeviceTab(render_process_id, render_view_id, devices); |
| + AddCaptureDevices(render_process_id, render_view_id, devices); |
| } |
| void MediaStreamCaptureIndicator::DoDevicesClosedOnUIThread( |
| @@ -213,10 +243,10 @@ void MediaStreamCaptureIndicator::DoDevicesClosedOnUIThread( |
| const content::MediaStreamDevices& devices) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - RemoveCaptureDeviceTab(render_process_id, render_view_id, devices); |
| + RemoveCaptureDevices(render_process_id, render_view_id, devices); |
| } |
| -void MediaStreamCaptureIndicator::CreateStatusTray() { |
| +void MediaStreamCaptureIndicator::MaybeCreateStatusTrayIcon() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if (status_icon_) |
| return; |
| @@ -254,10 +284,7 @@ void MediaStreamCaptureIndicator::EnsureStatusTrayIconResources() { |
| } |
| void MediaStreamCaptureIndicator::ShowBalloon( |
| - int render_process_id, |
| - int render_view_id, |
| - bool audio, |
| - bool video) { |
| + WebContents* web_contents, bool audio, bool video) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK(audio || video); |
| @@ -268,8 +295,7 @@ void MediaStreamCaptureIndicator::ShowBalloon( |
| message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_VIDEO_ONLY; |
| // Only show the balloon for extensions. |
| - const extensions::Extension* extension = |
| - GetExtension(render_process_id, render_view_id); |
| + const extensions::Extension* const extension = GetExtension(web_contents); |
| if (!extension) { |
| DVLOG(1) << "Balloon is shown only for extensions"; |
| return; |
| @@ -278,10 +304,6 @@ void MediaStreamCaptureIndicator::ShowBalloon( |
| string16 message = |
| l10n_util::GetStringFUTF16(message_id, |
| UTF8ToUTF16(extension->name())); |
| - |
| - WebContents* web_contents = tab_util::GetWebContentsByID( |
| - render_process_id, render_view_id); |
| - |
| Profile* profile = |
| Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| @@ -297,7 +319,7 @@ void MediaStreamCaptureIndicator::ShowBalloon( |
| void MediaStreamCaptureIndicator::OnImageLoaded( |
| const string16& message, |
| const gfx::Image& image) { |
| - if (!should_show_balloon_) |
| + if (!should_show_balloon_ || !status_icon_) |
| return; |
| const gfx::ImageSkia* image_skia = !image.IsEmpty() ? image.ToImageSkia() : |
| @@ -306,7 +328,7 @@ void MediaStreamCaptureIndicator::OnImageLoaded( |
| status_icon_->DisplayBalloon(*image_skia, string16(), message); |
| } |
| -void MediaStreamCaptureIndicator::Hide() { |
| +void MediaStreamCaptureIndicator::MaybeDestroyStatusTrayIcon() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| // Make sure images that finish loading don't cause a balloon to be shown. |
| @@ -333,44 +355,42 @@ void MediaStreamCaptureIndicator::UpdateStatusTrayIconContextMenu() { |
| bool audio = false; |
| bool video = false; |
| int command_id = IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST; |
| - for (CaptureDeviceTabs::iterator iter = tabs_.begin(); |
| - iter != tabs_.end();) { |
| - string16 tab_title = GetTitle(iter->render_process_id, |
| - iter->render_view_id); |
| - if (tab_title.empty()) { |
| - // Delete the entry since the tab has gone away. |
| - iter = tabs_.erase(iter); |
| - continue; |
| - } |
| + command_map_.clear(); |
| + for (UsageMap::const_iterator iter = usage_map_.begin(); |
| + iter != usage_map_.end(); ++iter) { |
| + WebContents* const web_contents = iter->first; |
| + command_map_.push_back(web_contents); |
| + menu->AddItem(command_id, GetTitle(web_contents)); |
| // Check if any audio and video devices have been used. |
| - audio = audio || iter->audio_ref_count > 0; |
| - video = video || iter->video_ref_count > 0; |
| - |
| - menu->AddItem(command_id, tab_title); |
| + const CaptureDeviceUsage& usage = *iter->second; |
| + audio = audio || usage.IsCapturingAudio(); |
| + video = video || usage.IsCapturingVideo(); |
| // If reaching the maximum number, no more item will be added to the menu. |
| if (command_id == IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_LAST) |
| break; |
| - |
| ++command_id; |
| - ++iter; |
| } |
| if (!audio && !video) { |
| - Hide(); |
| + MaybeDestroyStatusTrayIcon(); |
| return; |
| } |
| // The icon will take the ownership of the passed context menu. |
| - status_icon_->SetContextMenu(menu.release()); |
| - UpdateStatusTrayIconDisplay(audio, video); |
| + MaybeCreateStatusTrayIcon(); |
| + if (status_icon_) { |
| + status_icon_->SetContextMenu(menu.release()); |
| + UpdateStatusTrayIconDisplay(audio, video); |
| + } |
| } |
| void MediaStreamCaptureIndicator::UpdateStatusTrayIconDisplay( |
| bool audio, bool video) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK(audio || video); |
| + DCHECK(status_icon_); |
| int message_id = 0; |
| if (audio && video) { |
| message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_AUDIO_AND_VIDEO; |
| @@ -387,135 +407,120 @@ void MediaStreamCaptureIndicator::UpdateStatusTrayIconDisplay( |
| message_id, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| } |
| -void MediaStreamCaptureIndicator::AddCaptureDeviceTab( |
| +content::WebContents* MediaStreamCaptureIndicator::LookUpByKnownAlias( |
| + int render_process_id, int render_view_id) const { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + WebContents* result = |
| + tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| + if (!result) { |
| + const RenderViewIDs key(render_process_id, render_view_id); |
| + AliasMap::const_iterator it = aliases_.find(key); |
| + if (it != aliases_.end()) |
|
justinlin
2013/01/23 19:30:43
DCHECK this? Seems like all lookups should resolve
miu
2013/01/23 20:33:28
Not necessarily. Example: When this method is cal
|
| + result = it->second; |
| + } |
| + return result; |
| +} |
| + |
| +void MediaStreamCaptureIndicator::AddCaptureDevices( |
| int render_process_id, |
| int render_view_id, |
| const content::MediaStreamDevices& devices) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id, |
| - render_view_id); |
| + WebContents* const web_contents = |
| + LookUpByKnownAlias(render_process_id, render_view_id); |
| if (!web_contents) |
| return; |
| - CaptureDeviceTabs::iterator iter = std::find_if( |
| - tabs_.begin(), tabs_.end(), TabEquals(web_contents, |
| - render_process_id, |
| - render_view_id)); |
| - if (iter == tabs_.end()) { |
| - tabs_.push_back(CaptureDeviceTab(web_contents, |
| - render_process_id, |
| - render_view_id)); |
| - iter = tabs_.end() - 1; |
| - } |
| + // Increase the usage ref-counts. |
| + int num_audio, num_video, num_mirroring; |
| + CountDevices(devices, &num_audio, &num_video, &num_mirroring); |
| + DCHECK(num_audio > 0 || num_video > 0 || num_mirroring > 0); |
| + CaptureDeviceUsage*& usage = usage_map_[web_contents]; |
| + if (!usage) |
| + usage = new CaptureDeviceUsage(); |
| + usage->TallyUsage(num_audio, num_video, num_mirroring); |
| + |
| + // Keep track of the IDs as a known alias to the WebContents instance. |
| + const AliasMap::iterator insert_it = aliases_.insert( |
| + make_pair(RenderViewIDs(render_process_id, render_view_id), |
| + web_contents)).first; |
| + DCHECK_EQ(web_contents, insert_it->second) |
| + << "BUG: IDs refer to two different WebContents instances."; |
| - bool audio = false; |
| - bool video = false; |
| - bool tab_capture = false; |
| - content::MediaStreamDevices::const_iterator dev = devices.begin(); |
| - for (; dev != devices.end(); ++dev) { |
| - if (dev->type == content::MEDIA_TAB_AUDIO_CAPTURE || |
| - dev->type == content::MEDIA_TAB_VIDEO_CAPTURE) { |
| - ++iter->tab_capture_ref_count; |
| - tab_capture = true; |
| - } else if (content::IsAudioMediaType(dev->type)) { |
| - ++iter->audio_ref_count; |
| - audio = true; |
| - } else if (content::IsVideoMediaType(dev->type)) { |
| - ++iter->video_ref_count; |
| - video = true; |
| - } else { |
| - NOTIMPLEMENTED(); |
| - } |
| - } |
| - |
| - DCHECK(web_contents); |
| web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| // Don't use desktop notifications for tab capture. We use a favicon |
| // glow notification instead. |
| - if (!status_icon_ || tab_capture) |
| + if (num_mirroring > 0 && num_audio == 0 && num_video == 0) |
| return; |
| UpdateStatusTrayIconContextMenu(); |
| - ShowBalloon(render_process_id, render_view_id, audio, video); |
| + ShowBalloon(web_contents, num_audio > 0, num_video > 0); |
| } |
| -void MediaStreamCaptureIndicator::RemoveCaptureDeviceTab( |
| +void MediaStreamCaptureIndicator::RemoveCaptureDevices( |
| int render_process_id, |
| int render_view_id, |
| const content::MediaStreamDevices& devices) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id, |
| - render_view_id); |
| - CaptureDeviceTabs::iterator iter = std::find_if( |
| - tabs_.begin(), tabs_.end(), TabEquals(web_contents, |
| - render_process_id, |
| - render_view_id)); |
| - |
| - if (iter != tabs_.end()) { |
| - content::MediaStreamDevices::const_iterator dev = devices.begin(); |
| - for (; dev != devices.end(); ++dev) { |
| - if (dev->type == content::MEDIA_TAB_AUDIO_CAPTURE || |
| - dev->type == content::MEDIA_TAB_VIDEO_CAPTURE) { |
| - --iter->tab_capture_ref_count; |
| - } else if (content::IsAudioMediaType(dev->type)) { |
| - --iter->audio_ref_count; |
| - } else if (content::IsVideoMediaType(dev->type)) { |
| - --iter->video_ref_count; |
| + |
| + WebContents* const web_contents = |
| + LookUpByKnownAlias(render_process_id, render_view_id); |
| + if (!web_contents) |
| + return; |
| + |
| + // Decrease the usage ref-counts. |
| + int num_audio, num_video, num_mirroring; |
|
justinlin
2013/01/23 19:30:43
nit: I think the style guide specifies that they e
miu
2013/01/23 20:33:28
Done.
|
| + CountDevices(devices, &num_audio, &num_video, &num_mirroring); |
| + CaptureDeviceUsage* const usage = usage_map_[web_contents]; |
| + DCHECK(usage); |
| + usage->TallyUsage(-num_audio, -num_video, -num_mirroring); |
| + |
| + // Remove the usage and alias mappings if all the devices have been closed. |
| + if (!usage->IsCapturingAudio() && !usage->IsCapturingVideo() && |
| + !usage->IsMirroring()) { |
| + for (AliasMap::iterator alias_it = aliases_.begin(); |
| + alias_it != aliases_.end(); ) { |
| + if (alias_it->second == web_contents) { |
| + aliases_.erase(alias_it++); |
| } else { |
| - NOTIMPLEMENTED(); |
| + ++alias_it; |
| } |
| - |
| - DCHECK_GE(iter->audio_ref_count, 0); |
| - DCHECK_GE(iter->video_ref_count, 0); |
| } |
| - |
| - // Remove the tab if all the devices have been closed. |
| - if (iter->audio_ref_count == 0 && iter->video_ref_count == 0 && |
| - iter->tab_capture_ref_count == 0) |
| - tabs_.erase(iter); |
| + delete usage; |
| + usage_map_.erase(web_contents); |
| } |
| - if (web_contents) |
| - web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| - |
| - if (!status_icon_) |
| - return; |
| + web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| UpdateStatusTrayIconContextMenu(); |
| } |
| -bool MediaStreamCaptureIndicator::IsProcessCapturing(int render_process_id, |
| - int render_view_id) const { |
| +bool MediaStreamCaptureIndicator::IsRenderViewCapturing( |
| + int render_process_id, int render_view_id) const { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id, |
| - render_view_id); |
| + |
| + WebContents* const web_contents = |
| + LookUpByKnownAlias(render_process_id, render_view_id); |
| if (!web_contents) |
| return false; |
| - CaptureDeviceTabs::const_iterator iter = std::find_if( |
| - tabs_.begin(), tabs_.end(), TabEquals(web_contents, |
| - render_process_id, |
| - render_view_id)); |
| - if (iter == tabs_.end()) |
| - return false; |
| - return (iter->audio_ref_count > 0 || iter->video_ref_count > 0); |
| + UsageMap::const_iterator it = usage_map_.find(web_contents); |
| + return (it != usage_map_.end() && |
| + (it->second->IsCapturingAudio() || it->second->IsCapturingVideo())); |
| } |
| -bool MediaStreamCaptureIndicator::IsProcessCapturingTab( |
| +bool MediaStreamCaptureIndicator::IsRenderViewMirroring( |
| int render_process_id, int render_view_id) const { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id, |
| - render_view_id); |
| + |
| + WebContents* const web_contents = |
| + LookUpByKnownAlias(render_process_id, render_view_id); |
| if (!web_contents) |
| return false; |
| - CaptureDeviceTabs::const_iterator iter = std::find_if( |
| - tabs_.begin(), tabs_.end(), TabEquals(web_contents, |
| - render_process_id, |
| - render_view_id)); |
| - if (iter == tabs_.end()) |
| - return false; |
| - return (iter->tab_capture_ref_count > 0); |
| + UsageMap::const_iterator it = usage_map_.find(web_contents); |
| + return it != usage_map_.end() && it->second->IsMirroring(); |
| } |