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