| 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/child/memory/child_memory_coordinator_impl.h" | 5 #include "content/child/memory/child_memory_coordinator_impl.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/memory_coordinator_client_registry.h" | 8 #include "base/memory/memory_coordinator_client_registry.h" |
| 9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 #include "base/trace_event/trace_event.h" |
| 10 | 11 |
| 11 namespace content { | 12 namespace content { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 base::LazyInstance<base::Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER; | 16 base::LazyInstance<base::Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER; |
| 16 ChildMemoryCoordinatorImpl* g_child_memory_coordinator = nullptr; | 17 ChildMemoryCoordinatorImpl* g_child_memory_coordinator = nullptr; |
| 17 | 18 |
| 18 base::MemoryState ToBaseMemoryState(mojom::MemoryState state) { | 19 base::MemoryState ToBaseMemoryState(mojom::MemoryState state) { |
| 19 switch (state) { | 20 switch (state) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } | 52 } |
| 52 | 53 |
| 53 ChildMemoryCoordinatorImpl::~ChildMemoryCoordinatorImpl() { | 54 ChildMemoryCoordinatorImpl::~ChildMemoryCoordinatorImpl() { |
| 54 base::AutoLock lock(*g_lock.Pointer()); | 55 base::AutoLock lock(*g_lock.Pointer()); |
| 55 DCHECK(g_child_memory_coordinator == this); | 56 DCHECK(g_child_memory_coordinator == this); |
| 56 g_child_memory_coordinator = nullptr; | 57 g_child_memory_coordinator = nullptr; |
| 57 } | 58 } |
| 58 | 59 |
| 59 void ChildMemoryCoordinatorImpl::OnStateChange(mojom::MemoryState state) { | 60 void ChildMemoryCoordinatorImpl::OnStateChange(mojom::MemoryState state) { |
| 60 base::MemoryState base_state = ToBaseMemoryState(state); | 61 base::MemoryState base_state = ToBaseMemoryState(state); |
| 62 TRACE_EVENT1("memory-infra", "ChildMemoryCoordinatorImpl::OnStateChange", |
| 63 "state", MemoryStateToString(base_state)); |
| 61 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 64 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 62 base_state); | 65 base_state); |
| 63 } | 66 } |
| 64 | 67 |
| 65 #if !defined(OS_ANDROID) | 68 #if !defined(OS_ANDROID) |
| 66 std::unique_ptr<ChildMemoryCoordinatorImpl> CreateChildMemoryCoordinator( | 69 std::unique_ptr<ChildMemoryCoordinatorImpl> CreateChildMemoryCoordinator( |
| 67 mojom::MemoryCoordinatorHandlePtr parent, | 70 mojom::MemoryCoordinatorHandlePtr parent, |
| 68 ChildMemoryCoordinatorDelegate* delegate) { | 71 ChildMemoryCoordinatorDelegate* delegate) { |
| 69 return base::WrapUnique( | 72 return base::WrapUnique( |
| 70 new ChildMemoryCoordinatorImpl(std::move(parent), delegate)); | 73 new ChildMemoryCoordinatorImpl(std::move(parent), delegate)); |
| 71 } | 74 } |
| 72 #endif | 75 #endif |
| 73 | 76 |
| 74 } // namespace content | 77 } // namespace content |
| OLD | NEW |