Index: services/resource_coordinator/coordination_unit/coordination_unit_provider_impl.cc |
diff --git a/services/resource_coordinator/coordination_unit/coordination_unit_provider_impl.cc b/services/resource_coordinator/coordination_unit/coordination_unit_provider_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..91afd59fed66bc90871c0bcead2a7f147d2a5e16 |
--- /dev/null |
+++ b/services/resource_coordinator/coordination_unit/coordination_unit_provider_impl.cc |
@@ -0,0 +1,42 @@ |
+// Copyright 2017 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 "services/resource_coordinator/coordination_unit/coordination_unit_provider_impl.h" |
+ |
+#include "base/logging.h" |
+#include "mojo/public/cpp/bindings/strong_binding.h" |
+#include "services/resource_coordinator/coordination_unit/coordination_unit_impl.h" |
+#include "services/service_manager/public/cpp/connection.h" |
+ |
+namespace resource_coordinator { |
+ |
+CoordinationUnitProviderImpl::CoordinationUnitProviderImpl( |
+ service_manager::ServiceContextRefFactory* service_ref_factory) |
+ : service_ref_factory_(service_ref_factory) { |
+ if (service_ref_factory) |
+ service_ref_ = service_ref_factory->CreateRef(); |
+} |
+ |
+CoordinationUnitProviderImpl::~CoordinationUnitProviderImpl() = default; |
+ |
+void CoordinationUnitProviderImpl::CreateCoordinationUnit( |
+ mojom::CoordinationUnitRequest request, |
+ const CoordinationUnitID& id) { |
+ // TODO(oysteine): A strong binding here means the first binding set up |
+ // to a CoordinationUnit via CoordinationUnitProvider, i.e. the authoritative |
+ // one in terms of setting the context, has to outlive all of the other |
+ // connections (as the rest are just duplicated and held within |
+ // CoordinationUnit). Make sure this assumption is correct, or refactor into |
+ // some kind of refcounted thing. |
+ |
+ std::unique_ptr<service_manager::ServiceContextRef> service_ref; |
+ if (service_ref_factory_) |
+ service_ref = service_ref_factory_->CreateRef(); |
+ |
+ mojo::MakeStrongBinding( |
+ base::MakeUnique<CoordinationUnitImpl>(id, std::move(service_ref)), |
+ std::move(request)); |
+}; |
+ |
+} // namespace resource_coordinator |