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 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_ANDROID_H_ |
6 #define CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_ANDROID_H_ | 6 #define CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include "content/browser/memory/memory_monitor.h" | 10 #include "content/browser/memory/memory_monitor.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 // A memory monitor for the Android system. | 14 // A memory monitor for the Android system. |
15 class CONTENT_EXPORT MemoryMonitorAndroid : public MemoryMonitor { | 15 class CONTENT_EXPORT MemoryMonitorAndroid : public MemoryMonitor { |
16 public: | 16 public: |
17 static std::unique_ptr<MemoryMonitorAndroid> Create(); | 17 static std::unique_ptr<MemoryMonitorAndroid> Create(); |
18 | 18 |
19 static bool Register(JNIEnv* env); | 19 static bool Register(JNIEnv* env); |
20 | 20 |
21 // C++ counter-part of ActivityManager.MemoryInfo | 21 // C++ counter-part of ActivityManager.MemoryInfo |
22 struct MemoryInfo { | 22 struct MemoryInfo { |
23 jlong avail_mem; | 23 jlong avail_mem; |
24 jboolean low_memory; | 24 jboolean low_memory; |
25 jlong threshold; | 25 jlong threshold; |
26 jlong total_mem; | 26 jlong total_mem; |
27 }; | 27 }; |
28 | 28 |
| 29 // Delegate interface used by MemoryMonitorAndroid. |
| 30 class Delegate { |
| 31 public: |
| 32 Delegate() {} |
| 33 virtual ~Delegate() {}; |
| 34 |
| 35 // Get MemoryInfo. Implementations should fill |out| accordingly. |
| 36 virtual void GetMemoryInfo(MemoryInfo* out) = 0; |
| 37 }; |
| 38 |
| 39 MemoryMonitorAndroid(std::unique_ptr<Delegate> delegate); |
29 ~MemoryMonitorAndroid() override; | 40 ~MemoryMonitorAndroid() override; |
30 | 41 |
31 // MemoryMonitor implementation: | 42 // MemoryMonitor implementation: |
32 int GetFreeMemoryUntilCriticalMB() override; | 43 int GetFreeMemoryUntilCriticalMB() override; |
33 | 44 |
34 // Get memory info from the Android system. | 45 // Get memory info from the Android system. |
35 void GetMemoryInfo(MemoryInfo* out); | 46 void GetMemoryInfo(MemoryInfo* out); |
36 | 47 |
| 48 Delegate* delegate() { return delegate_.get(); } |
| 49 |
37 private: | 50 private: |
38 MemoryMonitorAndroid(); | 51 std::unique_ptr<Delegate> delegate_; |
39 | 52 |
40 DISALLOW_COPY_AND_ASSIGN(MemoryMonitorAndroid); | 53 DISALLOW_COPY_AND_ASSIGN(MemoryMonitorAndroid); |
41 }; | 54 }; |
42 | 55 |
43 } // namespace content | 56 } // namespace content |
44 | 57 |
45 #endif // CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_ANDROID_H_ | 58 #endif // CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_ANDROID_H_ |
OLD | NEW |