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 #include "components/memory_coordinator/browser/memory_state_notifier.h" | |
6 | |
7 #include "base/bind.h" | |
8 | |
9 namespace memory_coordinator { | |
10 | |
11 MemoryStateNotifier::MemoryStateNotifier() {} | |
12 | |
13 MemoryStateNotifier::~MemoryStateNotifier() {} | |
14 | |
15 void MemoryStateNotifier::Notify(mojom::MemoryState state) { | |
16 for (auto& pair : children_) { | |
17 pair.second->OnStateChange(state); | |
18 } | |
19 } | |
20 | |
21 void MemoryStateNotifier::IterateChildren(const IterateCallback& callback) { | |
22 for (auto& pair : children_) { | |
23 callback.Run(pair.second); | |
24 } | |
25 } | |
26 | |
27 void MemoryStateNotifier::AddChild(mojom::ChildMemoryCoordinatorPtr child) { | |
28 int id = GetNextId(); | |
29 children_[id] = std::move(child); | |
30 children_[id].set_connection_error_handler(base::Bind( | |
31 &MemoryStateNotifier::RemoveChild, base::Unretained(this), id)); | |
haraken
2016/06/27 11:16:00
I'm not sure if the ID system is the best way to i
chrisha
2016/06/27 20:35:30
I don't see any problem with this, but you could a
bashi
2016/06/27 22:40:23
Yes. I'd just prefer using IDs but raw pointers sh
| |
32 } | |
33 | |
34 int MemoryStateNotifier::GetNextId() { | |
35 return ++next_id_; | |
36 } | |
37 | |
38 void MemoryStateNotifier::RemoveChild(int id) { | |
39 children_.erase(id); | |
40 } | |
41 | |
42 } // namespace memory_coordinator | |
OLD | NEW |