Index: content/child/memory/child_memory_coordinator_impl.cc |
diff --git a/content/child/memory/child_memory_coordinator_impl.cc b/content/child/memory/child_memory_coordinator_impl.cc |
index 1e6339926d28f3e94fdc354e65b921cc1ead2047..79b582560bbcc25637bd74bd3e0a5f2a16909b3e 100644 |
--- a/content/child/memory/child_memory_coordinator_impl.cc |
+++ b/content/child/memory/child_memory_coordinator_impl.cc |
@@ -6,6 +6,7 @@ |
#include "base/lazy_instance.h" |
#include "base/memory/memory_coordinator_client_registry.h" |
+#include "base/memory/memory_coordinator_proxy.h" |
#include "base/synchronization/lock.h" |
#include "base/trace_event/trace_event.h" |
@@ -32,6 +33,12 @@ base::MemoryState ToBaseMemoryState(mojom::MemoryState state) { |
} |
} |
+// Wrapper for GetCurrentMemoryState that converts converts to a |
+// base::MemoryState. |
+base::MemoryState GetCurrentMemoryState() { |
+ return ToBaseMemoryState(g_child_memory_coordinator->GetCurrentMemoryState()); |
haraken
2016/11/05 12:52:22
g_child_memory_coordinator => GetInstance() ?
chrisha
2016/11/07 19:33:41
Done.
|
+} |
+ |
} // namespace |
// static |
@@ -43,7 +50,8 @@ ChildMemoryCoordinatorImpl* ChildMemoryCoordinatorImpl::GetInstance() { |
ChildMemoryCoordinatorImpl::ChildMemoryCoordinatorImpl( |
mojom::MemoryCoordinatorHandlePtr parent, |
ChildMemoryCoordinatorDelegate* delegate) |
- : binding_(this), parent_(std::move(parent)), delegate_(delegate) { |
+ : binding_(this), parent_(std::move(parent)), delegate_(delegate), |
+ state_(mojom::MemoryState::UNKNOWN), remaining_global_budget_mb_(0) { |
base::AutoLock lock(*g_lock.Pointer()); |
DCHECK(delegate_); |
DCHECK(!g_child_memory_coordinator); |
@@ -65,12 +73,28 @@ void ChildMemoryCoordinatorImpl::OnStateChange(mojom::MemoryState state) { |
base_state); |
} |
+void ChildMemoryCoordinatorImpl::SetRemainingGlobalBudget( |
+ int64_t remaining_global_budget_mb) { |
+ remaining_global_budget_mb_ = remaining_global_budget_mb; |
+} |
+ |
#if !defined(OS_ANDROID) |
std::unique_ptr<ChildMemoryCoordinatorImpl> CreateChildMemoryCoordinator( |
mojom::MemoryCoordinatorHandlePtr parent, |
ChildMemoryCoordinatorDelegate* delegate) { |
- return base::WrapUnique( |
- new ChildMemoryCoordinatorImpl(std::move(parent), delegate)); |
+ auto* cmc = new ChildMemoryCoordinatorImpl(std::move(parent), delegate); |
+ |
+ // Hookup the coordinator to the MemoryCoordinatorProxy. base::Unretained is |
+ // safe because the lifetime of the ChildMemoryCoordinatorImpl is tied to the |
+ // lifetime of the renderer process. |
+ base::MemoryCoordinatorProxy::GetInstance()-> |
+ SetGetCurrentMemoryStateCallback(base::Bind(&GetCurrentMemoryState)); |
+ base::MemoryCoordinatorProxy::GetInstance()-> |
+ SetGetRemainingGlobalBudgetCallback(base::Bind( |
+ &ChildMemoryCoordinatorImpl::GetRemainingGlobalBudget, |
+ base::Unretained(cmc))); |
+ |
+ return base::WrapUnique(cmc); |
} |
#endif |