| 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_coordinator.h" | 5 #include "content/browser/memory/memory_coordinator.h" |
| 6 | 6 |
| 7 #include "base/memory/memory_coordinator_client_registry.h" | 7 #include "base/memory/memory_coordinator_client_registry.h" |
| 8 #include "base/metrics/histogram_macros.h" |
| 8 #include "content/public/browser/content_browser_client.h" | 9 #include "content/public/browser/content_browser_client.h" |
| 9 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/common/content_client.h" | 11 #include "content/public/common/content_client.h" |
| 11 #include "content/public/common/content_features.h" | 12 #include "content/public/common/content_features.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 15 // The implementation of MemoryCoordinatorHandle. See memory_coordinator.mojom | 16 // The implementation of MemoryCoordinatorHandle. See memory_coordinator.mojom |
| 16 // for the role of this class. | 17 // for the role of this class. |
| 17 class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle { | 18 class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 114 } |
| 114 | 115 |
| 115 mojom::MemoryState MemoryCoordinator::GetMemoryState( | 116 mojom::MemoryState MemoryCoordinator::GetMemoryState( |
| 116 int render_process_id) const { | 117 int render_process_id) const { |
| 117 auto iter = children_.find(render_process_id); | 118 auto iter = children_.find(render_process_id); |
| 118 if (iter == children_.end()) | 119 if (iter == children_.end()) |
| 119 return mojom::MemoryState::UNKNOWN; | 120 return mojom::MemoryState::UNKNOWN; |
| 120 return iter->second.memory_state; | 121 return iter->second.memory_state; |
| 121 } | 122 } |
| 122 | 123 |
| 124 void MemoryCoordinator::RecordMemoryPressure( |
| 125 base::MemoryPressureMonitor::MemoryPressureLevel level) { |
| 126 int state = static_cast<int>(GetCurrentMemoryState()); |
| 127 switch (level) { |
| 128 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE: |
| 129 UMA_HISTOGRAM_ENUMERATION( |
| 130 "Memory.Coordinator.StateOnModerateNotificationReceived", |
| 131 state, base::kMemoryStateMax); |
| 132 break; |
| 133 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL: |
| 134 UMA_HISTOGRAM_ENUMERATION( |
| 135 "Memory.Coordinator.StateOnCriticalNotificationReceived", |
| 136 state, base::kMemoryStateMax); |
| 137 break; |
| 138 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE: |
| 139 NOTREACHED(); |
| 140 } |
| 141 } |
| 142 |
| 123 void MemoryCoordinator::EnableFeaturesForTesting() { | 143 void MemoryCoordinator::EnableFeaturesForTesting() { |
| 124 base::FeatureList::ClearInstanceForTesting(); | 144 base::FeatureList::ClearInstanceForTesting(); |
| 125 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 145 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 126 feature_list->InitializeFromCommandLine(features::kMemoryCoordinator.name, | 146 feature_list->InitializeFromCommandLine(features::kMemoryCoordinator.name, |
| 127 ""); | 147 ""); |
| 128 base::FeatureList::SetInstance(std::move(feature_list)); | 148 base::FeatureList::SetInstance(std::move(feature_list)); |
| 129 } | 149 } |
| 130 | 150 |
| 131 base::MemoryState MemoryCoordinator::GetCurrentMemoryState() const { | 151 base::MemoryState MemoryCoordinator::GetCurrentMemoryState() const { |
| 132 return base::MemoryState::UNKNOWN; | 152 return base::MemoryState::UNKNOWN; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 204 |
| 185 MemoryCoordinator::ChildInfo::ChildInfo() {} | 205 MemoryCoordinator::ChildInfo::ChildInfo() {} |
| 186 | 206 |
| 187 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) { | 207 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) { |
| 188 // This is a nop, but exists for compatibility with STL containers. | 208 // This is a nop, but exists for compatibility with STL containers. |
| 189 } | 209 } |
| 190 | 210 |
| 191 MemoryCoordinator::ChildInfo::~ChildInfo() {} | 211 MemoryCoordinator::ChildInfo::~ChildInfo() {} |
| 192 | 212 |
| 193 } // namespace content | 213 } // namespace content |
| OLD | NEW |