Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: chrome/browser/chromeos/memory/oom_priority_manager.h

Issue 815183002: Using the new MemoryPressureListener instead of the LowMemoryObserver when the enhanced memory mana… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/memory_pressure_listener.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/process/process.h" 16 #include "base/process/process.h"
16 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
17 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "base/timer/timer.h" 20 #include "base/timer/timer.h"
20 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
22 23
23 class GURL; 24 class GURL;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 132
132 // Sets the score of the focused tab to the least value. 133 // Sets the score of the focused tab to the least value.
133 void AdjustFocusedTabScoreOnFileThread(); 134 void AdjustFocusedTabScoreOnFileThread();
134 135
135 static bool CompareTabStats(TabStats first, TabStats second); 136 static bool CompareTabStats(TabStats first, TabStats second);
136 137
137 virtual void Observe(int type, 138 virtual void Observe(int type,
138 const content::NotificationSource& source, 139 const content::NotificationSource& source,
139 const content::NotificationDetails& details) override; 140 const content::NotificationDetails& details) override;
140 141
142 // Called by the memory pressure listener when the memory pressure rises.
143 void OnMemoryPressure(
144 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
145
141 base::RepeatingTimer<OomPriorityManager> timer_; 146 base::RepeatingTimer<OomPriorityManager> timer_;
142 base::OneShotTimer<OomPriorityManager> focus_tab_score_adjust_timer_; 147 base::OneShotTimer<OomPriorityManager> focus_tab_score_adjust_timer_;
143 base::RepeatingTimer<OomPriorityManager> recent_tab_discard_timer_; 148 base::RepeatingTimer<OomPriorityManager> recent_tab_discard_timer_;
144 content::NotificationRegistrar registrar_; 149 content::NotificationRegistrar registrar_;
145 150
146 // This lock is for |oom_score_map_| and |focused_tab_process_info_|. 151 // This lock is for |oom_score_map_| and |focused_tab_process_info_|.
147 base::Lock oom_score_lock_; 152 base::Lock oom_score_lock_;
148 // Map maintaining the child process host id - oom_score mapping. 153 // Map maintaining the child process host id - oom_score mapping.
149 typedef base::hash_map<int, int> ProcessScoreMap; 154 typedef base::hash_map<int, int> ProcessScoreMap;
150 ProcessScoreMap oom_score_map_; 155 ProcessScoreMap oom_score_map_;
151 // Holds the focused tab's child process host id. 156 // Holds the focused tab's child process host id.
152 ProcessInfo focused_tab_process_info_; 157 ProcessInfo focused_tab_process_info_;
153 158
154 // Observer for the kernel low memory signal. NULL if tab discarding is 159 // The old observer for the kernel low memory signal. This is null if
155 // disabled. 160 // the new MemoryPressureListener is used.
161 // TODO(skuhne): Remove this when the enhanced memory observer is turned on
162 // by default.
156 scoped_ptr<LowMemoryObserver> low_memory_observer_; 163 scoped_ptr<LowMemoryObserver> low_memory_observer_;
157 164
165 // A listener to global memory pressure events. This will be used if the
166 // memory pressure system was instantiated - otherwise the LowMemoryObserver
167 // will be used.
168 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_;
169
158 // Wall-clock time when the priority manager started running. 170 // Wall-clock time when the priority manager started running.
159 base::TimeTicks start_time_; 171 base::TimeTicks start_time_;
160 172
161 // Wall-clock time of last tab discard during this browsing session, or 0 if 173 // Wall-clock time of last tab discard during this browsing session, or 0 if
162 // no discard has happened yet. 174 // no discard has happened yet.
163 base::TimeTicks last_discard_time_; 175 base::TimeTicks last_discard_time_;
164 176
165 // Wall-clock time of last priority adjustment, used to correct the above 177 // Wall-clock time of last priority adjustment, used to correct the above
166 // times for discontinuities caused by suspend/resume. 178 // times for discontinuities caused by suspend/resume.
167 base::TimeTicks last_adjust_time_; 179 base::TimeTicks last_adjust_time_;
168 180
169 // Number of times we have discarded a tab, for statistics. 181 // Number of times we have discarded a tab, for statistics.
170 int discard_count_; 182 int discard_count_;
171 183
172 // Whether a tab discard event has occurred during the last time interval, 184 // Whether a tab discard event has occurred during the last time interval,
173 // used for statistics normalized by usage. 185 // used for statistics normalized by usage.
174 bool recent_tab_discard_; 186 bool recent_tab_discard_;
175 187
176 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager); 188 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager);
177 }; 189 };
178 190
179 } // namespace chromeos 191 } // namespace chromeos
180 192
181 #endif // CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ 193 #endif // CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698