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

Unified Diff: content/browser/memory/memory_monitor_android.cc

Issue 2382623002: Add a test for MemoryMonitorAndroid::GetFreeMemoryUntilCriticalMB (Closed)
Patch Set: Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/memory/memory_monitor_android.cc
diff --git a/content/browser/memory/memory_monitor_android.cc b/content/browser/memory/memory_monitor_android.cc
index bbe3352176616d1c22ee170175a6b4a6484083f4..70c1e6dc4ca377cd3080b8545f38a1427a2b184b 100644
--- a/content/browser/memory/memory_monitor_android.cc
+++ b/content/browser/memory/memory_monitor_android.cc
@@ -15,27 +15,20 @@ namespace {
const size_t kMBShift = 20;
}
-// static
-std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() {
- return base::WrapUnique(new MemoryMonitorAndroid);
-}
-
-// static
-bool MemoryMonitorAndroid::Register(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
+// An implementation of MemoryMonitorAndroid::Delegate using the Android APIs.
+class MemoryMonitorAndroidDelegateImpl : public MemoryMonitorAndroid::Delegate {
+ public:
+ MemoryMonitorAndroidDelegateImpl() {}
+ ~MemoryMonitorAndroidDelegateImpl() override {}
-MemoryMonitorAndroid::MemoryMonitorAndroid() {}
+ using MemoryInfo = MemoryMonitorAndroid::MemoryInfo;
+ void GetMemoryInfo(MemoryInfo* out) override;
-MemoryMonitorAndroid::~MemoryMonitorAndroid() {}
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MemoryMonitorAndroidDelegateImpl);
+};
-int MemoryMonitorAndroid::GetFreeMemoryUntilCriticalMB() {
- MemoryInfo info;
- GetMemoryInfo(&info);
- return (info.avail_mem - info.threshold) >> kMBShift;
-}
-
-void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) {
+void MemoryMonitorAndroidDelegateImpl::GetMemoryInfo(MemoryInfo* out) {
DCHECK(out);
JNIEnv* env = base::android::AttachCurrentThread();
Java_MemoryMonitorAndroid_getMemoryInfo(
@@ -61,6 +54,34 @@ static void GetMemoryInfoCallback(
info->total_mem = total_mem;
}
+// static
+std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() {
+ auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl);
+ return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate)));
+}
+
+// static
+bool MemoryMonitorAndroid::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+MemoryMonitorAndroid::MemoryMonitorAndroid(std::unique_ptr<Delegate> delegate)
+ : delegate_(std::move(delegate)) {
+ DCHECK(delegate_.get());
+}
+
+MemoryMonitorAndroid::~MemoryMonitorAndroid() {}
+
+int MemoryMonitorAndroid::GetFreeMemoryUntilCriticalMB() {
+ MemoryInfo info;
+ GetMemoryInfo(&info);
+ return (info.avail_mem - info.threshold) >> kMBShift;
+}
+
+void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) {
+ delegate_->GetMemoryInfo(out);
+}
+
// Implementation of a factory function defined in memory_monitor.h.
std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() {
return MemoryMonitorAndroid::Create();
« no previous file with comments | « content/browser/memory/memory_monitor_android.h ('k') | content/browser/memory/memory_monitor_android_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698