OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_STATE_NOTIFIER_H_ |
| 6 #define COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_STATE_NOTIFIER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <memory> |
| 10 |
| 11 #include "base/threading/non_thread_safe.h" |
| 12 #include "components/memory_coordinator/public/interfaces/child_memory_coordinat
or.mojom.h" |
| 13 |
| 14 namespace memory_coordinator { |
| 15 |
| 16 // MemoryStateNotifier sends memory events to ChildMemoryCoordinators using |
| 17 // mojo messages. This isn't thread-safe. |
| 18 class MemoryStateNotifier : public base::NonThreadSafe { |
| 19 public: |
| 20 MemoryStateNotifier(); |
| 21 ~MemoryStateNotifier(); |
| 22 |
| 23 // Add a ChildMemoryCoordinator. MemoryStateNotifier takes the ownership. |
| 24 // A child will be removed when a connection error happens. |
| 25 void AddChild(mojom::ChildMemoryCoordinatorPtr child); |
| 26 |
| 27 // Notify a memory event to all ChildMemoryCoordinators. |
| 28 void Notify(mojom::MemoryState state); |
| 29 |
| 30 // Iterate all clients and run a given callback. |
| 31 using IterateCallback = |
| 32 base::Callback<void(mojom::ChildMemoryCoordinatorPtr&)>; |
| 33 void IterateChildren(const IterateCallback& callback); |
| 34 |
| 35 private: |
| 36 int GetNextId(); |
| 37 void RemoveChild(int id); |
| 38 |
| 39 int next_id_ = 0; |
| 40 std::map<int, mojom::ChildMemoryCoordinatorPtr> children_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(MemoryStateNotifier); |
| 43 }; |
| 44 |
| 45 } // namespace memory_coordinator |
| 46 |
| 47 #endif // COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_STATE_NOTIFIER_H_ |
OLD | NEW |