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/memory/tab_manager.h" | 5 #include "chrome/browser/memory/tab_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 | 663 |
664 #if defined(OS_CHROMEOS) | 664 #if defined(OS_CHROMEOS) |
665 TabStatsList stats_list = GetTabStats(); | 665 TabStatsList stats_list = GetTabStats(); |
666 // This starts the CrOS specific OOM adjustments in /proc/<pid>/oom_score_adj. | 666 // This starts the CrOS specific OOM adjustments in /proc/<pid>/oom_score_adj. |
667 delegate_->AdjustOomPriorities(stats_list); | 667 delegate_->AdjustOomPriorities(stats_list); |
668 #endif | 668 #endif |
669 | 669 |
670 PurgeAndSuspendBackgroundedTabs(); | 670 PurgeAndSuspendBackgroundedTabs(); |
671 } | 671 } |
672 | 672 |
| 673 bool TabManager::CanPurgeAndSuspendBackgroundedTab( |
| 674 int64_t target_web_contents_id) const { |
| 675 TabStripModel* model; |
| 676 int idx = FindTabStripModelById(target_web_contents_id, &model); |
| 677 if (idx == -1) |
| 678 return false; |
| 679 |
| 680 WebContents* web_contents = model->GetWebContentsAt(idx); |
| 681 |
| 682 // Do not suspend tabs that are playing either playing audio or accessing the |
| 683 // microphone or camera as it's too distruptive to the user experience. |
| 684 if (IsMediaTab(web_contents)) |
| 685 return false; |
| 686 |
| 687 return true; |
| 688 } |
| 689 |
673 void TabManager::PurgeAndSuspendBackgroundedTabs() { | 690 void TabManager::PurgeAndSuspendBackgroundedTabs() { |
674 const base::CommandLine& command_line = | 691 const base::CommandLine& command_line = |
675 *base::CommandLine::ForCurrentProcess(); | 692 *base::CommandLine::ForCurrentProcess(); |
676 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) | 693 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) |
677 return; | 694 return; |
678 int purge_and_suspend_time = 0; | 695 int purge_and_suspend_time = 0; |
679 if (!base::StringToInt( | 696 if (!base::StringToInt( |
680 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), | 697 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), |
681 &purge_and_suspend_time)) { | 698 &purge_and_suspend_time)) { |
682 return; | 699 return; |
683 } | 700 } |
684 if (purge_and_suspend_time <= 0) | 701 if (purge_and_suspend_time <= 0) |
685 return; | 702 return; |
686 auto purge_and_suspend_time_threshold = | 703 auto purge_and_suspend_time_threshold = |
687 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); | 704 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); |
688 auto tab_stats = GetUnsortedTabStats(); | 705 auto tab_stats = GetUnsortedTabStats(); |
689 for (auto& tab : tab_stats) { | 706 for (auto& tab : tab_stats) { |
690 if (!tab.render_process_host->IsProcessBackgrounded()) | 707 if (!tab.render_process_host->IsProcessBackgrounded()) |
691 continue; | 708 continue; |
692 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without | 709 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without |
693 // timers for simplicity, so PurgeAndSuspend is called even after the | 710 // timers for simplicity, so PurgeAndSuspend is called even after the |
694 // renderer is purged and suspended once. This should be replaced with | 711 // renderer is purged and suspended once. This should be replaced with |
695 // timers if we want necessary and sufficient signals. | 712 // timers if we want necessary and sufficient signals. |
696 if (tab.last_active > purge_and_suspend_time_threshold) | 713 if (tab.last_active > purge_and_suspend_time_threshold) |
697 continue; | 714 continue; |
| 715 if (!CanPurgeAndSuspendBackgroundedTab(tab.tab_contents_id)) |
| 716 continue; |
698 tab.render_process_host->PurgeAndSuspend(); | 717 tab.render_process_host->PurgeAndSuspend(); |
699 } | 718 } |
700 } | 719 } |
701 | 720 |
702 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { | 721 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { |
703 // Can't discard active index. | 722 // Can't discard active index. |
704 if (model->active_index() == index) | 723 if (model->active_index() == index) |
705 return nullptr; | 724 return nullptr; |
706 | 725 |
707 WebContents* old_contents = model->GetWebContentsAt(index); | 726 WebContents* old_contents = model->GetWebContentsAt(index); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 // platform. | 959 // platform. |
941 std::string allow_multiple_discards = variations::GetVariationParamValue( | 960 std::string allow_multiple_discards = variations::GetVariationParamValue( |
942 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | 961 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); |
943 return (allow_multiple_discards != "true"); | 962 return (allow_multiple_discards != "true"); |
944 #else | 963 #else |
945 return false; | 964 return false; |
946 #endif | 965 #endif |
947 } | 966 } |
948 | 967 |
949 } // namespace memory | 968 } // namespace memory |
OLD | NEW |