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

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

Issue 2731913002: NotForReview: Expose the global memory budget (chromium side)
Patch Set: Add --simulate-memory-pressure 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 parent_->GetGlobalBudgetHandle(
54 base::Bind(&ChildMemoryCoordinatorImpl::OnGetGlobalBudgetHandle,
55 base::Unretained(this)));
53 base::MemoryCoordinatorProxy::SetMemoryCoordinator(this); 56 base::MemoryCoordinatorProxy::SetMemoryCoordinator(this);
54 } 57 }
55 58
56 ChildMemoryCoordinatorImpl::~ChildMemoryCoordinatorImpl() { 59 ChildMemoryCoordinatorImpl::~ChildMemoryCoordinatorImpl() {
57 base::AutoLock lock(*g_lock.Pointer()); 60 base::AutoLock lock(*g_lock.Pointer());
58 DCHECK(g_child_memory_coordinator == this); 61 DCHECK(g_child_memory_coordinator == this);
59 g_child_memory_coordinator = nullptr; 62 g_child_memory_coordinator = nullptr;
60 } 63 }
61 64
62 base::MemoryState ChildMemoryCoordinatorImpl::GetCurrentMemoryState() const { 65 base::MemoryState ChildMemoryCoordinatorImpl::GetCurrentMemoryState() const {
63 return current_state_; 66 return current_state_;
64 } 67 }
65 68
69 int64_t ChildMemoryCoordinatorImpl::GetGlobalBudget() {
70 if (!global_budget_handle_.is_valid())
71 return -1;
72 return *reinterpret_cast<int64_t*>(global_budget_mapping_.get());
73 }
74
75 void ChildMemoryCoordinatorImpl::SetGlobalBudgetUpdateInterval(
76 uint32_t interval_ms) {
77 parent_->SetGlobalBudgetUpdateInterval(interval_ms);
78 }
79
66 void ChildMemoryCoordinatorImpl::PurgeMemory() { 80 void ChildMemoryCoordinatorImpl::PurgeMemory() {
67 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory-infra"), 81 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("memory-infra"),
68 "ChildMemoryCoordinatorImpl::PurgeMemory"); 82 "ChildMemoryCoordinatorImpl::PurgeMemory");
69 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); 83 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory();
70 } 84 }
71 85
72 void ChildMemoryCoordinatorImpl::OnStateChange(mojom::MemoryState state) { 86 void ChildMemoryCoordinatorImpl::OnStateChange(mojom::MemoryState state) {
73 current_state_ = ToBaseMemoryState(state); 87 current_state_ = ToBaseMemoryState(state);
74 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("memory-infra"), 88 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("memory-infra"),
75 "ChildMemoryCoordinatorImpl::OnStateChange", "state", 89 "ChildMemoryCoordinatorImpl::OnStateChange", "state",
76 MemoryStateToString(current_state_)); 90 MemoryStateToString(current_state_));
77 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify(current_state_); 91 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify(current_state_);
78 } 92 }
79 93
94 void ChildMemoryCoordinatorImpl::OnGetGlobalBudgetHandle(
95 mojo::ScopedSharedBufferHandle handle) {
96 global_budget_handle_ = std::move(handle);
97 global_budget_mapping_ = global_budget_handle_->Map(sizeof(int64_t));
98 DCHECK(global_budget_mapping_.get());
99 }
100
80 #if !defined(OS_ANDROID) 101 #if !defined(OS_ANDROID)
81 std::unique_ptr<ChildMemoryCoordinatorImpl> CreateChildMemoryCoordinator( 102 std::unique_ptr<ChildMemoryCoordinatorImpl> CreateChildMemoryCoordinator(
82 mojom::MemoryCoordinatorHandlePtr parent, 103 mojom::MemoryCoordinatorHandlePtr parent,
83 ChildMemoryCoordinatorDelegate* delegate) { 104 ChildMemoryCoordinatorDelegate* delegate) {
84 return base::WrapUnique( 105 return base::WrapUnique(
85 new ChildMemoryCoordinatorImpl(std::move(parent), delegate)); 106 new ChildMemoryCoordinatorImpl(std::move(parent), delegate));
86 } 107 }
87 #endif 108 #endif
88 109
89 } // namespace content 110 } // namespace content
OLDNEW
« no previous file with comments | « content/child/memory/child_memory_coordinator_impl.h ('k') | content/common/memory_coordinator.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698