Chromium Code Reviews| 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)) | |
|
chrisha
2016/10/04 21:52:41
This is the only reason I think we shouldn't suspe
tasak
2016/10/05 05:28:46
I see.
Done.
| |
| 685 return false; | |
| 686 | |
| 687 // Do not discard a recently used tab. | |
|
Georges Khalil
2016/10/04 13:28:55
nit: s/discard/suspend.
chrisha
2016/10/04 21:52:41
I don't think this is necessary. We should feel fr
tasak
2016/10/05 05:28:46
Done.
| |
| 688 if (minimum_protection_time_.InSeconds() > 0) { | |
| 689 auto delta = | |
| 690 NowTicks() - GetWebContentsData(web_contents)->LastInactiveTime(); | |
| 691 if (delta < minimum_protection_time_) | |
| 692 return false; | |
|
Georges Khalil
2016/10/04 13:28:55
nit: Let's move this logic to a function, instead
| |
| 693 } | |
| 694 | |
| 695 // Do not purge and suspend a tab that was explicitly disallowed to. | |
| 696 // Note: reused tab discarding logic. | |
| 697 if (!IsTabAutoDiscardable(web_contents)) | |
|
chrisha
2016/10/04 21:52:41
Discarding logic shouldn't affect suspending, IMO.
tasak
2016/10/05 05:28:46
I see.
If needed, I will update src/chrome/common/
| |
| 698 return false; | |
| 699 | |
| 700 return true; | |
| 701 } | |
| 702 | |
| 673 void TabManager::PurgeAndSuspendBackgroundedTabs() { | 703 void TabManager::PurgeAndSuspendBackgroundedTabs() { |
| 674 const base::CommandLine& command_line = | 704 const base::CommandLine& command_line = |
| 675 *base::CommandLine::ForCurrentProcess(); | 705 *base::CommandLine::ForCurrentProcess(); |
| 676 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) | 706 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) |
| 677 return; | 707 return; |
| 678 int purge_and_suspend_time = 0; | 708 int purge_and_suspend_time = 0; |
| 679 if (!base::StringToInt( | 709 if (!base::StringToInt( |
| 680 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), | 710 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), |
| 681 &purge_and_suspend_time)) { | 711 &purge_and_suspend_time)) { |
| 682 return; | 712 return; |
| 683 } | 713 } |
| 684 if (purge_and_suspend_time <= 0) | 714 if (purge_and_suspend_time <= 0) |
| 685 return; | 715 return; |
| 686 auto purge_and_suspend_time_threshold = | 716 auto purge_and_suspend_time_threshold = |
| 687 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); | 717 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); |
| 688 auto tab_stats = GetUnsortedTabStats(); | 718 auto tab_stats = GetUnsortedTabStats(); |
| 689 for (auto& tab : tab_stats) { | 719 for (auto& tab : tab_stats) { |
| 690 if (!tab.render_process_host->IsProcessBackgrounded()) | 720 if (!tab.render_process_host->IsProcessBackgrounded()) |
| 691 continue; | 721 continue; |
| 692 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without | 722 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without |
| 693 // timers for simplicity, so PurgeAndSuspend is called even after the | 723 // timers for simplicity, so PurgeAndSuspend is called even after the |
| 694 // renderer is purged and suspended once. This should be replaced with | 724 // renderer is purged and suspended once. This should be replaced with |
| 695 // timers if we want necessary and sufficient signals. | 725 // timers if we want necessary and sufficient signals. |
| 696 if (tab.last_active > purge_and_suspend_time_threshold) | 726 if (tab.last_active > purge_and_suspend_time_threshold) |
| 697 continue; | 727 continue; |
| 728 if (!CanPurgeAndSuspendBackgroundedTab(tab.tab_contents_id)) | |
| 729 continue; | |
| 698 tab.render_process_host->PurgeAndSuspend(); | 730 tab.render_process_host->PurgeAndSuspend(); |
| 699 } | 731 } |
| 700 } | 732 } |
| 701 | 733 |
| 702 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { | 734 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { |
| 703 // Can't discard active index. | 735 // Can't discard active index. |
| 704 if (model->active_index() == index) | 736 if (model->active_index() == index) |
| 705 return nullptr; | 737 return nullptr; |
| 706 | 738 |
| 707 WebContents* old_contents = model->GetWebContentsAt(index); | 739 WebContents* old_contents = model->GetWebContentsAt(index); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 // platform. | 972 // platform. |
| 941 std::string allow_multiple_discards = variations::GetVariationParamValue( | 973 std::string allow_multiple_discards = variations::GetVariationParamValue( |
| 942 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | 974 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); |
| 943 return (allow_multiple_discards != "true"); | 975 return (allow_multiple_discards != "true"); |
| 944 #else | 976 #else |
| 945 return false; | 977 return false; |
| 946 #endif | 978 #endif |
| 947 } | 979 } |
| 948 | 980 |
| 949 } // namespace memory | 981 } // namespace memory |
| OLD | NEW |