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

Unified Diff: services/resource_coordinator/public/cpp/resource_coordinator_interface.cc

Issue 2798713002: Global Resource Coordinator: Basic service internals (Closed)
Patch Set: Buildfix after rebase Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: services/resource_coordinator/public/cpp/resource_coordinator_interface.cc
diff --git a/services/resource_coordinator/public/cpp/resource_coordinator_interface.cc b/services/resource_coordinator/public/cpp/resource_coordinator_interface.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7e25a5c816dfd7743ef356a149d4375c926e61bc
--- /dev/null
+++ b/services/resource_coordinator/public/cpp/resource_coordinator_interface.cc
@@ -0,0 +1,80 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/resource_coordinator/public/cpp/resource_coordinator_interface.h"
+
+#include "mojo/public/cpp/bindings/binding.h"
+#include "services/resource_coordinator/public/interfaces/coordination_unit_provider.mojom.h"
+#include "services/resource_coordinator/public/interfaces/service_constants.mojom.h"
+#include "services/service_manager/public/cpp/connector.h"
+
+namespace {
+
+void OnConnectionError() {
+ DCHECK(false);
+}
+
+} // namespace
+
+namespace resource_coordinator {
+
+ResourceCoordinatorInterface::ResourceCoordinatorInterface(
+ service_manager::Connector* connector,
+ const CoordinationUnitType& type)
+ : weak_ptr_factory_(this) {
+ ConnectToService(connector, type, std::string());
+}
+
+ResourceCoordinatorInterface::ResourceCoordinatorInterface(
+ service_manager::Connector* connector,
+ const CoordinationUnitType& type,
+ const std::string& id)
+ : weak_ptr_factory_(this) {
+ ConnectToService(connector, type, id);
+}
+
+ResourceCoordinatorInterface::~ResourceCoordinatorInterface() = default;
+
+void ResourceCoordinatorInterface::ConnectToService(
+ service_manager::Connector* connector,
+ const CoordinationUnitType& type,
+ const std::string& id) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(connector);
+ mojom::CoordinationUnitProviderPtr provider;
+ connector->BindInterface(mojom::kServiceName, mojo::MakeRequest(&provider));
+
+ CoordinationUnitID new_cu_id(type, id);
+
+ provider->CreateCoordinationUnit(mojo::MakeRequest(&service_), new_cu_id);
+
+ service_.set_connection_error_handler(base::Bind(&OnConnectionError));
+}
+
+void ResourceCoordinatorInterface::SendEvent(
+ const mojom::EventType& event_type) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ mojom::EventPtr event = mojom::Event::New();
+ event->type = event_type;
+
+ service_->SendEvent(std::move(event));
+}
+
+void ResourceCoordinatorInterface::AddChild(
+ const ResourceCoordinatorInterface& child) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(service_);
+ // We could keep the ID around ourselves, but this hop ensures that the child
+ // has been created on the service-side.
+ child.service()->GetID(base::Bind(&ResourceCoordinatorInterface::AddChildByID,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void ResourceCoordinatorInterface::AddChildByID(
+ const CoordinationUnitID& child_id) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ service_->AddChild(child_id);
+}
+
+} // namespace resource_coordinator

Powered by Google App Engine
This is Rietveld 408576698