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

Unified Diff: components/memory_coordinator/browser/memory_state_notifier.cc

Issue 2094583002: Add MemoryCoordinator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gyp Created 4 years, 6 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
Index: components/memory_coordinator/browser/memory_state_notifier.cc
diff --git a/components/memory_coordinator/browser/memory_state_notifier.cc b/components/memory_coordinator/browser/memory_state_notifier.cc
new file mode 100644
index 0000000000000000000000000000000000000000..691102890d5389f43c11e4ebcc3b7a19e1db60cd
--- /dev/null
+++ b/components/memory_coordinator/browser/memory_state_notifier.cc
@@ -0,0 +1,43 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/memory_coordinator/browser/memory_state_notifier.h"
+
+#include "base/bind.h"
+#include "base/memory/singleton.h"
+
+namespace memory_coordinator {
+
+MemoryStateNotifier::MemoryStateNotifier() {}
+
+MemoryStateNotifier::~MemoryStateNotifier() {}
+
+void MemoryStateNotifier::Notify(mojom::MemoryState state) {
+ for (auto& pair : children_) {
+ pair.second->OnStateChange(state);
+ }
+}
+
+void MemoryStateNotifier::IterateChildren(const IterateCallback& callback) {
+ for (auto& pair : children_) {
+ callback.Run(pair.second);
+ }
+}
+
+void MemoryStateNotifier::AddChild(mojom::ChildMemoryCoordinatorPtr child) {
+ int id = GetNextId();
haraken 2016/06/27 02:17:07 Would you help me understand why you need an id sy
bashi 2016/06/27 03:49:29 ChildMemoryCoordinatorPtr is an alias for Interfac
+ children_[id] = std::move(child);
+ children_[id].set_connection_error_handler(base::Bind(
+ &MemoryStateNotifier::RemoveChild, base::Unretained(this), id));
+}
+
+int MemoryStateNotifier::GetNextId() {
+ return ++next_id_;
+}
+
+void MemoryStateNotifier::RemoveChild(int id) {
+ children_.erase(id);
+}
+
+} // namespace memory_coordinator

Powered by Google App Engine
This is Rietveld 408576698