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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 const int kTrimMemoryRunningCritical = 15; | 69 const int kTrimMemoryRunningCritical = 15; |
70 | 70 |
71 // Called by JNI. | 71 // Called by JNI. |
72 static void OnTrimMemory(JNIEnv* env, | 72 static void OnTrimMemory(JNIEnv* env, |
73 const base::android::JavaParamRef<jclass>& jcaller, | 73 const base::android::JavaParamRef<jclass>& jcaller, |
74 jint level) { | 74 jint level) { |
75 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax); | 75 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax); |
76 auto* coordinator = MemoryCoordinatorImpl::GetInstance(); | 76 auto* coordinator = MemoryCoordinatorImpl::GetInstance(); |
77 | 77 |
78 if (level >= kTrimMemoryRunningCritical) { | 78 if (level >= kTrimMemoryRunningCritical) { |
79 coordinator->ForceSetGlobalState(base::MemoryState::SUSPENDED, | 79 coordinator->ForceSetMemoryCondition(MemoryCondition::CRITICAL, |
80 base::TimeDelta::FromMinutes(1)); | 80 base::TimeDelta::FromMinutes(1)); |
81 } else if (level >= kTrimMemoryRunningLow) { | 81 } else if (level >= kTrimMemoryRunningLow) { |
82 coordinator->ForceSetGlobalState(base::MemoryState::THROTTLED, | 82 coordinator->ForceSetMemoryCondition(MemoryCondition::WARNING, |
83 base::TimeDelta::FromMinutes(1)); | 83 base::TimeDelta::FromMinutes(1)); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 // static | 87 // static |
88 std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() { | 88 std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() { |
89 auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl); | 89 auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl); |
90 return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate))); | 90 return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate))); |
91 } | 91 } |
92 | 92 |
93 // static | 93 // static |
(...skipping 18 matching lines...) Expand all Loading... |
112 void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) { | 112 void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) { |
113 delegate_->GetMemoryInfo(out); | 113 delegate_->GetMemoryInfo(out); |
114 } | 114 } |
115 | 115 |
116 // Implementation of a factory function defined in memory_monitor.h. | 116 // Implementation of a factory function defined in memory_monitor.h. |
117 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { | 117 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { |
118 return MemoryMonitorAndroid::Create(); | 118 return MemoryMonitorAndroid::Create(); |
119 } | 119 } |
120 | 120 |
121 } // namespace content | 121 } // namespace content |
OLD | NEW |