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 | |
| 88 // suspended, resume the renderer to avoid breaking web. | |
| 89 const int kResumeSuspendedRendererMinutes = 20; | |
|
haraken
2016/10/06 07:29:05
I'd say 20 seconds would be too short.
tasak
2016/10/06 08:02:06
2min.
Done.
| |
| 90 | |
| 91 // After resuming and running a backgrounded rendererr for this period, | |
|
haraken
2016/10/06 07:29:05
renderer
tasak
2016/10/06 08:02:06
Done.
| |
| 92 // the renderer is purged and suspended again. | |
| 93 const int kSuspendResumedRendererMinutes = 2; | |
|
haraken
2016/10/06 07:29:05
Would it be hard to run the renderer until it has
tasak
2016/10/06 08:02:06
I think, it is difficult to ask task runners in ta
| |
| 94 | |
| 87 // The time during which a tab is protected from discarding after it stops being | 95 // The time during which a tab is protected from discarding after it stops being |
| 88 // audible. | 96 // audible. |
| 89 const int kAudioProtectionTimeSeconds = 60; | 97 const int kAudioProtectionTimeSeconds = 60; |
| 90 | 98 |
| 91 int FindTabStripModelById(int64_t target_web_contents_id, | 99 int FindTabStripModelById(int64_t target_web_contents_id, |
| 92 TabStripModel** model) { | 100 TabStripModel** model) { |
| 93 DCHECK(model); | 101 DCHECK(model); |
| 94 for (auto* browser : *BrowserList::GetInstance()) { | 102 for (auto* browser : *BrowserList::GetInstance()) { |
| 95 TabStripModel* local_model = browser->tab_strip_model(); | 103 TabStripModel* local_model = browser->tab_strip_model(); |
| 96 for (int idx = 0; idx < local_model->count(); idx++) { | 104 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)) | 684 if (!command_line.HasSwitch(switches::kPurgeAndSuspendTime)) |
| 677 return; | 685 return; |
| 678 int purge_and_suspend_time = 0; | 686 int purge_and_suspend_time = 0; |
| 679 if (!base::StringToInt( | 687 if (!base::StringToInt( |
| 680 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), | 688 command_line.GetSwitchValueASCII(switches::kPurgeAndSuspendTime), |
| 681 &purge_and_suspend_time)) { | 689 &purge_and_suspend_time)) { |
| 682 return; | 690 return; |
| 683 } | 691 } |
| 684 if (purge_and_suspend_time <= 0) | 692 if (purge_and_suspend_time <= 0) |
| 685 return; | 693 return; |
| 694 base::TimeTicks current_time = NowTicks(); | |
| 686 auto purge_and_suspend_time_threshold = | 695 auto purge_and_suspend_time_threshold = |
| 687 NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time); | 696 current_time - base::TimeDelta::FromSeconds(purge_and_suspend_time); |
| 688 auto tab_stats = GetUnsortedTabStats(); | 697 auto tab_stats = GetUnsortedTabStats(); |
| 689 for (auto& tab : tab_stats) { | 698 for (auto& tab : tab_stats) { |
| 690 if (!tab.render_process_host->IsProcessBackgrounded()) | 699 if (!tab.render_process_host->IsProcessBackgrounded()) |
| 691 continue; | 700 continue; |
| 692 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without | 701 // TODO(hajimehoshi): Now calling PurgeAndSuspend is implemented without |
| 693 // timers for simplicity, so PurgeAndSuspend is called even after the | 702 // timers for simplicity, so PurgeAndSuspend is called even after the |
| 694 // renderer is purged and suspended once. This should be replaced with | 703 // renderer is purged and suspended once. This should be replaced with |
| 695 // timers if we want necessary and sufficient signals. | 704 // timers if we want necessary and sufficient signals. |
| 696 if (tab.last_active > purge_and_suspend_time_threshold) | 705 if (tab.last_active > purge_and_suspend_time_threshold) |
| 697 continue; | 706 continue; |
| 698 tab.render_process_host->PurgeAndSuspend(); | 707 |
| 708 auto last_purged_and_suspended_time = | |
| 709 tab.render_process_host->GetLastPurgedAndSuspendedTime(); | |
| 710 auto last_resumed_time = | |
| 711 tab.render_process_host->GetLastResumedInBackgroundTime(); | |
| 712 | |
| 713 if (last_purged_and_suspended_time < tab.last_active || | |
| 714 (last_resumed_time > last_purged_and_suspended_time && | |
| 715 last_purged_and_suspended_time > tab.last_active && | |
| 716 ((current_time - last_resumed_time) > | |
| 717 base::TimeDelta::FromMinutes(kSuspendResumedRendererMinutes)))) { | |
| 718 tab.render_process_host->PurgeAndSuspend(); | |
| 719 if (!task_runner_.get()) | |
| 720 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
| 721 } else { | |
| 722 auto delta = current_time - last_purged_and_suspended_time; | |
| 723 if (last_resumed_time < last_purged_and_suspended_time && | |
| 724 delta > base::TimeDelta::FromMinutes(kResumeSuspendedRendererMinutes)) | |
| 725 tab.render_process_host->Resume(); | |
| 726 } | |
| 699 } | 727 } |
| 700 } | 728 } |
| 701 | 729 |
| 702 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { | 730 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { |
| 703 // Can't discard active index. | 731 // Can't discard active index. |
| 704 if (model->active_index() == index) | 732 if (model->active_index() == index) |
| 705 return nullptr; | 733 return nullptr; |
| 706 | 734 |
| 707 WebContents* old_contents = model->GetWebContentsAt(index); | 735 WebContents* old_contents = model->GetWebContentsAt(index); |
| 708 | 736 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 // platform. | 968 // platform. |
| 941 std::string allow_multiple_discards = variations::GetVariationParamValue( | 969 std::string allow_multiple_discards = variations::GetVariationParamValue( |
| 942 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | 970 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); |
| 943 return (allow_multiple_discards != "true"); | 971 return (allow_multiple_discards != "true"); |
| 944 #else | 972 #else |
| 945 return false; | 973 return false; |
| 946 #endif | 974 #endif |
| 947 } | 975 } |
| 948 | 976 |
| 949 } // namespace memory | 977 } // namespace memory |
| OLD | NEW |