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)) | |
| 685 return false; | |
| 686 | |
| 687 if (web_contents->GetContentsMimeType() == "application/pdf") | |
|
haraken
2016/10/03 06:32:35
I don't think this check is needed. It will be saf
tasak
2016/10/03 07:08:54
Done.
| |
| 688 return false; | |
| 689 | |
| 690 // Do not purge and suspend a tab that was explicitly disallowed to. | |
| 691 // Note: reused tab discarding logic. | |
| 692 if (!IsTabAutoDiscardable(web_contents)) | |
| 693 return false; | |
| 694 | |
|
haraken
2016/10/03 06:32:35
I'd add the minimum_protection_time_ check we have
tasak
2016/10/03 07:08:54
Done.
| |
| 695 return true; | |
| 696 } | |
| 697 | |
| 673 void TabManager::PurgeAndSuspendBackgroundedTabs() { | 698 void TabManager::PurgeAndSuspendBackgroundedTabs() { |
| 674 const base::CommandLine& command_line = | 699 const base::CommandLine& command_line = |
| 675 *base::CommandLine::ForCurrentProcess(); | 700 *base::CommandLine::ForCurrentProcess(); |
| 676 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) | 701 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) |
| 677 return; | 702 return; |
| 678 int purge_and_suspend_time = 0; | 703 int purge_and_suspend_time = 0; |
| 679 if (!base::StringToInt( | 704 if (!base::StringToInt( |
| 680 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), | 705 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), |
| 681 &purge_and_suspend_time)) { | 706 &purge_and_suspend_time)) { |
| 682 return; | 707 return; |
| 683 } | 708 } |
| 684 if (purge_and_suspend_time <= 0) | 709 if (purge_and_suspend_time <= 0) |
| 685 return; | 710 return; |
| 686 auto purge_and_suspend_time_threshold = | 711 auto purge_and_suspend_time_threshold = |
| 687 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); | 712 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); |
| 688 auto tab_stats = GetUnsortedTabStats(); | 713 auto tab_stats = GetUnsortedTabStats(); |
| 689 for (auto& tab : tab_stats) { | 714 for (auto& tab : tab_stats) { |
| 690 if (!tab.render_process_host->IsProcessBackgrounded()) | 715 if (!tab.render_process_host->IsProcessBackgrounded()) |
| 691 continue; | 716 continue; |
| 692 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without | 717 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without |
| 693 // timers for simplicity, so PurgeAndSuspend is called even after the | 718 // timers for simplicity, so PurgeAndSuspend is called even after the |
| 694 // renderer is purged and suspended once. This should be replaced with | 719 // renderer is purged and suspended once. This should be replaced with |
| 695 // timers if we want necessary and sufficient signals. | 720 // timers if we want necessary and sufficient signals. |
| 696 if (tab.last_active > purge_and_suspend_time_threshold) | 721 if (tab.last_active > purge_and_suspend_time_threshold) |
| 697 continue; | 722 continue; |
| 723 if (!CanPurgeAndSuspendBackgroundedTab(tab.tab_contents_id)) | |
| 724 continue; | |
| 698 tab.render_process_host->PurgeAndSuspend(); | 725 tab.render_process_host->PurgeAndSuspend(); |
| 699 } | 726 } |
| 700 } | 727 } |
| 701 | 728 |
| 702 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { | 729 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { |
| 703 // Can't discard active index. | 730 // Can't discard active index. |
| 704 if (model->active_index() == index) | 731 if (model->active_index() == index) |
| 705 return nullptr; | 732 return nullptr; |
| 706 | 733 |
| 707 WebContents* old_contents = model->GetWebContentsAt(index); | 734 WebContents* old_contents = model->GetWebContentsAt(index); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 // platform. | 967 // platform. |
| 941 std::string allow_multiple_discards = variations::GetVariationParamValue( | 968 std::string allow_multiple_discards = variations::GetVariationParamValue( |
| 942 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | 969 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); |
| 943 return (allow_multiple_discards != "true"); | 970 return (allow_multiple_discards != "true"); |
| 944 #else | 971 #else |
| 945 return false; | 972 return false; |
| 946 #endif | 973 #endif |
| 947 } | 974 } |
| 948 | 975 |
| 949 } // namespace memory | 976 } // namespace memory |
| OLD | NEW |