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

Unified Diff: services/service_manager/public/cpp/connector.h

Issue 2804373002: Eliminate Connector::Connect(), Connection, etc. (Closed)
Patch Set: . Created 3 years, 8 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/service_manager/public/cpp/connector.h
diff --git a/services/service_manager/public/cpp/connector.h b/services/service_manager/public/cpp/connector.h
index 37d833815445f21a456b900f3c087edaeeb462ac..ae15116292acc928d3a5150fd84bcdfb1a675411 100644
--- a/services/service_manager/public/cpp/connector.h
+++ b/services/service_manager/public/cpp/connector.h
@@ -7,7 +7,6 @@
#include <memory>
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/interfaces/connector.mojom.h"
#include "services/service_manager/public/interfaces/service.mojom.h"
@@ -17,27 +16,31 @@ namespace service_manager {
// An interface that encapsulates the Service Manager's brokering interface, by
// which
-// connections between services are established. Once Connect() is called,
-// this class is bound to the thread the call was made on and it cannot be
-// passed to another thread without calling Clone().
+// connections between services are established. Once either StartService() or
+// BindInterface() is called, this class is bound to the thread the call was
+// made on and it cannot be passed to another thread without calling Clone().
//
// An instance of this class is created internally by ServiceContext for use
// on the thread ServiceContext is instantiated on.
//
// To use this interface on another thread, call Clone() and pass the new
-// instance to the desired thread before calling Connect().
+// instance to the desired thread before calling StartService() or
+// BindInterface().
//
// While instances of this object are owned by the caller, the underlying
// connection with the service manager is bound to the lifetime of the instance
-// that
-// created it, i.e. when the application is terminated the Connector pipe is
-// closed.
+// that created it, i.e. when the application is terminated the Connector pipe
+// is closed.
class Connector {
public:
+ using StartServiceCallback =
+ base::Callback<void(mojom::ConnectResult, const Identity& identity)>;
+
class TestApi {
public:
using Binder = base::Callback<void(mojo::ScopedMessagePipeHandle)>;
explicit TestApi(Connector* connector) : connector_(connector) {}
+ ~TestApi() { connector_->ResetStartServiceCallback(); }
// Allows caller to specify a callback to bind requests for |interface_name|
// from |service_name| locally, rather than passing the request through the
@@ -50,6 +53,13 @@ class Connector {
}
void ClearBinderOverrides() { connector_->ClearBinderOverrides(); }
+ // Register a callback to be run with the result of an attempt to start a
+ // service. This will be run in response to calls to StartService() or
+ // BindInterface().
+ void SetStartServiceCallback(const StartServiceCallback& callback) {
+ connector_->SetStartServiceCallback(callback);
+ }
+
private:
Connector* connector_;
};
@@ -60,22 +70,20 @@ class Connector {
// for the other end the Connector's interface.
static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request);
+ // Creates an instance of a service for |identity|.
+ virtual void StartService(const Identity& identity) = 0;
+
+ // Creates an instance of the service |name| inheriting the caller's identity.
+ virtual void StartService(const std::string& name) = 0;
+
// Creates an instance of a service for |identity| in a process started by the
- // client (or someone else). Must be called before Connect() may be called to
- // |identity|.
+ // client (or someone else). Must be called before BindInterface() may be
+ // called to |identity|.
virtual void StartService(
const Identity& identity,
mojom::ServicePtr service,
mojom::PIDReceiverRequest pid_receiver_request) = 0;
- // Requests a new connection to a service. Returns a pointer to the
- // connection if the connection is permitted by that service, nullptr
- // otherwise. Once this method is called, this object is bound to the thread
- // on which the call took place. To pass to another thread, call Clone() and
- // pass the result.
- virtual std::unique_ptr<Connection> Connect(const std::string& name) = 0;
- virtual std::unique_ptr<Connection> Connect(const Identity& target) = 0;
-
// Connect to |target| & request to bind |Interface|.
template <typename Interface>
void BindInterface(const Identity& target,
@@ -100,8 +108,9 @@ class Connector {
mojo::ScopedMessagePipeHandle interface_pipe) = 0;
// Creates a new instance of this class which may be passed to another thread.
- // The returned object may be passed multiple times until Connect() is called,
- // at which point this method must be called again to pass again.
+ // The returned object may be passed multiple times until StartService() or
+ // BindInterface() is called, at which point this method must be called again
+ // to pass again.
virtual std::unique_ptr<Connector> Clone() = 0;
// Binds a Connector request to the other end of this Connector.
@@ -114,6 +123,9 @@ class Connector {
const std::string& interface_name,
const TestApi::Binder& binder) = 0;
virtual void ClearBinderOverrides() = 0;
+ virtual void SetStartServiceCallback(
+ const StartServiceCallback& callback) = 0;
+ virtual void ResetStartServiceCallback() = 0;
};
} // namespace service_manager

Powered by Google App Engine
This is Rietveld 408576698