| 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 render_process_id, | |
| 40 mojom::MemoryCoordinatorHandleRequest request) { | |
| 41 auto handle = new MemoryCoordinatorHandleImpl(std::move(request)); | |
| 42 handle->binding().set_connection_error_handler( | |
| 43 base::Bind(&MemoryCoordinator::OnConnectionError, base::Unretained(this), | |
| 44 render_process_id)); | |
| 45 children_[render_process_id].reset(handle); | |
| 46 } | |
| 47 | |
| 48 size_t MemoryCoordinator::NumChildrenForTesting() { | |
| 49 return children_.size(); | |
| 50 } | |
| 51 | |
| 52 void MemoryCoordinator::OnConnectionError(int render_process_id) { | |
| 53 children_.erase(render_process_id); | |
| 54 } | |
| 55 | |
| 56 } // namespace memory_coordinator | |
| OLD | NEW |