Chromium Code Reviews| 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..4bbc8ccb68a2aa2b66f2ed910f2700d8cf1acb4b |
| --- /dev/null |
| +++ b/components/memory_coordinator/browser/memory_state_notifier.h |
| @@ -0,0 +1,48 @@ |
| +// 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/common/memory_coordinator_features.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); |
|
chrisha
2016/06/27 20:35:30
Documentation for these functions would be helpful
|
| + |
| + 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_ |