| 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 "base/metrics/histogram_macros.h" | |
| 11 #include "content/browser/memory/memory_coordinator_impl.h" | 10 #include "content/browser/memory/memory_coordinator_impl.h" |
| 12 #include "jni/MemoryMonitorAndroid_jni.h" | 11 #include "jni/MemoryMonitorAndroid_jni.h" |
| 13 | 12 |
| 14 namespace content { | 13 namespace content { |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 const size_t kMBShift = 20; | 17 const size_t kMBShift = 20; |
| 19 | 18 |
| 20 void RegisterComponentCallbacks() { | 19 void RegisterComponentCallbacks() { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 const int kTrimMemoryRunningLow = 10; | 68 const int kTrimMemoryRunningLow = 10; |
| 70 const int kTrimMemoryRunningCritical = 15; | 69 const int kTrimMemoryRunningCritical = 15; |
| 71 | 70 |
| 72 // Called by JNI. | 71 // Called by JNI. |
| 73 static void OnTrimMemory(JNIEnv* env, | 72 static void OnTrimMemory(JNIEnv* env, |
| 74 const base::android::JavaParamRef<jclass>& jcaller, | 73 const base::android::JavaParamRef<jclass>& jcaller, |
| 75 jint level) { | 74 jint level) { |
| 76 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax); | 75 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax); |
| 77 auto* coordinator = MemoryCoordinatorImpl::GetInstance(); | 76 auto* coordinator = MemoryCoordinatorImpl::GetInstance(); |
| 78 | 77 |
| 79 auto state = coordinator->GetGlobalMemoryState(); | |
| 80 switch (state) { | |
| 81 case base::MemoryState::NORMAL: | |
| 82 UMA_HISTOGRAM_ENUMERATION("Memory.Coordinator.TrimMemoryLevel.Normal", | |
| 83 level, kTrimMemoryLevelMax); | |
| 84 break; | |
| 85 case base::MemoryState::THROTTLED: | |
| 86 UMA_HISTOGRAM_ENUMERATION("Memory.Coordinator.TrimMemoryLevel.Throttled", | |
| 87 level, kTrimMemoryLevelMax); | |
| 88 break; | |
| 89 case base::MemoryState::SUSPENDED: | |
| 90 UMA_HISTOGRAM_ENUMERATION("Memory.Coordinator.TrimMemoryLevel.Suspended", | |
| 91 level, kTrimMemoryLevelMax); | |
| 92 break; | |
| 93 case base::MemoryState::UNKNOWN: | |
| 94 NOTREACHED(); | |
| 95 break; | |
| 96 } | |
| 97 | |
| 98 if (level >= kTrimMemoryRunningCritical) { | 78 if (level >= kTrimMemoryRunningCritical) { |
| 99 coordinator->ForceSetGlobalState(base::MemoryState::SUSPENDED, | 79 coordinator->ForceSetGlobalState(base::MemoryState::SUSPENDED, |
| 100 base::TimeDelta::FromMinutes(1)); | 80 base::TimeDelta::FromMinutes(1)); |
| 101 } else if (level >= kTrimMemoryRunningLow) { | 81 } else if (level >= kTrimMemoryRunningLow) { |
| 102 coordinator->ForceSetGlobalState(base::MemoryState::THROTTLED, | 82 coordinator->ForceSetGlobalState(base::MemoryState::THROTTLED, |
| 103 base::TimeDelta::FromMinutes(1)); | 83 base::TimeDelta::FromMinutes(1)); |
| 104 } | 84 } |
| 105 } | 85 } |
| 106 | 86 |
| 107 // static | 87 // static |
| (...skipping 24 matching lines...) Expand all Loading... |
| 132 void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) { | 112 void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) { |
| 133 delegate_->GetMemoryInfo(out); | 113 delegate_->GetMemoryInfo(out); |
| 134 } | 114 } |
| 135 | 115 |
| 136 // Implementation of a factory function defined in memory_monitor.h. | 116 // Implementation of a factory function defined in memory_monitor.h. |
| 137 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { | 117 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { |
| 138 return MemoryMonitorAndroid::Create(); | 118 return MemoryMonitorAndroid::Create(); |
| 139 } | 119 } |
| 140 | 120 |
| 141 } // namespace content | 121 } // namespace content |
| OLD | NEW |