Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: content/browser/memory/memory_monitor_android.h

Issue 2340293003: Add MemoryMonitorAndroid (Closed)
Patch Set: Use native callback instead of returning MemoryInfo Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 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);
20
19 // C++ counter-part of ActivityManager.MemoryInfo 21 // C++ counter-part of ActivityManager.MemoryInfo
20 struct MemoryInfo { 22 struct MemoryInfo {
21 long avail_mem; 23 jlong avail_mem;
22 bool low_memory; 24 jboolean low_memory;
23 long threshold; 25 jlong threshold;
24 long total_mem; 26 jlong total_mem;
25 }; 27 };
26 28
27 ~MemoryMonitorAndroid() override; 29 ~MemoryMonitorAndroid() override;
28 30
29 // MemoryMonitor implementation: 31 // MemoryMonitor implementation:
30 int GetFreeMemoryUntilCriticalMB() override; 32 int GetFreeMemoryUntilCriticalMB() override;
31 33
32 // Returns true when this class can get memory info from the Android system.
33 bool CanGetMemoryInfo();
34 // Get memory info from the Android system. 34 // Get memory info from the Android system.
35 void GetMemoryInfo(MemoryInfo* out); 35 void GetMemoryInfo(MemoryInfo* out);
36 36
37 private: 37 private:
38 MemoryMonitorAndroid(); 38 MemoryMonitorAndroid();
39 39
40 // Initializes field IDs of ActivityManager.MemoryInfo
41 void InitializeFieldIDs();
42
43 // Field IDs for ActivityManager.MemoryInfo
44 jfieldID avail_mem_id_ = 0;
45 jfieldID low_memory_id_ = 0;
46 jfieldID threshold_id_ = 0;
47 jfieldID total_mem_id_ = 0;
48
49 DISALLOW_COPY_AND_ASSIGN(MemoryMonitorAndroid); 40 DISALLOW_COPY_AND_ASSIGN(MemoryMonitorAndroid);
50 }; 41 };
51 42
52 } // namespace content 43 } // namespace content
53 44
54 #endif // CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_ANDROID_H_ 45 #endif // CONTENT_BROWSER_MEMORY_MEMORY_MONITOR_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698