Commit 7056550d authored by bashi's avatar bashi Committed by Commit bot

Add a static getter for ChildMemoryCoordinator

Currently ChildMemoryCoordinator is owned by RenderThreadImpl but
some other components (like cc) would want to become clients of
ChildMemoryCoordinator. Add a static getter to provide access
to ChildMemoryCoordinator.

BUG=617492

Review-Url: https://codereview.chromium.org/2291473002
Cr-Commit-Position: refs/heads/master@{#415212}
parent 5fe00b8d
......@@ -4,17 +4,39 @@
#include "components/memory_coordinator/child/child_memory_coordinator_impl.h"
#include "base/lazy_instance.h"
#include "base/synchronization/lock.h"
namespace memory_coordinator {
namespace {
base::LazyInstance<base::Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER;
ChildMemoryCoordinatorImpl* g_child_memory_coordinator = nullptr;
} // namespace
// static
ChildMemoryCoordinatorImpl* ChildMemoryCoordinatorImpl::GetInstance() {
base::AutoLock lock(*g_lock.Pointer());
return g_child_memory_coordinator;
}
ChildMemoryCoordinatorImpl::ChildMemoryCoordinatorImpl(
mojom::MemoryCoordinatorHandlePtr parent,
ChildMemoryCoordinatorDelegate* delegate)
: binding_(this), parent_(std::move(parent)), delegate_(delegate) {
base::AutoLock lock(*g_lock.Pointer());
DCHECK(delegate_);
DCHECK(!g_child_memory_coordinator);
g_child_memory_coordinator = this;
parent_->AddChild(binding_.CreateInterfacePtrAndBind());
}
ChildMemoryCoordinatorImpl::~ChildMemoryCoordinatorImpl() {
base::AutoLock lock(*g_lock.Pointer());
DCHECK(g_child_memory_coordinator == this);
g_child_memory_coordinator = nullptr;
}
void ChildMemoryCoordinatorImpl::OnStateChange(mojom::MemoryState state) {
......
......@@ -31,8 +31,11 @@ class MEMORY_COORDINATOR_EXPORT ChildMemoryCoordinatorImpl
: public ClientRegistry,
NON_EXPORTED_BASE(public mojom::ChildMemoryCoordinator) {
public:
explicit ChildMemoryCoordinatorImpl(mojom::MemoryCoordinatorHandlePtr parent,
ChildMemoryCoordinatorDelegate* delegate);
// Returns the instance of ChildMemoryCoordinatorImpl. Could be nullptr.
static ChildMemoryCoordinatorImpl* GetInstance();
ChildMemoryCoordinatorImpl(mojom::MemoryCoordinatorHandlePtr parent,
ChildMemoryCoordinatorDelegate* delegate);
~ChildMemoryCoordinatorImpl() override;
// mojom::ChildMemoryCoordinator implementations:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment