Chromium Code Reviews| Index: components/memory_coordinator/browser/memory_state_notifier.cc |
| diff --git a/components/memory_coordinator/browser/memory_state_notifier.cc b/components/memory_coordinator/browser/memory_state_notifier.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..afa90109b5ea12265f77d63ff005bb02ad1fa369 |
| --- /dev/null |
| +++ b/components/memory_coordinator/browser/memory_state_notifier.cc |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/memory_coordinator/browser/memory_state_notifier.h" |
| + |
| +#include "base/bind.h" |
| + |
| +namespace memory_coordinator { |
| + |
| +MemoryStateNotifier::MemoryStateNotifier() {} |
| + |
| +MemoryStateNotifier::~MemoryStateNotifier() {} |
| + |
| +void MemoryStateNotifier::Notify(mojom::MemoryState state) { |
| + for (auto& pair : children_) { |
| + pair.second->OnStateChange(state); |
| + } |
| +} |
| + |
| +void MemoryStateNotifier::IterateChildren(const IterateCallback& callback) { |
| + for (auto& pair : children_) { |
| + callback.Run(pair.second); |
| + } |
| +} |
| + |
| +void MemoryStateNotifier::AddChild(mojom::ChildMemoryCoordinatorPtr child) { |
| + int id = GetNextId(); |
| + children_[id] = std::move(child); |
| + children_[id].set_connection_error_handler(base::Bind( |
| + &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
|
| +} |
| + |
| +int MemoryStateNotifier::GetNextId() { |
| + return ++next_id_; |
| +} |
| + |
| +void MemoryStateNotifier::RemoveChild(int id) { |
| + children_.erase(id); |
| +} |
| + |
| +} // namespace memory_coordinator |