| 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_impl.h" | 5 #include "content/browser/memory/memory_coordinator_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/memory_coordinator_client_registry.h" | 7 #include "base/memory/memory_coordinator_client_registry.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 148 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 149 std::unique_ptr<MemoryMonitor> memory_monitor) | 149 std::unique_ptr<MemoryMonitor> memory_monitor) |
| 150 : delegate_(GetContentClient()->browser()->GetMemoryCoordinatorDelegate()), | 150 : delegate_(GetContentClient()->browser()->GetMemoryCoordinatorDelegate()), |
| 151 memory_monitor_(std::move(memory_monitor)), | 151 memory_monitor_(std::move(memory_monitor)), |
| 152 condition_observer_( | 152 condition_observer_( |
| 153 base::MakeUnique<MemoryConditionObserver>(this, task_runner)), | 153 base::MakeUnique<MemoryConditionObserver>(this, task_runner)), |
| 154 minimum_state_transition_period_(base::TimeDelta::FromSeconds( | 154 minimum_state_transition_period_(base::TimeDelta::FromSeconds( |
| 155 kDefaultMinimumTransitionPeriodSeconds)) { | 155 kDefaultMinimumTransitionPeriodSeconds)) { |
| 156 DCHECK(memory_monitor_.get()); | 156 DCHECK(memory_monitor_.get()); |
| 157 base::MemoryCoordinatorProxy::SetMemoryCoordinator(this); | 157 base::MemoryCoordinatorProxy::SetMemoryCoordinator(this); |
| 158 |
| 159 // Force the "memory_coordinator" category to show up in the trace viewer. |
| 160 base::trace_event::TraceLog::GetCategoryGroupEnabled( |
| 161 TRACE_DISABLED_BY_DEFAULT("memory_coordinator")); |
| 158 } | 162 } |
| 159 | 163 |
| 160 MemoryCoordinatorImpl::~MemoryCoordinatorImpl() { | 164 MemoryCoordinatorImpl::~MemoryCoordinatorImpl() { |
| 161 base::MemoryCoordinatorProxy::SetMemoryCoordinator(nullptr); | 165 base::MemoryCoordinatorProxy::SetMemoryCoordinator(nullptr); |
| 162 } | 166 } |
| 163 | 167 |
| 164 void MemoryCoordinatorImpl::Start() { | 168 void MemoryCoordinatorImpl::Start() { |
| 165 DCHECK(CalledOnValidThread()); | 169 DCHECK(CalledOnValidThread()); |
| 166 DCHECK(last_state_change_.is_null()); | 170 DCHECK(last_state_change_.is_null()); |
| 167 | 171 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // Discard one tab when the system is under high memory pressure. | 277 // Discard one tab when the system is under high memory pressure. |
| 274 if (next_condition == MemoryCondition::CRITICAL) | 278 if (next_condition == MemoryCondition::CRITICAL) |
| 275 DiscardTab(); | 279 DiscardTab(); |
| 276 | 280 |
| 277 if (memory_condition_ == next_condition) | 281 if (memory_condition_ == next_condition) |
| 278 return; | 282 return; |
| 279 | 283 |
| 280 MemoryCondition prev_condition = memory_condition_; | 284 MemoryCondition prev_condition = memory_condition_; |
| 281 memory_condition_ = next_condition; | 285 memory_condition_ = next_condition; |
| 282 | 286 |
| 283 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("memory-infra"), | 287 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("memory_coordinator"), |
| 284 "MemoryCoordinatorImpl::UpdateConditionIfNeeded", "prev", | 288 "MemoryCoordinatorImpl::UpdateConditionIfNeeded", "prev", |
| 285 MemoryConditionToString(prev_condition), "next", | 289 MemoryConditionToString(prev_condition), "next", |
| 286 MemoryConditionToString(next_condition)); | 290 MemoryConditionToString(next_condition)); |
| 287 | 291 |
| 288 // TODO(bashi): Following actions are tentative. We might want to prioritize | 292 // TODO(bashi): Following actions are tentative. We might want to prioritize |
| 289 // processes and handle them one-by-one. | 293 // processes and handle them one-by-one. |
| 290 | 294 |
| 291 if (next_condition == MemoryCondition::NORMAL) { | 295 if (next_condition == MemoryCondition::NORMAL) { |
| 292 // Set NORMAL state to all clients/processes. | 296 // Set NORMAL state to all clients/processes. |
| 293 UpdateBrowserStateAndNotifyStateToClients(MemoryState::NORMAL); | 297 UpdateBrowserStateAndNotifyStateToClients(MemoryState::NORMAL); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 439 |
| 436 MemoryCoordinatorImpl::ChildInfo::ChildInfo() {} | 440 MemoryCoordinatorImpl::ChildInfo::ChildInfo() {} |
| 437 | 441 |
| 438 MemoryCoordinatorImpl::ChildInfo::ChildInfo(const ChildInfo& rhs) { | 442 MemoryCoordinatorImpl::ChildInfo::ChildInfo(const ChildInfo& rhs) { |
| 439 // This is a nop, but exists for compatibility with STL containers. | 443 // This is a nop, but exists for compatibility with STL containers. |
| 440 } | 444 } |
| 441 | 445 |
| 442 MemoryCoordinatorImpl::ChildInfo::~ChildInfo() {} | 446 MemoryCoordinatorImpl::ChildInfo::~ChildInfo() {} |
| 443 | 447 |
| 444 } // namespace content | 448 } // namespace content |
| OLD | NEW |