Commit 87f6aa1c authored by dmichael's avatar dmichael Committed by Commit bot

Introduce base::MemoryPressureMonitor

This is a step towards unifying the various ways to "notify"
MemoryPressureListeners.

This also provides "GetCurrentPressureLevel" to a more general-purpose
place so we'll be able to use it on other platforms.
(Especially Windows, so we can use it in renderer_frame_manager).

See:
https://docs.google.com/a/chromium.org/document/d/1z3SR3JfKOwVaZxrsfHLOrPjo4-IVtnijaX86LKYPEQs/edit#
for more on the rationale and design, and
https://codereview.chromium.org/1045433002/
for what this might look like for ChromeOS's memory
monitor.

BUG=463546

Review URL: https://codereview.chromium.org/1048983006

Cr-Commit-Position: refs/heads/master@{#324086}
parent c3dfc5b5
...@@ -329,6 +329,8 @@ ...@@ -329,6 +329,8 @@
'memory/manual_constructor.h', 'memory/manual_constructor.h',
'memory/memory_pressure_listener.cc', 'memory/memory_pressure_listener.cc',
'memory/memory_pressure_listener.h', 'memory/memory_pressure_listener.h',
'memory/memory_pressure_monitor.cc',
'memory/memory_pressure_monitor.h',
'memory/raw_scoped_refptr_mismatch_checker.h', 'memory/raw_scoped_refptr_mismatch_checker.h',
'memory/ref_counted.cc', 'memory/ref_counted.cc',
'memory/ref_counted.h', 'memory/ref_counted.h',
......
...@@ -16,6 +16,8 @@ source_set("memory") { ...@@ -16,6 +16,8 @@ source_set("memory") {
"manual_constructor.h", "manual_constructor.h",
"memory_pressure_listener.cc", "memory_pressure_listener.cc",
"memory_pressure_listener.h", "memory_pressure_listener.h",
"memory_pressure_monitor.cc",
"memory_pressure_monitor.h",
"raw_scoped_refptr_mismatch_checker.h", "raw_scoped_refptr_mismatch_checker.h",
"ref_counted.cc", "ref_counted.cc",
"ref_counted.h", "ref_counted.h",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/memory_pressure_monitor.h"
#include "base/logging.h"
namespace base {
namespace {
MemoryPressureMonitor* g_monitor = nullptr;
} // namespace
MemoryPressureMonitor::MemoryPressureMonitor() {
DCHECK(!g_monitor);
g_monitor = this;
}
MemoryPressureMonitor::~MemoryPressureMonitor() {
DCHECK(g_monitor);
g_monitor = nullptr;
}
// static
MemoryPressureMonitor* MemoryPressureMonitor::Get() {
return g_monitor;
}
} // namespace base
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_
#define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_
#include "base/base_export.h"
#include "base/memory/memory_pressure_listener.h"
namespace base {
// Declares the interface for a MemoryPressureMonitor. There are multiple
// OS specific implementations of this class. An instance of the memory
// pressure observer is created at the process level, tracks memory usage, and
// pushes memory state change notifications to the static function
// base::MemoryPressureListener::NotifyMemoryPressure. This is turn notifies
// all MemoryPressureListener instances via a callback.
class BASE_EXPORT MemoryPressureMonitor {
public:
using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel;
// Return the singleton MemoryPressureMonitor.
static MemoryPressureMonitor* Get();
// Returns the currently observed memory pressure.
virtual MemoryPressureLevel GetCurrentPressureLevel() const = 0;
protected:
MemoryPressureMonitor();
virtual ~MemoryPressureMonitor();
private:
DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor);
};
} // namespace base
#endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment