summaryrefslogtreecommitdiffstats
path: root/chrome/browser/oom_priority_manager.h
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-08 21:27:32 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-08 21:27:32 +0000
commit0c94cd09de40bc19cb1be6e1126ae4cd8517bf1b (patch)
tree57142d87ecf332902d26771505c464bcaca790d4 /chrome/browser/oom_priority_manager.h
parent38490fe4bab15170c9179368fa81143b4ab3e0da (diff)
downloadchromium_src-0c94cd09de40bc19cb1be6e1126ae4cd8517bf1b.zip
chromium_src-0c94cd09de40bc19cb1be6e1126ae4cd8517bf1b.tar.gz
chromium_src-0c94cd09de40bc19cb1be6e1126ae4cd8517bf1b.tar.bz2
CrOS - Fix use-after-free in OomPriorityManager on shutdown
OomPriorityManager was being deleted during shutdown while a task was pending on the IO thread. Convert it to a singleton and explicitly start and stop it in the main loop. BUG=chromium-os:18375 TEST=Open 3 tabs and navigate to web pages, wait 10 seconds, then open a tab to "about:discards". It should list 3 tabs and itself. Order is unimportant for now. Also, valgrind less red. Review URL: http://codereview.chromium.org/7859006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100254 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/oom_priority_manager.h')
-rw-r--r--chrome/browser/oom_priority_manager.h49
1 files changed, 42 insertions, 7 deletions
diff --git a/chrome/browser/oom_priority_manager.h b/chrome/browser/oom_priority_manager.h
index a5eeef6..cfa7973 100644
--- a/chrome/browser/oom_priority_manager.h
+++ b/chrome/browser/oom_priority_manager.h
@@ -7,12 +7,16 @@
#include <vector>
+#include "base/memory/singleton.h"
+#include "base/process.h"
#include "base/string16.h"
+#include "base/synchronization/lock.h"
+#include "base/task.h"
+#include "base/time.h"
+#include "base/timer.h"
namespace browser {
-class OomPriorityManagerImpl;
-
// The OomPriorityManager periodically checks (see
// ADJUSTMENT_INTERVAL_SECONDS in the source) the status of renderers
// and adjusts the out of memory (OOM) adjustment value (in
@@ -27,18 +31,49 @@ class OomPriorityManagerImpl;
// them, as no two tabs will have exactly the same idle time.
class OomPriorityManager {
public:
- // We need to explicitly manage our destruction, so don't use Singleton.
- static void Create();
- static void Destroy();
+ static OomPriorityManager* GetInstance();
+
+ void Start();
+ void Stop();
// Returns list of tab titles sorted from most interesting (don't kill)
// to least interesting (OK to kill).
- static std::vector<string16> GetTabTitles();
+ std::vector<string16> GetTabTitles();
private:
- static OomPriorityManagerImpl* impl_;
+ OomPriorityManager();
+ ~OomPriorityManager();
+ friend struct DefaultSingletonTraits<OomPriorityManager>;
+
+ struct RendererStats {
+ bool is_pinned;
+ bool is_selected;
+ base::TimeTicks last_selected;
+ size_t memory_used;
+ base::ProcessHandle renderer_handle;
+ string16 title;
+ };
+ typedef std::vector<RendererStats> StatsList;
+
+ // Posts DoAdjustOomPriorities task to the file thread. Called when
+ // the timer fires.
+ void AdjustOomPriorities();
+
+ // Called by AdjustOomPriorities. Runs on the file thread.
+ void DoAdjustOomPriorities();
+
+ static bool CompareRendererStats(RendererStats first, RendererStats second);
+
+ base::RepeatingTimer<OomPriorityManager> timer_;
+ // renderer_stats_ is used on both UI and file threads.
+ base::Lock renderer_stats_lock_;
+ StatsList renderer_stats_;
+
+ DISALLOW_COPY_AND_ASSIGN(OomPriorityManager);
};
} // namespace browser
+DISABLE_RUNNABLE_METHOD_REFCOUNT(browser::OomPriorityManager);
+
#endif // CHROME_BROWSER_OOM_PRIORITY_MANAGER_H_