Chromium Code Reviews| 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/common/memory_coordinator_features.h" | |
| 13 #include "components/memory_coordinator/public/interfaces/child_memory_coordinat or.mojom.h" | |
| 14 | |
| 15 namespace memory_coordinator { | |
| 16 | |
| 17 // MemoryStateNotifier sends memory events to ChildMemoryCoordinators using | |
| 18 // mojo messages. This isn't thread-safe. | |
| 19 class MemoryStateNotifier : public base::NonThreadSafe { | |
| 20 public: | |
| 21 MemoryStateNotifier(); | |
| 22 ~MemoryStateNotifier(); | |
| 23 | |
| 24 // Add a ChildMemoryCoordinator. MemoryStateNotifier takes the ownership. | |
| 25 // A child will be removed when a connection error happens. | |
| 26 void AddChild(mojom::ChildMemoryCoordinatorPtr child); | |
| 27 | |
| 28 // Notify a memory event to all ChildMemoryCoordinators. | |
| 29 void Notify(mojom::MemoryState state); | |
| 30 | |
| 31 // Iterate all clients and run a given callback. | |
| 32 using IterateCallback = | |
| 33 base::Callback<void(mojom::ChildMemoryCoordinatorPtr&)>; | |
| 34 void IterateChildren(const IterateCallback& callback); | |
| 35 | |
| 36 private: | |
| 37 int GetNextId(); | |
| 38 void RemoveChild(int id); | |
|
chrisha
2016/06/27 20:35:30
Documentation for these functions would be helpful
| |
| 39 | |
| 40 int next_id_ = 0; | |
| 41 std::map<int, mojom::ChildMemoryCoordinatorPtr> children_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(MemoryStateNotifier); | |
| 44 }; | |
| 45 | |
| 46 } // namespace memory_coordinator | |
| 47 | |
| 48 #endif // COMPONENTS_MEMORY_COORDINATOR_BROWSER_MEMORY_STATE_NOTIFIER_H_ | |
| OLD | NEW |