| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "content/browser/memory/memory_monitor_android.h" | 5 #include "content/browser/memory/memory_monitor_android.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "content/browser/memory/memory_coordinator_impl.h" | 10 #include "content/browser/memory/memory_coordinator_impl.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 MemoryMonitorAndroid::MemoryInfo* info = | 58 MemoryMonitorAndroid::MemoryInfo* info = |
| 59 reinterpret_cast<MemoryMonitorAndroid::MemoryInfo*>(out_ptr); | 59 reinterpret_cast<MemoryMonitorAndroid::MemoryInfo*>(out_ptr); |
| 60 info->avail_mem = avail_mem; | 60 info->avail_mem = avail_mem; |
| 61 info->low_memory = low_memory; | 61 info->low_memory = low_memory; |
| 62 info->threshold = threshold; | 62 info->threshold = threshold; |
| 63 info->total_mem = total_mem; | 63 info->total_mem = total_mem; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // The maximum level of onTrimMemory (TRIM_MEMORY_COMPLETE). | 66 // The maximum level of onTrimMemory (TRIM_MEMORY_COMPLETE). |
| 67 const int kTrimMemoryLevelMax = 80; | 67 const int kTrimMemoryLevelMax = 80; |
| 68 const int kTrimMemoryRunningLow = 10; | |
| 69 const int kTrimMemoryRunningCritical = 15; | 68 const int kTrimMemoryRunningCritical = 15; |
| 70 | 69 |
| 71 // Called by JNI. | 70 // Called by JNI. |
| 72 static void OnTrimMemory(JNIEnv* env, | 71 static void OnTrimMemory(JNIEnv* env, |
| 73 const base::android::JavaParamRef<jclass>& jcaller, | 72 const base::android::JavaParamRef<jclass>& jcaller, |
| 74 jint level) { | 73 jint level) { |
| 75 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax); | 74 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax); |
| 76 auto* coordinator = MemoryCoordinatorImpl::GetInstance(); | 75 auto* coordinator = MemoryCoordinatorImpl::GetInstance(); |
| 76 DCHECK(coordinator); |
| 77 | 77 |
| 78 if (level >= kTrimMemoryRunningCritical) { | 78 MemoryCondition condition = MemoryCondition::WARNING; |
| 79 coordinator->ForceSetMemoryCondition(MemoryCondition::CRITICAL, | 79 if (level >= kTrimMemoryRunningCritical || |
| 80 base::TimeDelta::FromMinutes(1)); | 80 coordinator->GetMemoryCondition() == MemoryCondition::CRITICAL) |
| 81 } else if (level >= kTrimMemoryRunningLow) { | 81 condition = MemoryCondition::CRITICAL; |
| 82 coordinator->ForceSetMemoryCondition(MemoryCondition::WARNING, | 82 coordinator->ForceSetMemoryCondition(condition, |
| 83 base::TimeDelta::FromMinutes(1)); | 83 base::TimeDelta::FromMinutes(1)); |
| 84 } | |
| 85 } | 84 } |
| 86 | 85 |
| 87 // static | 86 // static |
| 88 std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() { | 87 std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() { |
| 89 auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl); | 88 auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl); |
| 90 return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate))); | 89 return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate))); |
| 91 } | 90 } |
| 92 | 91 |
| 93 // static | 92 // static |
| 94 bool MemoryMonitorAndroid::Register(JNIEnv* env) { | 93 bool MemoryMonitorAndroid::Register(JNIEnv* env) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 coordinator->OnBackgrounded(); | 128 coordinator->OnBackgrounded(); |
| 130 } | 129 } |
| 131 } | 130 } |
| 132 | 131 |
| 133 // Implementation of a factory function defined in memory_monitor.h. | 132 // Implementation of a factory function defined in memory_monitor.h. |
| 134 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { | 133 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { |
| 135 return MemoryMonitorAndroid::Create(); | 134 return MemoryMonitorAndroid::Create(); |
| 136 } | 135 } |
| 137 | 136 |
| 138 } // namespace content | 137 } // namespace content |
| OLD | NEW |