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 |