OLD | NEW |
| (Empty) |
1 // Copyright 2017 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 "services/resource_coordinator/coordination_unit/coordination_unit_prov
ider_impl.h" | |
6 | |
7 #include <memory> | |
8 #include <utility> | |
9 | |
10 #include "base/logging.h" | |
11 #include "mojo/public/cpp/bindings/strong_binding.h" | |
12 #include "services/resource_coordinator/coordination_unit/coordination_unit_impl
.h" | |
13 #include "services/service_manager/public/cpp/service_context_ref.h" | |
14 | |
15 namespace resource_coordinator { | |
16 | |
17 CoordinationUnitProviderImpl::CoordinationUnitProviderImpl( | |
18 service_manager::ServiceContextRefFactory* service_ref_factory) | |
19 : service_ref_factory_(service_ref_factory) { | |
20 DCHECK(service_ref_factory); | |
21 service_ref_ = service_ref_factory->CreateRef(); | |
22 } | |
23 | |
24 CoordinationUnitProviderImpl::~CoordinationUnitProviderImpl() = default; | |
25 | |
26 void CoordinationUnitProviderImpl::CreateCoordinationUnit( | |
27 mojom::CoordinationUnitRequest request, | |
28 const CoordinationUnitID& id) { | |
29 // TODO(oysteine): A strong binding here means the first binding set up | |
30 // to a CoordinationUnit via CoordinationUnitProvider, i.e. the authoritative | |
31 // one in terms of setting the context, has to outlive all of the other | |
32 // connections (as the rest are just duplicated and held within | |
33 // CoordinationUnit). Make sure this assumption is correct, or refactor into | |
34 // some kind of refcounted thing. | |
35 | |
36 // Once there's a need for custom code for various types of CUs (tabs, | |
37 // processes, etc) then this could become a factory function and instantiate | |
38 // different subclasses of CoordinationUnitImpl based on the id.type. | |
39 mojo::MakeStrongBinding(base::MakeUnique<CoordinationUnitImpl>( | |
40 id, service_ref_factory_->CreateRef()), | |
41 std::move(request)); | |
42 }; | |
43 | |
44 // static | |
45 void CoordinationUnitProviderImpl::Create( | |
46 service_manager::ServiceContextRefFactory* service_ref_factory, | |
47 resource_coordinator::mojom::CoordinationUnitProviderRequest request) { | |
48 mojo::MakeStrongBinding( | |
49 base::MakeUnique<CoordinationUnitProviderImpl>(service_ref_factory), | |
50 std::move(request)); | |
51 } | |
52 | |
53 } // namespace resource_coordinator | |
OLD | NEW |