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

Unified Diff: components/memory_coordinator/child/child_memory_coordinator_impl.cc

Issue 2291473002: Add a static getter for ChildMemoryCoordinator (Closed)
Patch Set: Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/memory_coordinator/child/child_memory_coordinator_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/memory_coordinator/child/child_memory_coordinator_impl.cc
diff --git a/components/memory_coordinator/child/child_memory_coordinator_impl.cc b/components/memory_coordinator/child/child_memory_coordinator_impl.cc
index 1e4a9c8ecd22df7664935112f75398660279c1ba..75dd8ed5243e46e1ee1cec024a90a67f034a700d 100644
--- a/components/memory_coordinator/child/child_memory_coordinator_impl.cc
+++ b/components/memory_coordinator/child/child_memory_coordinator_impl.cc
@@ -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;
bashi 2016/08/29 09:52:06 Not sure we really need a lock. Can be removed whe
haraken 2016/09/01 18:49:10 I begin to think that ChildMemoryCoordinator must
bashi 2016/09/01 22:53:39 Making ChildMemoryCoordinator only accessible via
+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) {
« no previous file with comments | « components/memory_coordinator/child/child_memory_coordinator_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698