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

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

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.h
diff --git a/components/memory_coordinator/browser/memory_state_notifier.h b/components/memory_coordinator/browser/memory_state_notifier.h
new file mode 100644
index 0000000000000000000000000000000000000000..bbdabea27930d8d608f588a84f78d33ec5b001e6
--- /dev/null
+++ b/components/memory_coordinator/browser/memory_state_notifier.h
@@ -0,0 +1,47 @@
+// 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.
+
+#ifndef COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_STATE_NOTIFIER_H_
+#define COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_STATE_NOTIFIER_H_
+
+#include <map>
+#include <memory>
+
+#include "base/threading/non_thread_safe.h"
+#include "components/memory_coordinator/public/interfaces/child_memory_coordinator.mojom.h"
+
+namespace memory_coordinator {
+
+// MemoryStateNotifier sends memory events to ChildMemoryCoordinators using
+// mojo messages. This isn't thread-safe.
+class MemoryStateNotifier : public base::NonThreadSafe {
+ public:
+ MemoryStateNotifier();
+ ~MemoryStateNotifier();
+
+ // Add a ChildMemoryCoordinator. MemoryStateNotifier takes the ownership.
+ // A child will be removed when a connection error happens.
+ void AddChild(mojom::ChildMemoryCoordinatorPtr child);
+
+ // Notify a memory event to all ChildMemoryCoordinators.
+ void Notify(mojom::MemoryState state);
+
+ // Iterate all clients and run a given callback.
+ using IterateCallback =
+ base::Callback<void(mojom::ChildMemoryCoordinatorPtr&)>;
+ void IterateChildren(const IterateCallback& callback);
+
+ private:
+ int GetNextId();
+ void RemoveChild(int id);
+
+ int next_id_ = 0;
+ std::map<int, mojom::ChildMemoryCoordinatorPtr> children_;
+
+ DISALLOW_COPY_AND_ASSIGN(MemoryStateNotifier);
+};
+
+} // namespace memory_coordinator
+
+#endif // COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_STATE_NOTIFIER_H_

Powered by Google App Engine
This is Rietveld 408576698