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

Side by Side Diff: components/memory_coordinator/browser/memory_state_notifier.cc

Issue 2094583002: Add MemoryCoordinator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gyp Created 4 years, 5 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 #include "components/memory_coordinator/browser/memory_state_notifier.h"
6
7 #include "base/bind.h"
8 #include "base/memory/singleton.h"
9
10 namespace memory_coordinator {
11
12 MemoryStateNotifier::MemoryStateNotifier() {}
13
14 MemoryStateNotifier::~MemoryStateNotifier() {}
15
16 void MemoryStateNotifier::Notify(mojom::MemoryState state) {
17 for (auto& pair : children_) {
18 pair.second->OnStateChange(state);
19 }
20 }
21
22 void MemoryStateNotifier::IterateChildren(const IterateCallback& callback) {
23 for (auto& pair : children_) {
24 callback.Run(pair.second);
25 }
26 }
27
28 void MemoryStateNotifier::AddChild(mojom::ChildMemoryCoordinatorPtr child) {
29 int id = GetNextId();
haraken 2016/06/27 02:17:07 Would you help me understand why you need an id sy
bashi 2016/06/27 03:49:29 ChildMemoryCoordinatorPtr is an alias for Interfac
30 children_[id] = std::move(child);
31 children_[id].set_connection_error_handler(base::Bind(
32 &MemoryStateNotifier::RemoveChild, base::Unretained(this), id));
33 }
34
35 int MemoryStateNotifier::GetNextId() {
36 return ++next_id_;
37 }
38
39 void MemoryStateNotifier::RemoveChild(int id) {
40 children_.erase(id);
41 }
42
43 } // namespace memory_coordinator
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698