Chromium Code Reviews| Index: chrome/browser/memory/tab_manager_delegate_chromeos.cc |
| diff --git a/chrome/browser/memory/tab_manager_delegate_chromeos.cc b/chrome/browser/memory/tab_manager_delegate_chromeos.cc |
| index dbc66dc5b1c7890a2c157059468a1368d7953961..c64ceb1e7c8f7eda59df4d88cd9788495f5c9a02 100644 |
| --- a/chrome/browser/memory/tab_manager_delegate_chromeos.cc |
| +++ b/chrome/browser/memory/tab_manager_delegate_chromeos.cc |
| @@ -8,7 +8,6 @@ |
| #include <algorithm> |
| #include <map> |
| -#include <string> |
| #include <vector> |
| #include "ash/shell.h" |
| @@ -51,6 +50,7 @@ |
| using base::ProcessHandle; |
| using base::TimeDelta; |
| +using base::TimeTicks; |
| using content::BrowserThread; |
| namespace memory { |
| @@ -92,6 +92,9 @@ void OnSetOomScoreAdj(bool success, const std::string& output) { |
| } // namespace |
| +// static |
| +const int64_t TabManagerDelegate::kArcSkipKillingTimeInSeconds = 60; |
| + |
| std::ostream& operator<<(std::ostream& os, const ProcessType& type) { |
| switch (type) { |
| case ProcessType::FOCUSED_APP: |
| @@ -552,6 +555,18 @@ TabManagerDelegate::GetSortedCandidates( |
| return candidates; |
| } |
| +bool TabManagerDelegate::IsRecentlyKilledArcProcess( |
| + const std::string& process_name, |
| + const TimeTicks& now) { |
| + static constexpr TimeDelta kArcSkipKillingTime = |
| + TimeDelta::FromSeconds(kArcSkipKillingTimeInSeconds); |
| + |
| + auto it = recently_killed_arc_processes_.find(process_name); |
|
Luis Héctor Chávez
2017/05/02 20:16:27
nit: maybe const auto.
Yusuke Sato
2017/05/02 20:47:32
Done.
|
| + if (it == recently_killed_arc_processes_.end()) |
| + return false; |
| + return (now - it->second) <= kArcSkipKillingTime; |
| +} |
| + |
| bool TabManagerDelegate::KillArcProcess(const int nspid) { |
| auto* arc_service_manager = arc::ArcServiceManager::Get(); |
| if (!arc_service_manager) |
| @@ -588,6 +603,7 @@ void TabManagerDelegate::LowMemoryKillImpl( |
| GetSortedCandidates(tab_list, arc_processes); |
| int target_memory_to_free_kb = mem_stat_->TargetMemoryToFreeKB(); |
| + const TimeTicks now = TimeTicks::Now(); |
| // Kill processes until the estimated amount of freed memory is sufficient to |
| // bring the system memory back to a normal level. |
| @@ -608,9 +624,14 @@ void TabManagerDelegate::LowMemoryKillImpl( |
| continue; |
| } |
| if (it->app()) { |
| + if (IsRecentlyKilledArcProcess(it->app()->process_name(), now)) { |
| + MEMORY_LOG(ERROR) << "Avoided killing " << *it << " too often"; |
| + continue; |
| + } |
| int estimated_memory_freed_kb = |
| mem_stat_->EstimatedMemoryFreedKB(it->app()->pid()); |
| if (KillArcProcess(it->app()->nspid())) { |
| + recently_killed_arc_processes_[it->app()->process_name()] = now; |
| target_memory_to_free_kb -= estimated_memory_freed_kb; |
| MemoryKillsMonitor::LogLowMemoryKill("APP", estimated_memory_freed_kb); |
| MEMORY_LOG(ERROR) << "Killed " << *it << ", estimated " |