Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: services/resource_coordinator/public/cpp/resource_coordinator_interface.cc

Issue 2710823003: NOCOMMIT prototype: GRC service plumbing and process priority
Patch Set: Buildfixes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/constants.mojom.h"
11 #include "services/resource_coordinator/public/interfaces/coordination_unit_prov ider.mojom.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 mojom::IDType& type)
27 : weak_ptr_factory_(this) {
28 static int next_id = 0;
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 mojom::IDType& type,
39 const std::string& id) {
40 DCHECK(connector);
41 mojom::CoordinationUnitProviderPtr provider;
42 connector->BindInterface(mojom::kServiceName, mojo::MakeRequest(&provider));
43
44 mojom::CoordinationUnitIDPtr options = mojom::CoordinationUnitID::New();
45 options->type = type;
46 options->id = id;
47
48 provider->CreateCoordinationUnit(mojo::MakeRequest(&service_),
49 std::move(options));
50
51 service_.set_connection_error_handler(base::Bind(&OnConnectionError));
52 }
53
54 void ResourceCoordinatorInterface::SendEvent(
55 const resource_coordinator::mojom::EventType& event_type) {
56 DCHECK(service_);
57 mojom::EventPtr event = mojom::Event::New();
58 event->type = event_type;
59
60 service_->SendEvent(std::move(event));
61 }
62
63 void ResourceCoordinatorInterface::AddChild(
64 const ResourceCoordinatorInterface& child) {
65 DCHECK(service_);
66 // We could keep the ID around ourselves, but this hop ensures that the child
67 // has been created on the service-side.
68 child.service()->GetID(base::Bind(&ResourceCoordinatorInterface::AddChildByID,
69 weak_ptr_factory_.GetWeakPtr()));
70 }
71
72 void ResourceCoordinatorInterface::AddChildByID(
73 resource_coordinator::mojom::CoordinationUnitIDPtr child_id) {
74 service_->AddChild(std::move(child_id));
75 }
76
77 } // namespace resource_coordinator
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698