Commit 1cf2e1c8 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert GraphExecutor from graph_executor.mojom to new Mojo types

This CL converts GraphExecutor graph_executor.mojom to new Mojo types
using PendingReceiver, ReceiverSet, and Remote.

Bug: 955171
Change-Id: I4ef4ad439b4eaa7b6e607a734f8f04a9a84776cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1850681
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarAndrew Moylan <amoylan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708631}
parent 52a72af8
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chromeos/services/machine_learning/public/mojom/model.mojom.h" #include "chromeos/services/machine_learning/public/mojom/model.mojom.h"
#include "chromeos/services/machine_learning/public/mojom/tensor.mojom.h" #include "chromeos/services/machine_learning/public/mojom/tensor.mojom.h"
#include "mojo/public/cpp/bindings/map.h" #include "mojo/public/cpp/bindings/map.h"
#include "mojo/public/cpp/bindings/remote.h"
using ::chromeos::machine_learning::mojom::BuiltinModelId; using ::chromeos::machine_learning::mojom::BuiltinModelId;
using ::chromeos::machine_learning::mojom::BuiltinModelSpec; using ::chromeos::machine_learning::mojom::BuiltinModelSpec;
...@@ -78,11 +79,11 @@ class MlServiceClientImpl : public MlServiceClient { ...@@ -78,11 +79,11 @@ class MlServiceClientImpl : public MlServiceClient {
// available. // available.
void InitMlServiceHandlesIfNeeded(); void InitMlServiceHandlesIfNeeded();
void OnConnectionError(); void OnMojoDisconnect();
// Pointers used to execute functions in the ML service server end. // Pointers used to execute functions in the ML service server end.
::chromeos::machine_learning::mojom::ModelPtr model_; ::chromeos::machine_learning::mojom::ModelPtr model_;
::chromeos::machine_learning::mojom::GraphExecutorPtr executor_; mojo::Remote<::chromeos::machine_learning::mojom::GraphExecutor> executor_;
base::WeakPtrFactory<MlServiceClientImpl> weak_factory_{this}; base::WeakPtrFactory<MlServiceClientImpl> weak_factory_{this};
...@@ -145,15 +146,15 @@ void MlServiceClientImpl::InitMlServiceHandlesIfNeeded() { ...@@ -145,15 +146,15 @@ void MlServiceClientImpl::InitMlServiceHandlesIfNeeded() {
if (!executor_) { if (!executor_) {
// Get the graph executor. // Get the graph executor.
model_->CreateGraphExecutor( model_->CreateGraphExecutor(
mojo::MakeRequest(&executor_), executor_.BindNewPipeAndPassReceiver(),
base::BindOnce(&MlServiceClientImpl::CreateGraphExecutorCallback, base::BindOnce(&MlServiceClientImpl::CreateGraphExecutorCallback,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
executor_.set_connection_error_handler(base::BindOnce( executor_.set_disconnect_handler(base::BindOnce(
&MlServiceClientImpl::OnConnectionError, weak_factory_.GetWeakPtr())); &MlServiceClientImpl::OnMojoDisconnect, weak_factory_.GetWeakPtr()));
} }
} }
void MlServiceClientImpl::OnConnectionError() { void MlServiceClientImpl::OnMojoDisconnect() {
// TODO(crbug.com/893425): Log to UMA. // TODO(crbug.com/893425): Log to UMA.
LOG(WARNING) << "Mojo connection for ML service closed."; LOG(WARNING) << "Mojo connection for ML service closed.";
executor_.reset(); executor_.reset();
......
...@@ -31,9 +31,9 @@ void FakeServiceConnectionImpl::LoadFlatBufferModel( ...@@ -31,9 +31,9 @@ void FakeServiceConnectionImpl::LoadFlatBufferModel(
} }
void FakeServiceConnectionImpl::CreateGraphExecutor( void FakeServiceConnectionImpl::CreateGraphExecutor(
mojom::GraphExecutorRequest request, mojo::PendingReceiver<mojom::GraphExecutor> receiver,
mojom::Model::CreateGraphExecutorCallback callback) { mojom::Model::CreateGraphExecutorCallback callback) {
graph_bindings_.AddBinding(this, std::move(request)); graph_receivers_.Add(this, std::move(receiver));
std::move(callback).Run(mojom::CreateGraphExecutorResult::OK); std::move(callback).Run(mojom::CreateGraphExecutorResult::OK);
} }
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "chromeos/services/machine_learning/public/mojom/graph_executor.mojom.h" #include "chromeos/services/machine_learning/public/mojom/graph_executor.mojom.h"
#include "chromeos/services/machine_learning/public/mojom/model.mojom.h" #include "chromeos/services/machine_learning/public/mojom/model.mojom.h"
#include "chromeos/services/machine_learning/public/mojom/tensor.mojom.h" #include "chromeos/services/machine_learning/public/mojom/tensor.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h" #include "mojo/public/cpp/bindings/receiver_set.h"
...@@ -46,7 +45,7 @@ class FakeServiceConnectionImpl : public ServiceConnection, ...@@ -46,7 +45,7 @@ class FakeServiceConnectionImpl : public ServiceConnection,
// mojom::Model: // mojom::Model:
void CreateGraphExecutor( void CreateGraphExecutor(
mojom::GraphExecutorRequest request, mojo::PendingReceiver<mojom::GraphExecutor> receiver,
mojom::Model::CreateGraphExecutorCallback callback) override; mojom::Model::CreateGraphExecutorCallback callback) override;
// mojom::GraphExecutor: // mojom::GraphExecutor:
...@@ -61,7 +60,7 @@ class FakeServiceConnectionImpl : public ServiceConnection, ...@@ -61,7 +60,7 @@ class FakeServiceConnectionImpl : public ServiceConnection,
private: private:
mojo::ReceiverSet<mojom::Model> model_receivers_; mojo::ReceiverSet<mojom::Model> model_receivers_;
mojo::BindingSet<mojom::GraphExecutor> graph_bindings_; mojo::ReceiverSet<mojom::GraphExecutor> graph_receivers_;
mojom::TensorPtr execute_result_; mojom::TensorPtr execute_result_;
DISALLOW_COPY_AND_ASSIGN(FakeServiceConnectionImpl); DISALLOW_COPY_AND_ASSIGN(FakeServiceConnectionImpl);
......
...@@ -99,9 +99,9 @@ TEST_F(ServiceConnectionTest, FakeServiceConnectionForBuiltinModel) { ...@@ -99,9 +99,9 @@ TEST_F(ServiceConnectionTest, FakeServiceConnectionForBuiltinModel) {
ASSERT_TRUE(model.is_bound()); ASSERT_TRUE(model.is_bound());
callback_done = false; callback_done = false;
mojom::GraphExecutorPtr graph; mojo::Remote<mojom::GraphExecutor> graph;
model->CreateGraphExecutor( model->CreateGraphExecutor(
mojo::MakeRequest(&graph), graph.BindNewPipeAndPassReceiver(),
base::BindOnce( base::BindOnce(
[](bool* callback_done, mojom::CreateGraphExecutorResult result) { [](bool* callback_done, mojom::CreateGraphExecutorResult result) {
EXPECT_EQ(result, mojom::CreateGraphExecutorResult::OK); EXPECT_EQ(result, mojom::CreateGraphExecutorResult::OK);
...@@ -160,9 +160,9 @@ TEST_F(ServiceConnectionTest, FakeServiceConnectionForFlatBufferModel) { ...@@ -160,9 +160,9 @@ TEST_F(ServiceConnectionTest, FakeServiceConnectionForFlatBufferModel) {
ASSERT_TRUE(model.is_bound()); ASSERT_TRUE(model.is_bound());
callback_done = false; callback_done = false;
mojom::GraphExecutorPtr graph; mojo::Remote<mojom::GraphExecutor> graph;
model->CreateGraphExecutor( model->CreateGraphExecutor(
mojo::MakeRequest(&graph), graph.BindNewPipeAndPassReceiver(),
base::BindOnce( base::BindOnce(
[](bool* callback_done, mojom::CreateGraphExecutorResult result) { [](bool* callback_done, mojom::CreateGraphExecutorResult result) {
EXPECT_EQ(result, mojom::CreateGraphExecutorResult::OK); EXPECT_EQ(result, mojom::CreateGraphExecutorResult::OK);
......
...@@ -78,6 +78,6 @@ struct FlatBufferModelSpec { ...@@ -78,6 +78,6 @@ struct FlatBufferModelSpec {
// interface pipe. The Model interface pipe can be used to acquire multiple // interface pipe. The Model interface pipe can be used to acquire multiple
// separate GraphExecutor instances. // separate GraphExecutor instances.
interface Model { interface Model {
CreateGraphExecutor(GraphExecutor& request) => CreateGraphExecutor(pending_receiver<GraphExecutor> receiver) =>
(CreateGraphExecutorResult result); (CreateGraphExecutorResult result);
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment