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

Side by Side Diff: content/child/memory/child_memory_coordinator_impl.cc

Issue 2739363002: Implement base::MemoryCoordinator for ChildMemoryCoordinatorImpl (Closed)
Patch Set: 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/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/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 ChildMemoryCoordinatorImpl::ChildMemoryCoordinatorImpl( 44 ChildMemoryCoordinatorImpl::ChildMemoryCoordinatorImpl(
45 mojom::MemoryCoordinatorHandlePtr parent, 45 mojom::MemoryCoordinatorHandlePtr parent,
46 ChildMemoryCoordinatorDelegate* delegate) 46 ChildMemoryCoordinatorDelegate* delegate)
47 : binding_(this), parent_(std::move(parent)), delegate_(delegate) { 47 : binding_(this), parent_(std::move(parent)), delegate_(delegate) {
48 base::AutoLock lock(*g_lock.Pointer()); 48 base::AutoLock lock(*g_lock.Pointer());
49 DCHECK(delegate_); 49 DCHECK(delegate_);
50 DCHECK(!g_child_memory_coordinator); 50 DCHECK(!g_child_memory_coordinator);
51 g_child_memory_coordinator = this; 51 g_child_memory_coordinator = this;
52 parent_->AddChild(binding_.CreateInterfacePtrAndBind()); 52 parent_->AddChild(binding_.CreateInterfacePtrAndBind());
53 base::MemoryCoordinatorProxy::SetMemoryCoordinator(this);
53 } 54 }
54 55
55 ChildMemoryCoordinatorImpl::~ChildMemoryCoordinatorImpl() { 56 ChildMemoryCoordinatorImpl::~ChildMemoryCoordinatorImpl() {
56 base::AutoLock lock(*g_lock.Pointer()); 57 base::AutoLock lock(*g_lock.Pointer());
57 DCHECK(g_child_memory_coordinator == this); 58 DCHECK(g_child_memory_coordinator == this);
58 g_child_memory_coordinator = nullptr; 59 g_child_memory_coordinator = nullptr;
59 } 60 }
60 61
62 base::MemoryState ChildMemoryCoordinatorImpl::GetCurrentMemoryState() const {
63 return current_state_;
64 }
65
61 void ChildMemoryCoordinatorImpl::PurgeMemory() { 66 void ChildMemoryCoordinatorImpl::PurgeMemory() {
62 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory-infra"), 67 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory-infra"),
63 "ChildMemoryCoordinatorImpl::PurgeMemory"); 68 "ChildMemoryCoordinatorImpl::PurgeMemory");
64 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); 69 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory();
65 } 70 }
66 71
67 void ChildMemoryCoordinatorImpl::OnStateChange(mojom::MemoryState state) { 72 void ChildMemoryCoordinatorImpl::OnStateChange(mojom::MemoryState state) {
68 base::MemoryState base_state = ToBaseMemoryState(state); 73 current_state_ = ToBaseMemoryState(state);
69 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("memory-infra"), 74 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("memory-infra"),
70 "ChildMemoryCoordinatorImpl::OnStateChange", "state", 75 "ChildMemoryCoordinatorImpl::OnStateChange", "state",
71 MemoryStateToString(base_state)); 76 MemoryStateToString(current_state_));
72 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( 77 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify(current_state_);
73 base_state);
74 } 78 }
75 79
76 #if !defined(OS_ANDROID) 80 #if !defined(OS_ANDROID)
77 std::unique_ptr<ChildMemoryCoordinatorImpl> CreateChildMemoryCoordinator( 81 std::unique_ptr<ChildMemoryCoordinatorImpl> CreateChildMemoryCoordinator(
78 mojom::MemoryCoordinatorHandlePtr parent, 82 mojom::MemoryCoordinatorHandlePtr parent,
79 ChildMemoryCoordinatorDelegate* delegate) { 83 ChildMemoryCoordinatorDelegate* delegate) {
80 return base::WrapUnique( 84 return base::WrapUnique(
81 new ChildMemoryCoordinatorImpl(std::move(parent), delegate)); 85 new ChildMemoryCoordinatorImpl(std::move(parent), delegate));
82 } 86 }
83 #endif 87 #endif
84 88
85 } // namespace content 89 } // namespace content
OLDNEW
« no previous file with comments | « content/child/memory/child_memory_coordinator_impl.h ('k') | content/child/memory/child_memory_coordinator_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698