Chromium Code Reviews| 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/public/cpp/resource_coordinator_interfac e.h" | |
| 6 | |
| 7 #include "base/process/process_handle.h" | |
| 8 #include "base/strings/string_number_conversions.h" | |
| 9 #include "mojo/public/cpp/bindings/binding.h" | |
| 10 #include "services/resource_coordinator/public/interfaces/coordination_unit_prov ider.mojom.h" | |
| 11 #include "services/resource_coordinator/public/interfaces/service_constants.mojo m.h" | |
| 12 #include "services/service_manager/public/cpp/connector.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 void OnConnectionError() { | |
| 17 CHECK(false); | |
| 18 } | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 namespace resource_coordinator { | |
| 23 | |
| 24 ResourceCoordinatorInterface::ResourceCoordinatorInterface( | |
| 25 service_manager::Connector* connector, | |
| 26 const CoordinationUnitType& type) | |
| 27 : weak_ptr_factory_(this) { | |
| 28 static int next_id = 0; | |
|
Primiano Tucci (use gerrit)
2017/04/06 18:09:47
you might be bitten by this in component builds si
oystein (OOO til 10th of July)
2017/04/10 20:03:00
Yikes. Done.
| |
| 29 std::string id = base::IntToString(base::GetCurrentProcId()) + "." + | |
| 30 base::IntToString(++next_id); | |
| 31 ConnectToService(connector, type, id); | |
| 32 } | |
| 33 | |
| 34 ResourceCoordinatorInterface::~ResourceCoordinatorInterface() = default; | |
| 35 | |
| 36 void ResourceCoordinatorInterface::ConnectToService( | |
| 37 service_manager::Connector* connector, | |
| 38 const CoordinationUnitType& type, | |
| 39 const std::string& id) { | |
| 40 DCHECK(connector); | |
| 41 mojom::CoordinationUnitProviderPtr provider; | |
| 42 connector->BindInterface(mojom::kServiceName, mojo::MakeRequest(&provider)); | |
| 43 | |
| 44 CoordinationUnitID new_cu_id(type, id); | |
| 45 | |
| 46 provider->CreateCoordinationUnit(mojo::MakeRequest(&service_), new_cu_id); | |
| 47 | |
| 48 service_.set_connection_error_handler(base::Bind(&OnConnectionError)); | |
| 49 } | |
| 50 | |
| 51 void ResourceCoordinatorInterface::SendEvent( | |
| 52 const resource_coordinator::EventType& event_type) { | |
| 53 DCHECK(service_); | |
|
Primiano Tucci (use gerrit)
2017/04/06 18:09:47
I think the patttern in chrome is to not DCHECK fo
oystein (OOO til 10th of July)
2017/04/10 20:03:00
Done.
| |
| 54 mojom::EventPtr event = mojom::Event::New(); | |
| 55 event->type = event_type; | |
| 56 | |
| 57 service_->SendEvent(std::move(event)); | |
| 58 } | |
| 59 | |
| 60 void ResourceCoordinatorInterface::AddChild( | |
| 61 const ResourceCoordinatorInterface& child) { | |
| 62 DCHECK(service_); | |
| 63 // We could keep the ID around ourselves, but this hop ensures that the child | |
| 64 // has been created on the service-side. | |
| 65 child.service()->GetID(base::Bind(&ResourceCoordinatorInterface::AddChildByID, | |
| 66 weak_ptr_factory_.GetWeakPtr())); | |
| 67 } | |
| 68 | |
| 69 void ResourceCoordinatorInterface::AddChildByID( | |
| 70 const CoordinationUnitID& child_id) { | |
| 71 service_->AddChild(child_id); | |
| 72 } | |
| 73 | |
| 74 } // namespace resource_coordinator | |
| OLD | NEW |