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_coordinator.h" |
| 6 |
| 7 namespace memory_coordinator { |
| 8 |
| 9 // The implementation of MemoryCoordinatorHandle. See memory_coordinator.mojom |
| 10 // for the role of this class. |
| 11 class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle { |
| 12 public: |
| 13 MemoryCoordinatorHandleImpl(mojom::MemoryCoordinatorHandleRequest request) |
| 14 : binding_(this, std::move(request)) { |
| 15 } |
| 16 |
| 17 // mojom::MemoryCoordinatorHandle implementations: |
| 18 |
| 19 void AddChild(mojom::ChildMemoryCoordinatorPtr child) override { |
| 20 DCHECK(!child_.is_bound()); |
| 21 child_ = std::move(child); |
| 22 } |
| 23 |
| 24 mojom::ChildMemoryCoordinatorPtr& child() { return child_; } |
| 25 mojo::Binding<mojom::MemoryCoordinatorHandle>& binding() { return binding_; } |
| 26 |
| 27 private: |
| 28 mojom::ChildMemoryCoordinatorPtr child_; |
| 29 mojo::Binding<mojom::MemoryCoordinatorHandle> binding_; |
| 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorHandleImpl); |
| 32 }; |
| 33 |
| 34 MemoryCoordinator::MemoryCoordinator() {} |
| 35 |
| 36 MemoryCoordinator::~MemoryCoordinator() {} |
| 37 |
| 38 void MemoryCoordinator::CreateHandle( |
| 39 int id, |
| 40 mojom::MemoryCoordinatorHandleRequest request) { |
| 41 auto handle = new MemoryCoordinatorHandleImpl(std::move(request)); |
| 42 handle->binding().set_connection_error_handler(base::Bind( |
| 43 &MemoryCoordinator::OnConnectionError, base::Unretained(this), id)); |
| 44 children_[id].reset(handle); |
| 45 } |
| 46 |
| 47 void MemoryCoordinator::IterateChildrenForTesting( |
| 48 IterateCallback callback) { |
| 49 for (auto& pair : children_) { |
| 50 auto& child = pair.second->child(); |
| 51 DCHECK(child.is_bound()); |
| 52 callback.Run(child.get()); |
| 53 } |
| 54 } |
| 55 |
| 56 void MemoryCoordinator::OnConnectionError(int id) { |
| 57 children_.erase(id); |
| 58 } |
| 59 |
| 60 } // namespace memory_coordinator |
OLD | NEW |