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 24 matching lines...) Expand all Loading... |
35 // The algorithm used favors killing tabs that are not selected, not pinned, | 35 // The algorithm used favors killing tabs that are not selected, not pinned, |
36 // and have been idle for longest, in that order of priority. | 36 // and have been idle for longest, in that order of priority. |
37 class OomPriorityManager : public content::NotificationObserver { | 37 class OomPriorityManager : public content::NotificationObserver { |
38 public: | 38 public: |
39 OomPriorityManager(); | 39 OomPriorityManager(); |
40 virtual ~OomPriorityManager(); | 40 virtual ~OomPriorityManager(); |
41 | 41 |
42 // Number of discard events since Chrome started. | 42 // Number of discard events since Chrome started. |
43 int discard_count() const { return discard_count_; } | 43 int discard_count() const { return discard_count_; } |
44 | 44 |
| 45 // See member comment. |
| 46 bool recent_tab_discard() const { return recent_tab_discard_; } |
| 47 |
45 void Start(); | 48 void Start(); |
46 void Stop(); | 49 void Stop(); |
47 | 50 |
48 // Returns list of tab titles sorted from most interesting (don't kill) | 51 // Returns list of tab titles sorted from most interesting (don't kill) |
49 // to least interesting (OK to kill). | 52 // to least interesting (OK to kill). |
50 std::vector<string16> GetTabTitles(); | 53 std::vector<string16> GetTabTitles(); |
51 | 54 |
52 // Discards a tab to free the memory occupied by its renderer. | 55 // Discards a tab to free the memory occupied by its renderer. |
53 // Tab still exists in the tab-strip; clicking on it will reload it. | 56 // Tab still exists in the tab-strip; clicking on it will reload it. |
54 // Returns true if it successfully found a tab and discarded it. | 57 // Returns true if it successfully found a tab and discarded it. |
(...skipping 29 matching lines...) Expand all Loading... |
84 static bool IsReloadableUI(const GURL& url); | 87 static bool IsReloadableUI(const GURL& url); |
85 | 88 |
86 // Discards a tab with the given unique ID. Returns true if discard occurred. | 89 // Discards a tab with the given unique ID. Returns true if discard occurred. |
87 bool DiscardTabById(int64 target_web_contents_id); | 90 bool DiscardTabById(int64 target_web_contents_id); |
88 | 91 |
89 // Records UMA histogram statistics for a tab discard. We record statistics | 92 // Records UMA histogram statistics for a tab discard. We record statistics |
90 // for user triggered discards via chrome://discards/ because that allows us | 93 // for user triggered discards via chrome://discards/ because that allows us |
91 // to manually test the system. | 94 // to manually test the system. |
92 void RecordDiscardStatistics(); | 95 void RecordDiscardStatistics(); |
93 | 96 |
| 97 // Record whether we ran out of memory during a recent time interval. |
| 98 // This allows us to normalize low memory statistics versus usage. |
| 99 void RecordRecentTabDiscard(); |
| 100 |
94 // Purges data structures in the browser that can be easily recomputed. | 101 // Purges data structures in the browser that can be easily recomputed. |
95 void PurgeBrowserMemory(); | 102 void PurgeBrowserMemory(); |
96 | 103 |
97 // Returns the number of tabs open in all browser instances. | 104 // Returns the number of tabs open in all browser instances. |
98 int GetTabCount() const; | 105 int GetTabCount() const; |
99 | 106 |
100 TabStatsList GetTabStatsOnUIThread(); | 107 TabStatsList GetTabStatsOnUIThread(); |
101 | 108 |
102 // Called when the timer fires, sets oom_adjust_score for all renderers. | 109 // Called when the timer fires, sets oom_adjust_score for all renderers. |
103 void AdjustOomPriorities(); | 110 void AdjustOomPriorities(); |
104 | 111 |
105 // Called by AdjustOomPriorities. | 112 // Called by AdjustOomPriorities. |
106 void AdjustOomPrioritiesOnFileThread(TabStatsList stats_list); | 113 void AdjustOomPrioritiesOnFileThread(TabStatsList stats_list); |
107 | 114 |
108 // Posts AdjustFocusedTabScore task to the file thread. | 115 // Posts AdjustFocusedTabScore task to the file thread. |
109 void OnFocusTabScoreAdjustmentTimeout(); | 116 void OnFocusTabScoreAdjustmentTimeout(); |
110 | 117 |
111 // Sets the score of the focused tab to the least value. | 118 // Sets the score of the focused tab to the least value. |
112 void AdjustFocusedTabScoreOnFileThread(); | 119 void AdjustFocusedTabScoreOnFileThread(); |
113 | 120 |
114 static bool CompareTabStats(TabStats first, TabStats second); | 121 static bool CompareTabStats(TabStats first, TabStats second); |
115 | 122 |
116 virtual void Observe(int type, | 123 virtual void Observe(int type, |
117 const content::NotificationSource& source, | 124 const content::NotificationSource& source, |
118 const content::NotificationDetails& details) OVERRIDE; | 125 const content::NotificationDetails& details) OVERRIDE; |
119 | 126 |
120 base::RepeatingTimer<OomPriorityManager> timer_; | 127 base::RepeatingTimer<OomPriorityManager> timer_; |
121 base::OneShotTimer<OomPriorityManager> focus_tab_score_adjust_timer_; | 128 base::OneShotTimer<OomPriorityManager> focus_tab_score_adjust_timer_; |
| 129 base::RepeatingTimer<OomPriorityManager> recent_tab_discard_timer_; |
122 content::NotificationRegistrar registrar_; | 130 content::NotificationRegistrar registrar_; |
123 | 131 |
124 // This lock is for pid_to_oom_score_ and focus_tab_pid_. | 132 // This lock is for pid_to_oom_score_ and focus_tab_pid_. |
125 base::Lock pid_to_oom_score_lock_; | 133 base::Lock pid_to_oom_score_lock_; |
126 // map maintaining the process - oom_score mapping. | 134 // map maintaining the process - oom_score mapping. |
127 typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap; | 135 typedef base::hash_map<base::ProcessHandle, int> ProcessScoreMap; |
128 ProcessScoreMap pid_to_oom_score_; | 136 ProcessScoreMap pid_to_oom_score_; |
129 base::ProcessHandle focused_tab_pid_; | 137 base::ProcessHandle focused_tab_pid_; |
130 | 138 |
131 // Observer for the kernel low memory signal. NULL if tab discarding is | 139 // Observer for the kernel low memory signal. NULL if tab discarding is |
132 // disabled. | 140 // disabled. |
133 scoped_ptr<LowMemoryObserver> low_memory_observer_; | 141 scoped_ptr<LowMemoryObserver> low_memory_observer_; |
134 | 142 |
135 // Wall-clock time when the priority manager started running. | 143 // Wall-clock time when the priority manager started running. |
136 base::TimeTicks start_time_; | 144 base::TimeTicks start_time_; |
137 | 145 |
138 // Wall-clock time of last tab discard during this browsing session, or 0 if | 146 // Wall-clock time of last tab discard during this browsing session, or 0 if |
139 // no discard has happened yet. | 147 // no discard has happened yet. |
140 base::TimeTicks last_discard_time_; | 148 base::TimeTicks last_discard_time_; |
141 | 149 |
142 // Wall-clock time of last priority adjustment, used to correct the above | 150 // Wall-clock time of last priority adjustment, used to correct the above |
143 // times for discontinuities caused by suspend/resume. | 151 // times for discontinuities caused by suspend/resume. |
144 base::TimeTicks last_adjust_time_; | 152 base::TimeTicks last_adjust_time_; |
145 | 153 |
146 // Number of times we have discarded a tab, for statistics. | 154 // Number of times we have discarded a tab, for statistics. |
147 int discard_count_; | 155 int discard_count_; |
148 | 156 |
| 157 // Whether a tab discard event has occurred during the last time interval, |
| 158 // used for statistics normalized by usage. |
| 159 bool recent_tab_discard_; |
| 160 |
149 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager); | 161 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager); |
150 }; | 162 }; |
151 | 163 |
152 } // namespace chrome | 164 } // namespace chrome |
153 | 165 |
154 #endif // CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ | 166 #endif // CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ |
OLD | NEW |