Index: components/memory_coordinator/browser/memory_coordinator.cc |
diff --git a/components/memory_coordinator/browser/memory_coordinator.cc b/components/memory_coordinator/browser/memory_coordinator.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7c7fb2592413f8da6bd69b948be49f6bbe552706 |
--- /dev/null |
+++ b/components/memory_coordinator/browser/memory_coordinator.cc |
@@ -0,0 +1,60 @@ |
+// 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_coordinator.h" |
+ |
+namespace memory_coordinator { |
+ |
+// The implementation of MemoryCoordinatorHandle. See memory_coordinator.mojom |
+// for the role of this class. |
+class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle { |
+ public: |
+ MemoryCoordinatorHandleImpl(mojom::MemoryCoordinatorHandleRequest request) |
+ : binding_(this, std::move(request)) { |
+ } |
+ |
+ // mojom::MemoryCoordinatorHandle implementations: |
+ |
+ void AddChild(mojom::ChildMemoryCoordinatorPtr child) override { |
+ DCHECK(!child_.is_bound()); |
+ child_ = std::move(child); |
+ } |
+ |
+ mojom::ChildMemoryCoordinatorPtr& child() { return child_; } |
+ mojo::Binding<mojom::MemoryCoordinatorHandle>& binding() { return binding_; } |
+ |
+ private: |
+ mojom::ChildMemoryCoordinatorPtr child_; |
+ mojo::Binding<mojom::MemoryCoordinatorHandle> binding_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorHandleImpl); |
+}; |
+ |
+MemoryCoordinator::MemoryCoordinator() {} |
+ |
+MemoryCoordinator::~MemoryCoordinator() {} |
+ |
+void MemoryCoordinator::CreateHandle( |
+ int id, |
+ mojom::MemoryCoordinatorHandleRequest request) { |
+ auto handle = new MemoryCoordinatorHandleImpl(std::move(request)); |
+ handle->binding().set_connection_error_handler(base::Bind( |
+ &MemoryCoordinator::OnConnectionError, base::Unretained(this), id)); |
+ children_[id].reset(handle); |
+} |
+ |
+void MemoryCoordinator::IterateChildrenForTesting( |
+ IterateCallback callback) { |
+ for (auto& pair : children_) { |
+ auto& child = pair.second->child(); |
+ DCHECK(child.is_bound()); |
+ callback.Run(child.get()); |
+ } |
+} |
+ |
+void MemoryCoordinator::OnConnectionError(int id) { |
+ children_.erase(id); |
+} |
+ |
+} // namespace memory_coordinator |