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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 // For each period of this length record a statistic to indicate whether or not | 77 // For each period of this length record a statistic to indicate whether or not |
| 78 // the user experienced a low memory event. If this interval is changed, | 78 // the user experienced a low memory event. If this interval is changed, |
| 79 // Tabs.Discard.DiscardInLastMinute must be replaced with a new statistic. | 79 // Tabs.Discard.DiscardInLastMinute must be replaced with a new statistic. |
| 80 const int kRecentTabDiscardIntervalSeconds = 60; | 80 const int kRecentTabDiscardIntervalSeconds = 60; |
| 81 #endif | 81 #endif |
| 82 | 82 |
| 83 // If there has been no priority adjustment in this interval, assume the | 83 // If there has been no priority adjustment in this interval, assume the |
| 84 // machine was suspended and correct the timing statistics. | 84 // machine was suspended and correct the timing statistics. |
| 85 const int kSuspendThresholdSeconds = kAdjustmentIntervalSeconds * 4; | 85 const int kSuspendThresholdSeconds = kAdjustmentIntervalSeconds * 4; |
| 86 | 86 |
| 87 // If a backgrounded renderer is kept backgrounded during this time after | |
|
Sami
2016/10/06 13:10:09
s/during/for/
/after suspended/after being suspend
tasak
2016/10/07 05:31:26
Done.
| |
| 88 // suspended, resume the renderer to avoid breaking web. | |
| 89 constexpr base::TimeDelta kSuspendResumedRendererTime = | |
| 90 base::TimeDelta::FromSeconds(120); | |
| 91 | |
| 92 // After resuming and running a backgrounded renderer for this period, | |
| 93 // the renderer is purged and suspended again. | |
| 94 constexpr base::TimeDelta kResumeSuspendedRendererTime = | |
| 95 base::TimeDelta::FromSeconds(10); | |
| 96 | |
| 87 // The time during which a tab is protected from discarding after it stops being | 97 // The time during which a tab is protected from discarding after it stops being |
| 88 // audible. | 98 // audible. |
| 89 const int kAudioProtectionTimeSeconds = 60; | 99 const int kAudioProtectionTimeSeconds = 60; |
| 90 | 100 |
| 91 int FindTabStripModelById(int64_t target_web_contents_id, | 101 int FindTabStripModelById(int64_t target_web_contents_id, |
| 92 TabStripModel** model) { | 102 TabStripModel** model) { |
| 93 DCHECK(model); | 103 DCHECK(model); |
| 94 for (auto* browser : *BrowserList::GetInstance()) { | 104 for (auto* browser : *BrowserList::GetInstance()) { |
| 95 TabStripModel* local_model = browser->tab_strip_model(); | 105 TabStripModel* local_model = browser->tab_strip_model(); |
| 96 for (int idx = 0; idx < local_model->count(); idx++) { | 106 for (int idx = 0; idx < local_model->count(); idx++) { |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) | 686 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) |
| 677 return; | 687 return; |
| 678 int purge_and_suspend_time = 0; | 688 int purge_and_suspend_time = 0; |
| 679 if (!base::StringToInt( | 689 if (!base::StringToInt( |
| 680 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), | 690 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), |
| 681 &purge_and_suspend_time)) { | 691 &purge_and_suspend_time)) { |
| 682 return; | 692 return; |
| 683 } | 693 } |
| 684 if (purge_and_suspend_time <= 0) | 694 if (purge_and_suspend_time <= 0) |
| 685 return; | 695 return; |
| 696 base::TimeTicks current_time = NowTicks(); | |
| 686 auto purge_and_suspend_time_threshold = | 697 auto purge_and_suspend_time_threshold = |
| 687 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); | 698 current_time - base::TimeDelta::FromSeconds(purge_and_suspend_time); |
| 688 auto tab_stats = GetUnsortedTabStats(); | 699 auto tab_stats = GetUnsortedTabStats(); |
| 689 for (auto& tab : tab_stats) { | 700 for (auto& tab : tab_stats) { |
| 690 if (!tab.render_process_host->IsProcessBackgrounded()) | 701 if (!tab.render_process_host->IsProcessBackgrounded()) |
| 691 continue; | 702 continue; |
| 692 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without | 703 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without |
| 693 // timers for simplicity, so PurgeAndSuspend is called even after the | 704 // timers for simplicity, so PurgeAndSuspend is called even after the |
| 694 // renderer is purged and suspended once. This should be replaced with | 705 // renderer is purged and suspended once. This should be replaced with |
| 695 // timers if we want necessary and sufficient signals. | 706 // timers if we want necessary and sufficient signals. |
| 696 if (tab.last_active > purge_and_suspend_time_threshold) | 707 if (tab.last_active > purge_and_suspend_time_threshold) |
| 697 continue; | 708 continue; |
| 698 tab.render_process_host->PurgeAndSuspend(); | 709 |
| 710 auto last_purged_and_suspended_time = | |
| 711 tab.render_process_host->GetLastPurgedAndSuspendedTime(); | |
| 712 auto last_resumed_time = | |
| 713 tab.render_process_host->GetLastResumedInBackgroundTime(); | |
| 714 | |
| 715 if (last_purged_and_suspended_time < tab.last_active || | |
| 716 (last_resumed_time > last_purged_and_suspended_time && | |
| 717 last_purged_and_suspended_time > tab.last_active && | |
| 718 ((current_time - last_resumed_time) > kSuspendResumedRendererTime))) { | |
| 719 tab.render_process_host->PurgeAndSuspend(); | |
| 720 if (!task_runner_.get()) | |
| 721 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
| 722 } else { | |
| 723 auto delta = current_time - last_purged_and_suspended_time; | |
| 724 if (last_resumed_time < last_purged_and_suspended_time && | |
| 725 delta > kResumeSuspendedRendererTime) | |
| 726 tab.render_process_host->Resume(); | |
| 727 } | |
| 699 } | 728 } |
| 700 } | 729 } |
| 701 | 730 |
| 702 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { | 731 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { |
| 703 // Can't discard active index. | 732 // Can't discard active index. |
| 704 if (model->active_index() == index) | 733 if (model->active_index() == index) |
| 705 return nullptr; | 734 return nullptr; |
| 706 | 735 |
| 707 WebContents* old_contents = model->GetWebContentsAt(index); | 736 WebContents* old_contents = model->GetWebContentsAt(index); |
| 708 | 737 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 // platform. | 969 // platform. |
| 941 std::string allow_multiple_discards = variations::GetVariationParamValue( | 970 std::string allow_multiple_discards = variations::GetVariationParamValue( |
| 942 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | 971 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); |
| 943 return (allow_multiple_discards != "true"); | 972 return (allow_multiple_discards != "true"); |
| 944 #else | 973 #else |
| 945 return false; | 974 return false; |
| 946 #endif | 975 #endif |
| 947 } | 976 } |
| 948 | 977 |
| 949 } // namespace memory | 978 } // namespace memory |
| OLD | NEW |