#include "base/synchronization/lock.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
-#include "chromeos/memory/low_memory_listener_delegate.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
namespace chromeos {
-class LowMemoryListener;
+class LowMemoryObserver;
// The OomPriorityManager periodically checks (see
// ADJUSTMENT_INTERVAL_SECONDS in the source) the status of renderers
//
// The algorithm used favors killing tabs that are not selected, not pinned,
// and have been idle for longest, in that order of priority.
-class OomPriorityManager : public content::NotificationObserver,
- public LowMemoryListenerDelegate {
+class OomPriorityManager : public content::NotificationObserver {
public:
OomPriorityManager();
virtual ~OomPriorityManager();
friend class OomMemoryDetails;
FRIEND_TEST_ALL_PREFIXES(OomPriorityManagerTest, Comparator);
FRIEND_TEST_ALL_PREFIXES(OomPriorityManagerTest, IsReloadableUI);
+ FRIEND_TEST_ALL_PREFIXES(OomPriorityManagerTest, GetProcessHandles);
struct TabStats {
TabStats();
// Called when the timer fires, sets oom_adjust_score for all renderers.
void AdjustOomPriorities();
+ // Returns a list of unique process handles from |stats_list|. If multiple
+ // tabs use the same process, returns the first process handle. This implies
+ // that the processes are selected based on their "most important" tab.
+ static std::vector<base::ProcessHandle> GetProcessHandles(
+ const TabStatsList& stats_list);
+
// Called by AdjustOomPriorities.
void AdjustOomPrioritiesOnFileThread(TabStatsList stats_list);
static bool CompareTabStats(TabStats first, TabStats second);
- // NotificationObserver overrides:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // LowMemoryListenerDelegate overrides:
- virtual void OnMemoryLow() OVERRIDE;
-
base::RepeatingTimer<OomPriorityManager> timer_;
base::OneShotTimer<OomPriorityManager> focus_tab_score_adjust_timer_;
base::RepeatingTimer<OomPriorityManager> recent_tab_discard_timer_;
ProcessScoreMap pid_to_oom_score_;
base::ProcessHandle focused_tab_pid_;
- // Observer for the kernel low memory signal.
- scoped_ptr<LowMemoryListener> low_memory_listener_;
+ // Observer for the kernel low memory signal. NULL if tab discarding is
+ // disabled.
+ scoped_ptr<LowMemoryObserver> low_memory_observer_;
// Wall-clock time when the priority manager started running.
base::TimeTicks start_time_;