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

Side by Side 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 unified diff | Download patch
OLDNEW
(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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698