Chromium Code Reviews| Index: chrome/browser/memory/tab_manager_delegate_chromeos.h |
| diff --git a/chrome/browser/memory/tab_manager_delegate_chromeos.h b/chrome/browser/memory/tab_manager_delegate_chromeos.h |
| index ec9d4cad972b986ccc181849f91ccb665e3e9aca..100dfa08ecfc0a83e7ebfa55c239020da95ace1b 100644 |
| --- a/chrome/browser/memory/tab_manager_delegate_chromeos.h |
| +++ b/chrome/browser/memory/tab_manager_delegate_chromeos.h |
| @@ -6,6 +6,7 @@ |
| #define CHROME_BROWSER_MEMORY_TAB_MANAGER_DELEGATE_CHROMEOS_H_ |
| #include <memory> |
| +#include <string> |
| #include <utility> |
| #include <vector> |
| @@ -78,6 +79,11 @@ class TabManagerDelegate : public aura::client::ActivationChangeObserver, |
| // Called when the timer fires, sets oom_adjust_score for all renderers. |
| void AdjustOomPriorities(const TabStatsList& tab_list); |
| + // Returns true if the process has recently been killed. |
| + // Virtual for unit testing. |
| + virtual bool IsRecentlyKilledArcProcess(const std::string& process_name, |
| + const base::TimeTicks& now); |
| + |
| protected: |
| // Kills an ARC process. Returns true if the kill request is successfully sent |
| // to Android. Virtual for unit testing. |
| @@ -87,11 +93,14 @@ class TabManagerDelegate : public aura::client::ActivationChangeObserver, |
| // Virtual for unit testing. |
| virtual bool KillTab(int64_t tab_id); |
| - // Get debugd client instance. |
| + // Get debugd client instance. Virtual for unit testing. |
| virtual chromeos::DebugDaemonClient* GetDebugDaemonClient(); |
| private: |
| FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, CandidatesSorted); |
| + FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, IsRecentlyKilledArcProcess); |
| + FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, |
| + DoNotKillRecentlyKilledArcProcesses); |
| FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, KillMultipleProcesses); |
| FRIEND_TEST_ALL_PREFIXES(TabManagerDelegateTest, SetOomScoreAdj); |
| @@ -112,6 +121,9 @@ class TabManagerDelegate : public aura::client::ActivationChangeObserver, |
| // Cache OOM scores in memory. |
| typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap; |
| + // A map from an ARC process name to a monotonic timestamp when it's killed. |
| + typedef base::hash_map<std::string, base::TimeTicks> KilledArcProcessesMap; |
| + |
| // Get the list of candidates to kill, sorted by descending importance. |
| static std::vector<Candidate> GetSortedCandidates( |
| const TabStatsList& tab_list, |
| @@ -149,6 +161,11 @@ class TabManagerDelegate : public aura::client::ActivationChangeObserver, |
| // Initiates an oom priority adjustment. |
| void ScheduleEarlyOomPrioritiesAdjustment(); |
| + // A constant to avoid killing a process too often. ARC processes sometimes |
| + // respawn right after being killed. In that case, killing them every time |
| + // is just a waste of resources. |
| + static const int64_t kArcSkipKillingTimeInSeconds; |
|
Luis Héctor Chávez
2017/05/02 20:16:27
nit: maybe call this kArcRespawnKillDelay or kArcR
Yusuke Sato
2017/05/02 20:47:32
Done. Following the offline discussion, added a st
|
| + |
| // Holds a reference to the owning TabManager. |
| const base::WeakPtr<TabManager> tab_manager_; |
| @@ -165,6 +182,9 @@ class TabManagerDelegate : public aura::client::ActivationChangeObserver, |
| // Map maintaining the process handle - oom_score mapping. |
| ProcessScoreMap oom_score_map_; |
| + // Map maintaing ARC process names and their last killed time. |
| + KilledArcProcessesMap recently_killed_arc_processes_; |
| + |
| // Util for getting system memory status. |
| std::unique_ptr<TabManagerDelegate::MemoryStat> mem_stat_; |