| 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" | |
| 8 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 9 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 10 #include "content/browser/memory/memory_coordinator_impl.h" | 9 #include "content/browser/memory/memory_coordinator_impl.h" |
| 11 #include "jni/MemoryMonitorAndroid_jni.h" | 10 #include "jni/MemoryMonitorAndroid_jni.h" |
| 12 | 11 |
| 13 namespace content { | 12 namespace content { |
| 14 | 13 |
| 15 namespace { | 14 namespace { |
| 16 | 15 |
| 17 const size_t kMBShift = 20; | 16 const size_t kMBShift = 20; |
| 18 | 17 |
| 19 void RegisterComponentCallbacks() { | 18 void RegisterComponentCallbacks() { |
| 20 Java_MemoryMonitorAndroid_registerComponentCallbacks( | 19 Java_MemoryMonitorAndroid_registerComponentCallbacks( |
| 21 base::android::AttachCurrentThread(), | 20 base::android::AttachCurrentThread()); |
| 22 base::android::GetApplicationContext()); | |
| 23 } | 21 } |
| 24 | 22 |
| 25 } | 23 } |
| 26 | 24 |
| 27 // An implementation of MemoryMonitorAndroid::Delegate using the Android APIs. | 25 // An implementation of MemoryMonitorAndroid::Delegate using the Android APIs. |
| 28 class MemoryMonitorAndroidDelegateImpl : public MemoryMonitorAndroid::Delegate { | 26 class MemoryMonitorAndroidDelegateImpl : public MemoryMonitorAndroid::Delegate { |
| 29 public: | 27 public: |
| 30 MemoryMonitorAndroidDelegateImpl() {} | 28 MemoryMonitorAndroidDelegateImpl() {} |
| 31 ~MemoryMonitorAndroidDelegateImpl() override {} | 29 ~MemoryMonitorAndroidDelegateImpl() override {} |
| 32 | 30 |
| 33 using MemoryInfo = MemoryMonitorAndroid::MemoryInfo; | 31 using MemoryInfo = MemoryMonitorAndroid::MemoryInfo; |
| 34 void GetMemoryInfo(MemoryInfo* out) override; | 32 void GetMemoryInfo(MemoryInfo* out) override; |
| 35 | 33 |
| 36 private: | 34 private: |
| 37 DISALLOW_COPY_AND_ASSIGN(MemoryMonitorAndroidDelegateImpl); | 35 DISALLOW_COPY_AND_ASSIGN(MemoryMonitorAndroidDelegateImpl); |
| 38 }; | 36 }; |
| 39 | 37 |
| 40 void MemoryMonitorAndroidDelegateImpl::GetMemoryInfo(MemoryInfo* out) { | 38 void MemoryMonitorAndroidDelegateImpl::GetMemoryInfo(MemoryInfo* out) { |
| 41 DCHECK(out); | 39 DCHECK(out); |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); | 40 JNIEnv* env = base::android::AttachCurrentThread(); |
| 43 Java_MemoryMonitorAndroid_getMemoryInfo( | 41 Java_MemoryMonitorAndroid_getMemoryInfo(env, reinterpret_cast<intptr_t>(out)); |
| 44 env, base::android::GetApplicationContext(), | |
| 45 reinterpret_cast<intptr_t>(out)); | |
| 46 } | 42 } |
| 47 | 43 |
| 48 // Called by JNI to populate ActivityManager.MemoryInfo. | 44 // Called by JNI to populate ActivityManager.MemoryInfo. |
| 49 static void GetMemoryInfoCallback( | 45 static void GetMemoryInfoCallback( |
| 50 JNIEnv* env, | 46 JNIEnv* env, |
| 51 const base::android::JavaParamRef<jclass>& clazz, | 47 const base::android::JavaParamRef<jclass>& clazz, |
| 52 jlong avail_mem, | 48 jlong avail_mem, |
| 53 jboolean low_memory, | 49 jboolean low_memory, |
| 54 jlong threshold, | 50 jlong threshold, |
| 55 jlong total_mem, | 51 jlong total_mem, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 coordinator->OnBackgrounded(); | 124 coordinator->OnBackgrounded(); |
| 129 } | 125 } |
| 130 } | 126 } |
| 131 | 127 |
| 132 // Implementation of a factory function defined in memory_monitor.h. | 128 // Implementation of a factory function defined in memory_monitor.h. |
| 133 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { | 129 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { |
| 134 return MemoryMonitorAndroid::Create(); | 130 return MemoryMonitorAndroid::Create(); |
| 135 } | 131 } |
| 136 | 132 |
| 137 } // namespace content | 133 } // namespace content |
| OLD | NEW |