Chromium Code Reviews| 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 LOG(ERROR) << "OnConnectionError"; | |
|
oystein (OOO til 10th of July)
2017/05/17 23:06:07
Leftover log line?
matthalp
2017/05/18 16:13:46
Done.
| |
| 15 DCHECK(false); | 16 DCHECK(false); |
| 16 } | 17 } |
| 17 | 18 |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| 20 namespace resource_coordinator { | 21 namespace resource_coordinator { |
| 21 | 22 |
| 22 ResourceCoordinatorInterface::ResourceCoordinatorInterface( | 23 ResourceCoordinatorInterface::ResourceCoordinatorInterface( |
| 23 service_manager::Connector* connector, | 24 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, | 25 const CoordinationUnitType& type, |
| 32 const std::string& id) | 26 const std::string& id) |
| 33 : weak_ptr_factory_(this) { | 27 : weak_ptr_factory_(this) { |
| 34 ConnectToService(connector, type, id); | 28 CoordinationUnitID new_cu_id(type, id); |
| 29 ConnectToService(connector, new_cu_id); | |
| 30 } | |
| 31 | |
| 32 ResourceCoordinatorInterface::ResourceCoordinatorInterface( | |
| 33 service_manager::Connector* connector, | |
| 34 const CoordinationUnitType& type) | |
| 35 : ResourceCoordinatorInterface(connector, type, std::string()) {} | |
| 36 | |
| 37 ResourceCoordinatorInterface::ResourceCoordinatorInterface( | |
| 38 service_manager::Connector* connector, | |
| 39 const CoordinationUnitType& type, | |
| 40 uint64_t id) | |
| 41 : weak_ptr_factory_(this) { | |
| 42 CoordinationUnitID new_cu_id(type, id); | |
| 43 ConnectToService(connector, new_cu_id); | |
| 35 } | 44 } |
| 36 | 45 |
| 37 ResourceCoordinatorInterface::~ResourceCoordinatorInterface() = default; | 46 ResourceCoordinatorInterface::~ResourceCoordinatorInterface() = default; |
| 38 | 47 |
| 39 void ResourceCoordinatorInterface::ConnectToService( | 48 void ResourceCoordinatorInterface::ConnectToService( |
| 40 service_manager::Connector* connector, | 49 service_manager::Connector* connector, |
| 41 const CoordinationUnitType& type, | 50 const CoordinationUnitID& cu_id) { |
| 42 const std::string& id) { | |
| 43 DCHECK(thread_checker_.CalledOnValidThread()); | 51 DCHECK(thread_checker_.CalledOnValidThread()); |
| 44 DCHECK(connector); | 52 DCHECK(connector); |
| 45 mojom::CoordinationUnitProviderPtr provider; | 53 mojom::CoordinationUnitProviderPtr provider; |
| 46 connector->BindInterface(mojom::kServiceName, mojo::MakeRequest(&provider)); | 54 connector->BindInterface(mojom::kServiceName, mojo::MakeRequest(&provider)); |
| 47 | 55 |
| 48 CoordinationUnitID new_cu_id(type, id); | 56 provider->CreateCoordinationUnit(mojo::MakeRequest(&service_), cu_id); |
| 49 | |
| 50 provider->CreateCoordinationUnit(mojo::MakeRequest(&service_), new_cu_id); | |
| 51 | 57 |
| 52 service_.set_connection_error_handler(base::Bind(&OnConnectionError)); | 58 service_.set_connection_error_handler(base::Bind(&OnConnectionError)); |
| 53 } | 59 } |
| 54 | 60 |
| 55 void ResourceCoordinatorInterface::SendEvent( | 61 void ResourceCoordinatorInterface::SendEvent( |
| 56 const mojom::EventType& event_type) { | 62 const mojom::EventType& event_type) { |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 58 mojom::EventPtr event = mojom::Event::New(); | 64 mojom::EventPtr event = mojom::Event::New(); |
| 59 event->type = event_type; | 65 event->type = event_type; |
| 60 | 66 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 71 weak_ptr_factory_.GetWeakPtr())); | 77 weak_ptr_factory_.GetWeakPtr())); |
| 72 } | 78 } |
| 73 | 79 |
| 74 void ResourceCoordinatorInterface::AddChildByID( | 80 void ResourceCoordinatorInterface::AddChildByID( |
| 75 const CoordinationUnitID& child_id) { | 81 const CoordinationUnitID& child_id) { |
| 76 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
| 77 service_->AddChild(child_id); | 83 service_->AddChild(child_id); |
| 78 } | 84 } |
| 79 | 85 |
| 80 } // namespace resource_coordinator | 86 } // namespace resource_coordinator |
| OLD | NEW |