OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "services/resource_coordinator/public/cpp/resource_coordinator_interfac
e.h" | 5 #include "services/resource_coordinator/public/cpp/resource_coordinator_interfac
e.h" |
6 | 6 |
7 #include "mojo/public/cpp/bindings/binding.h" | 7 #include "mojo/public/cpp/bindings/binding.h" |
8 #include "services/resource_coordinator/public/interfaces/coordination_unit_prov
ider.mojom.h" | 8 #include "services/resource_coordinator/public/interfaces/coordination_unit_prov
ider.mojom.h" |
9 #include "services/resource_coordinator/public/interfaces/service_constants.mojo
m.h" | 9 #include "services/resource_coordinator/public/interfaces/service_constants.mojo
m.h" |
10 #include "services/service_manager/public/cpp/connector.h" | 10 #include "services/service_manager/public/cpp/connector.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 void OnConnectionError() { | 14 void OnConnectionError() { |
15 DCHECK(false); | 15 DCHECK(false); |
16 } | 16 } |
17 | 17 |
18 } // namespace | 18 } // namespace |
19 | 19 |
20 namespace resource_coordinator { | 20 namespace resource_coordinator { |
21 | 21 |
22 ResourceCoordinatorInterface::ResourceCoordinatorInterface( | 22 ResourceCoordinatorInterface::ResourceCoordinatorInterface( |
23 service_manager::Connector* connector, | 23 service_manager::Connector* connector, |
24 const CoordinationUnitType& type) | |
25 : weak_ptr_factory_(this) { | |
26 ConnectToService(connector, type, std::string()); | |
27 } | |
28 | |
29 ResourceCoordinatorInterface::ResourceCoordinatorInterface( | |
30 service_manager::Connector* connector, | |
31 const CoordinationUnitType& type, | 24 const CoordinationUnitType& type, |
32 const std::string& id) | 25 const std::string& id) |
33 : weak_ptr_factory_(this) { | 26 : weak_ptr_factory_(this) { |
34 ConnectToService(connector, type, id); | 27 CoordinationUnitID new_cu_id(type, id); |
| 28 ConnectToService(connector, new_cu_id); |
| 29 } |
| 30 |
| 31 ResourceCoordinatorInterface::ResourceCoordinatorInterface( |
| 32 service_manager::Connector* connector, |
| 33 const CoordinationUnitType& type) |
| 34 : ResourceCoordinatorInterface(connector, type, std::string()) {} |
| 35 |
| 36 ResourceCoordinatorInterface::ResourceCoordinatorInterface( |
| 37 service_manager::Connector* connector, |
| 38 const CoordinationUnitType& type, |
| 39 uint64_t id) |
| 40 : weak_ptr_factory_(this) { |
| 41 CoordinationUnitID new_cu_id(type, id); |
| 42 ConnectToService(connector, new_cu_id); |
35 } | 43 } |
36 | 44 |
37 ResourceCoordinatorInterface::~ResourceCoordinatorInterface() = default; | 45 ResourceCoordinatorInterface::~ResourceCoordinatorInterface() = default; |
38 | 46 |
39 void ResourceCoordinatorInterface::ConnectToService( | 47 void ResourceCoordinatorInterface::ConnectToService( |
40 service_manager::Connector* connector, | 48 service_manager::Connector* connector, |
41 const CoordinationUnitType& type, | 49 const CoordinationUnitID& cu_id) { |
42 const std::string& id) { | |
43 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
44 DCHECK(connector); | 51 DCHECK(connector); |
45 mojom::CoordinationUnitProviderPtr provider; | 52 mojom::CoordinationUnitProviderPtr provider; |
46 connector->BindInterface(mojom::kServiceName, mojo::MakeRequest(&provider)); | 53 connector->BindInterface(mojom::kServiceName, mojo::MakeRequest(&provider)); |
47 | 54 |
48 CoordinationUnitID new_cu_id(type, id); | 55 provider->CreateCoordinationUnit(mojo::MakeRequest(&service_), cu_id); |
49 | |
50 provider->CreateCoordinationUnit(mojo::MakeRequest(&service_), new_cu_id); | |
51 | 56 |
52 service_.set_connection_error_handler(base::Bind(&OnConnectionError)); | 57 service_.set_connection_error_handler(base::Bind(&OnConnectionError)); |
53 } | 58 } |
54 | 59 |
55 void ResourceCoordinatorInterface::SendEvent( | 60 void ResourceCoordinatorInterface::SendEvent( |
56 const mojom::EventType& event_type) { | 61 const mojom::EventType& event_type) { |
57 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
58 mojom::EventPtr event = mojom::Event::New(); | 63 mojom::EventPtr event = mojom::Event::New(); |
59 event->type = event_type; | 64 event->type = event_type; |
60 | 65 |
(...skipping 10 matching lines...) Expand all Loading... |
71 weak_ptr_factory_.GetWeakPtr())); | 76 weak_ptr_factory_.GetWeakPtr())); |
72 } | 77 } |
73 | 78 |
74 void ResourceCoordinatorInterface::AddChildByID( | 79 void ResourceCoordinatorInterface::AddChildByID( |
75 const CoordinationUnitID& child_id) { | 80 const CoordinationUnitID& child_id) { |
76 DCHECK(thread_checker_.CalledOnValidThread()); | 81 DCHECK(thread_checker_.CalledOnValidThread()); |
77 service_->AddChild(child_id); | 82 service_->AddChild(child_id); |
78 } | 83 } |
79 | 84 |
80 } // namespace resource_coordinator | 85 } // namespace resource_coordinator |
OLD | NEW |