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 #ifndef CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ |
| 7 | 7 |
| 8 #include <utility> | |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/process/process.h" | 15 #include "base/process/process.h" |
| 15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 TabStats(); | 73 TabStats(); |
| 73 ~TabStats(); | 74 ~TabStats(); |
| 74 bool is_app; // browser window is an app | 75 bool is_app; // browser window is an app |
| 75 bool is_reloadable_ui; // Reloadable web UI page, like NTP or Settings. | 76 bool is_reloadable_ui; // Reloadable web UI page, like NTP or Settings. |
| 76 bool is_playing_audio; | 77 bool is_playing_audio; |
| 77 bool is_pinned; | 78 bool is_pinned; |
| 78 bool is_selected; // selected in the currently active browser window | 79 bool is_selected; // selected in the currently active browser window |
| 79 bool is_discarded; | 80 bool is_discarded; |
| 80 base::TimeTicks last_active; | 81 base::TimeTicks last_active; |
| 81 base::ProcessHandle renderer_handle; | 82 base::ProcessHandle renderer_handle; |
| 83 int child_process_host_id; | |
| 82 base::string16 title; | 84 base::string16 title; |
| 83 int64 tab_contents_id; // unique ID per WebContents | 85 int64 tab_contents_id; // unique ID per WebContents |
| 84 }; | 86 }; |
| 85 typedef std::vector<TabStats> TabStatsList; | 87 typedef std::vector<TabStats> TabStatsList; |
| 86 | 88 |
| 87 // Returns true if the |url| represents an internal Chrome web UI page that | 89 // Returns true if the |url| represents an internal Chrome web UI page that |
| 88 // can be easily reloaded and hence makes a good choice to discard. | 90 // can be easily reloaded and hence makes a good choice to discard. |
| 89 static bool IsReloadableUI(const GURL& url); | 91 static bool IsReloadableUI(const GURL& url); |
| 90 | 92 |
| 91 // Discards a tab with the given unique ID. Returns true if discard occurred. | 93 // Discards a tab with the given unique ID. Returns true if discard occurred. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 104 void PurgeBrowserMemory(); | 106 void PurgeBrowserMemory(); |
| 105 | 107 |
| 106 // Returns the number of tabs open in all browser instances. | 108 // Returns the number of tabs open in all browser instances. |
| 107 int GetTabCount() const; | 109 int GetTabCount() const; |
| 108 | 110 |
| 109 TabStatsList GetTabStatsOnUIThread(); | 111 TabStatsList GetTabStatsOnUIThread(); |
| 110 | 112 |
| 111 // Called when the timer fires, sets oom_adjust_score for all renderers. | 113 // Called when the timer fires, sets oom_adjust_score for all renderers. |
| 112 void AdjustOomPriorities(); | 114 void AdjustOomPriorities(); |
| 113 | 115 |
| 114 // Returns a list of unique process handles from |stats_list|. If multiple | 116 // Pair to hold child process host id and ProcessHandle |
| 115 // tabs use the same process, returns the first process handle. This implies | 117 typedef std::pair<int, base::ProcessHandle> ProcessInfo; |
| 118 | |
| 119 // Returns a list of child process host ids and ProcessHandle from | |
|
James Cook
2014/12/01 19:25:58
nit: ProcessHandles
sramajay
2014/12/02 15:36:58
Done.
| |
| 120 // |stats_list| with unique pids. If multiple tabs use the same process, | |
| 121 // returns the first child process host id and correspoding pid. This implies | |
|
James Cook
2014/12/01 19:25:58
nit: corresponding
sramajay
2014/12/02 15:36:58
Done.
| |
| 116 // that the processes are selected based on their "most important" tab. | 122 // that the processes are selected based on their "most important" tab. |
| 117 static std::vector<base::ProcessHandle> GetProcessHandles( | 123 static std::vector<ProcessInfo> GetChildProcessInfos( |
| 118 const TabStatsList& stats_list); | 124 const TabStatsList& stats_list); |
| 119 | 125 |
| 120 // Called by AdjustOomPriorities. | 126 // Called by AdjustOomPriorities. |
| 121 void AdjustOomPrioritiesOnFileThread(TabStatsList stats_list); | 127 void AdjustOomPrioritiesOnFileThread(TabStatsList stats_list); |
| 122 | 128 |
| 123 // Posts AdjustFocusedTabScore task to the file thread. | 129 // Posts AdjustFocusedTabScore task to the file thread. |
| 124 void OnFocusTabScoreAdjustmentTimeout(); | 130 void OnFocusTabScoreAdjustmentTimeout(); |
| 125 | 131 |
| 126 // Sets the score of the focused tab to the least value. | 132 // Sets the score of the focused tab to the least value. |
| 127 void AdjustFocusedTabScoreOnFileThread(); | 133 void AdjustFocusedTabScoreOnFileThread(); |
| 128 | 134 |
| 129 static bool CompareTabStats(TabStats first, TabStats second); | 135 static bool CompareTabStats(TabStats first, TabStats second); |
| 130 | 136 |
| 131 virtual void Observe(int type, | 137 virtual void Observe(int type, |
| 132 const content::NotificationSource& source, | 138 const content::NotificationSource& source, |
| 133 const content::NotificationDetails& details) override; | 139 const content::NotificationDetails& details) override; |
| 134 | 140 |
| 135 base::RepeatingTimer<OomPriorityManager> timer_; | 141 base::RepeatingTimer<OomPriorityManager> timer_; |
| 136 base::OneShotTimer<OomPriorityManager> focus_tab_score_adjust_timer_; | 142 base::OneShotTimer<OomPriorityManager> focus_tab_score_adjust_timer_; |
| 137 base::RepeatingTimer<OomPriorityManager> recent_tab_discard_timer_; | 143 base::RepeatingTimer<OomPriorityManager> recent_tab_discard_timer_; |
| 138 content::NotificationRegistrar registrar_; | 144 content::NotificationRegistrar registrar_; |
| 139 | 145 |
| 140 // This lock is for pid_to_oom_score_ and focus_tab_pid_. | 146 // This lock is for |oom_score_map_| and |focused_tab_process_info_|. |
| 141 base::Lock pid_to_oom_score_lock_; | 147 base::Lock oom_score_lock_; |
| 142 // map maintaining the process - oom_score mapping. | 148 // Map maintaining the child process host id - oom_score mapping. |
| 143 typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap; | 149 typedef base::hash_map<int, int> ProcessScoreMap; |
| 144 ProcessScoreMap pid_to_oom_score_; | 150 ProcessScoreMap oom_score_map_; |
| 145 base::ProcessHandle focused_tab_pid_; | 151 // Holds the focused tab's child process host id. |
| 152 ProcessInfo focused_tab_process_info_; | |
| 146 | 153 |
| 147 // Observer for the kernel low memory signal. NULL if tab discarding is | 154 // Observer for the kernel low memory signal. NULL if tab discarding is |
| 148 // disabled. | 155 // disabled. |
| 149 scoped_ptr<LowMemoryObserver> low_memory_observer_; | 156 scoped_ptr<LowMemoryObserver> low_memory_observer_; |
| 150 | 157 |
| 151 // Wall-clock time when the priority manager started running. | 158 // Wall-clock time when the priority manager started running. |
| 152 base::TimeTicks start_time_; | 159 base::TimeTicks start_time_; |
| 153 | 160 |
| 154 // Wall-clock time of last tab discard during this browsing session, or 0 if | 161 // Wall-clock time of last tab discard during this browsing session, or 0 if |
| 155 // no discard has happened yet. | 162 // no discard has happened yet. |
| 156 base::TimeTicks last_discard_time_; | 163 base::TimeTicks last_discard_time_; |
| 157 | 164 |
| 158 // Wall-clock time of last priority adjustment, used to correct the above | 165 // Wall-clock time of last priority adjustment, used to correct the above |
| 159 // times for discontinuities caused by suspend/resume. | 166 // times for discontinuities caused by suspend/resume. |
| 160 base::TimeTicks last_adjust_time_; | 167 base::TimeTicks last_adjust_time_; |
| 161 | 168 |
| 162 // Number of times we have discarded a tab, for statistics. | 169 // Number of times we have discarded a tab, for statistics. |
| 163 int discard_count_; | 170 int discard_count_; |
| 164 | 171 |
| 165 // Whether a tab discard event has occurred during the last time interval, | 172 // Whether a tab discard event has occurred during the last time interval, |
| 166 // used for statistics normalized by usage. | 173 // used for statistics normalized by usage. |
| 167 bool recent_tab_discard_; | 174 bool recent_tab_discard_; |
| 168 | 175 |
| 169 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager); | 176 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager); |
| 170 }; | 177 }; |
| 171 | 178 |
| 172 } // namespace chromeos | 179 } // namespace chromeos |
| 173 | 180 |
| 174 #endif // CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ | 181 #endif // CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ |
| OLD | NEW |