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

Unified Diff: chrome/browser/memory/tab_manager.cc

Issue 1630443002: [Merge M49] [TabManager] Protect tabs that are using camera/microphone. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2623
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/memory/tab_manager.h ('k') | chrome/browser/memory/tab_manager_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/memory/tab_manager.cc
diff --git a/chrome/browser/memory/tab_manager.cc b/chrome/browser/memory/tab_manager.cc
index 371d9837c6c62a152151a093f84aaf6b529d6348..7124a5c13dc1a74f8caeb87d4c915b63d2f4f2fd 100644
--- a/chrome/browser/memory/tab_manager.cc
+++ b/chrome/browser/memory/tab_manager.cc
@@ -30,6 +30,8 @@
#include "base/time/tick_clock.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/media/media_capture_devices_dispatcher.h"
+#include "chrome/browser/media/media_stream_capture_indicator.h"
#include "chrome/browser/memory/oom_memory_details.h"
#include "chrome/browser/memory/tab_manager_web_contents_data.h"
#include "chrome/browser/profiles/profile.h"
@@ -427,7 +429,7 @@ void TabManager::AddTabStats(BrowserList* browser_list,
stats.is_app = is_browser_for_app;
stats.is_internal_page =
IsInternalPage(contents->GetLastCommittedURL());
- stats.is_playing_audio = IsAudioTab(contents);
+ stats.is_media = IsMediaTab(contents);
stats.is_pinned = model->IsTabPinned(i);
stats.is_selected = browser_active && model->IsTabSelected(i);
stats.is_discarded = GetWebContentsData(contents)->IsDiscarded();
@@ -505,10 +507,11 @@ bool TabManager::CanDiscardTab(int64_t target_web_contents_id) const {
if (web_contents->GetPageImportanceSignals().had_form_interaction)
return false;
- // Do not discard tabs that are playing audio as it's too distruptive to the
- // user experience. Note that tabs that have recently stopped playing audio by
- // at least |kAudioProtectionTimeSeconds| seconds are protected as well.
- if (IsAudioTab(web_contents))
+ // Do not discard tabs that are playing either playing audio or accessing the
+ // microphone or camera as it's too distruptive to the user experience. Note
+ // that tabs that have recently stopped playing audio by at least
+ // |kAudioProtectionTimeSeconds| seconds are protected as well.
+ if (IsMediaTab(web_contents))
return false;
// Do not discard PDFs as they might contain entry that is not saved and they
@@ -594,9 +597,18 @@ void TabManager::OnMemoryPressure(
// calling PurgeBrowserMemory() before CRITICAL is reached.
}
-bool TabManager::IsAudioTab(WebContents* contents) const {
+bool TabManager::IsMediaTab(WebContents* contents) const {
if (contents->WasRecentlyAudible())
return true;
+
+ scoped_refptr<MediaStreamCaptureIndicator> media_indicator =
+ MediaCaptureDevicesDispatcher::GetInstance()
+ ->GetMediaStreamCaptureIndicator();
+ if (media_indicator->IsCapturingUserMedia(contents) ||
+ media_indicator->IsBeingMirrored(contents)) {
+ return true;
+ }
+
auto delta = NowTicks() - GetWebContentsData(contents)->LastAudioChangeTime();
return delta < TimeDelta::FromSeconds(kAudioProtectionTimeSeconds);
}
@@ -621,8 +633,8 @@ bool TabManager::CompareTabStats(TabStats first, TabStats second) {
// Protect streaming audio and video conferencing tabs as these are similar to
// active tabs.
- if (first.is_playing_audio != second.is_playing_audio)
- return first.is_playing_audio;
+ if (first.is_media != second.is_media)
+ return first.is_media;
// Tab with internal web UI like NTP or Settings are good choices to discard,
// so protect non-Web UI and let the other conditionals finish the sort.
« no previous file with comments | « chrome/browser/memory/tab_manager.h ('k') | chrome/browser/memory/tab_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698