| 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_
|
|
|