| 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/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "content/browser/memory/memory_coordinator_impl.h" | 9 #include "content/browser/memory/memory_coordinator_impl.h" |
| 10 #include "jni/MemoryMonitorAndroid_jni.h" | 10 #include "jni/MemoryMonitorAndroid_jni.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 const int kTrimMemoryRunningCritical = 15; | 64 const int kTrimMemoryRunningCritical = 15; |
| 65 | 65 |
| 66 // Called by JNI. | 66 // Called by JNI. |
| 67 static void OnTrimMemory(JNIEnv* env, | 67 static void OnTrimMemory(JNIEnv* env, |
| 68 const base::android::JavaParamRef<jclass>& jcaller, | 68 const base::android::JavaParamRef<jclass>& jcaller, |
| 69 jint level) { | 69 jint level) { |
| 70 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax); | 70 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax); |
| 71 auto* coordinator = MemoryCoordinatorImpl::GetInstance(); | 71 auto* coordinator = MemoryCoordinatorImpl::GetInstance(); |
| 72 DCHECK(coordinator); | 72 DCHECK(coordinator); |
| 73 | 73 |
| 74 MemoryCondition condition = MemoryCondition::WARNING; | 74 if (level >= kTrimMemoryRunningCritical) { |
| 75 if (level >= kTrimMemoryRunningCritical || | 75 coordinator->ForceSetMemoryCondition(MemoryCondition::CRITICAL, |
| 76 coordinator->GetMemoryCondition() == MemoryCondition::CRITICAL) | 76 base::TimeDelta::FromMinutes(1)); |
| 77 condition = MemoryCondition::CRITICAL; | 77 } |
| 78 coordinator->ForceSetMemoryCondition(condition, | |
| 79 base::TimeDelta::FromMinutes(1)); | |
| 80 } | 78 } |
| 81 | 79 |
| 82 // static | 80 // static |
| 83 std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() { | 81 std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() { |
| 84 auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl); | 82 auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl); |
| 85 return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate))); | 83 return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate))); |
| 86 } | 84 } |
| 87 | 85 |
| 88 // static | 86 // static |
| 89 bool MemoryMonitorAndroid::Register(JNIEnv* env) { | 87 bool MemoryMonitorAndroid::Register(JNIEnv* env) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 coordinator->OnBackgrounded(); | 122 coordinator->OnBackgrounded(); |
| 125 } | 123 } |
| 126 } | 124 } |
| 127 | 125 |
| 128 // Implementation of a factory function defined in memory_monitor.h. | 126 // Implementation of a factory function defined in memory_monitor.h. |
| 129 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { | 127 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { |
| 130 return MemoryMonitorAndroid::Create(); | 128 return MemoryMonitorAndroid::Create(); |
| 131 } | 129 } |
| 132 | 130 |
| 133 } // namespace content | 131 } // namespace content |
| OLD | NEW |