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

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

Issue 2718963002: Drop the global memory state from memory coordinator (Closed)
Patch Set: tweak Created 3 years, 9 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 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" 10 #include "base/metrics/histogram_macros.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const int kTrimMemoryRunningLow = 10; 69 const int kTrimMemoryRunningLow = 10;
70 const int kTrimMemoryRunningCritical = 15; 70 const int kTrimMemoryRunningCritical = 15;
71 71
72 // Called by JNI. 72 // Called by JNI.
73 static void OnTrimMemory(JNIEnv* env, 73 static void OnTrimMemory(JNIEnv* env,
74 const base::android::JavaParamRef<jclass>& jcaller, 74 const base::android::JavaParamRef<jclass>& jcaller,
75 jint level) { 75 jint level) {
76 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax); 76 DCHECK(level >= 0 && level <= kTrimMemoryLevelMax);
77 auto* coordinator = MemoryCoordinatorImpl::GetInstance(); 77 auto* coordinator = MemoryCoordinatorImpl::GetInstance();
78 78
79 auto state = coordinator->GetGlobalMemoryState(); 79 // TODO(bashi): Update metrics.
80 switch (state) { 80 auto condition = coordinator->GetMemoryCondtion();
81 case base::MemoryState::NORMAL: 81 switch (condition) {
82 case MemoryCondition::NORMAL:
82 UMA_HISTOGRAM_ENUMERATION("Memory.Coordinator.TrimMemoryLevel.Normal", 83 UMA_HISTOGRAM_ENUMERATION("Memory.Coordinator.TrimMemoryLevel.Normal",
83 level, kTrimMemoryLevelMax); 84 level, kTrimMemoryLevelMax);
84 break; 85 break;
85 case base::MemoryState::THROTTLED: 86 case MemoryCondition::WARNING:
86 UMA_HISTOGRAM_ENUMERATION("Memory.Coordinator.TrimMemoryLevel.Throttled", 87 UMA_HISTOGRAM_ENUMERATION("Memory.Coordinator.TrimMemoryLevel.Throttled",
87 level, kTrimMemoryLevelMax); 88 level, kTrimMemoryLevelMax);
88 break; 89 break;
89 case base::MemoryState::SUSPENDED: 90 case MemoryCondition::CRITICAL:
90 UMA_HISTOGRAM_ENUMERATION("Memory.Coordinator.TrimMemoryLevel.Suspended", 91 UMA_HISTOGRAM_ENUMERATION("Memory.Coordinator.TrimMemoryLevel.Suspended",
91 level, kTrimMemoryLevelMax); 92 level, kTrimMemoryLevelMax);
92 break; 93 break;
93 case base::MemoryState::UNKNOWN:
94 NOTREACHED();
95 break;
96 } 94 }
97 95
98 if (level >= kTrimMemoryRunningCritical) { 96 if (level >= kTrimMemoryRunningCritical) {
99 coordinator->ForceSetGlobalState(base::MemoryState::SUSPENDED, 97 coordinator->ForceSetMemoryCondition(MemoryCondition::WARNING,
100 base::TimeDelta::FromMinutes(1)); 98 base::TimeDelta::FromMinutes(1));
101 } else if (level >= kTrimMemoryRunningLow) { 99 } else if (level >= kTrimMemoryRunningLow) {
102 coordinator->ForceSetGlobalState(base::MemoryState::THROTTLED, 100 coordinator->ForceSetMemoryCondition(MemoryCondition::CRITICAL,
103 base::TimeDelta::FromMinutes(1)); 101 base::TimeDelta::FromMinutes(1));
104 } 102 }
105 } 103 }
106 104
107 // static 105 // static
108 std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() { 106 std::unique_ptr<MemoryMonitorAndroid> MemoryMonitorAndroid::Create() {
109 auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl); 107 auto delegate = base::WrapUnique(new MemoryMonitorAndroidDelegateImpl);
110 return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate))); 108 return base::WrapUnique(new MemoryMonitorAndroid(std::move(delegate)));
111 } 109 }
112 110
113 // static 111 // static
(...skipping 18 matching lines...) Expand all
132 void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) { 130 void MemoryMonitorAndroid::GetMemoryInfo(MemoryInfo* out) {
133 delegate_->GetMemoryInfo(out); 131 delegate_->GetMemoryInfo(out);
134 } 132 }
135 133
136 // Implementation of a factory function defined in memory_monitor.h. 134 // Implementation of a factory function defined in memory_monitor.h.
137 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { 135 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() {
138 return MemoryMonitorAndroid::Create(); 136 return MemoryMonitorAndroid::Create();
139 } 137 }
140 138
141 } // namespace content 139 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698