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

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

Issue 2857963004: Flatten Connector & ConnectorImpl (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
« no previous file with comments | « services/service_manager/public/cpp/BUILD.gn ('k') | services/service_manager/public/cpp/connector.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9f2322874e6b5f23004dbcd43740f8e9ddcb4a48..f21e2d3edf355a5c38a24abd496a7bc16fc526c3 100644
--- a/services/service_manager/public/cpp/connector.h
+++ b/services/service_manager/public/cpp/connector.h
@@ -1,12 +1,15 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// 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.
#ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_
#define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTOR_H_
+#include <map>
#include <memory>
+#include "base/callback.h"
+#include "base/threading/thread_checker.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"
@@ -64,25 +67,26 @@ class Connector {
Connector* connector_;
};
- virtual ~Connector() {}
+ explicit Connector(mojom::ConnectorPtrInfo unbound_state);
+ explicit Connector(mojom::ConnectorPtr connector);
+ ~Connector();
// Creates a new Connector instance and fills in |*request| with a request
// 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;
+ void StartService(const Identity& identity);
// Creates an instance of the service |name| inheriting the caller's identity.
- virtual void StartService(const std::string& name) = 0;
+ void StartService(const std::string& name);
// Creates an instance of a service for |identity| in a process started by the
// 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;
+ void StartService(const Identity& identity,
+ mojom::ServicePtr service,
+ mojom::PIDReceiverRequest pid_receiver_request);
// Connect to |target| & request to bind |Interface|.
template <typename Interface>
@@ -103,34 +107,55 @@ class Connector {
return BindInterface(Identity(name, mojom::kInheritUserID),
Interface::Name_, request.PassMessagePipe());
}
- virtual void BindInterface(const Identity& target,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe) = 0;
+ void BindInterface(const Identity& target,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe);
// Creates a new instance of this class which may be passed to another thread.
// 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;
+ std::unique_ptr<Connector> Clone();
- virtual void FilterInterfaces(const std::string& spec,
- const Identity& source_identity,
- mojom::InterfaceProviderRequest request,
- mojom::InterfaceProviderPtr target) = 0;
+ void FilterInterfaces(const std::string& spec,
+ const Identity& source_identity,
+ mojom::InterfaceProviderRequest request,
+ mojom::InterfaceProviderPtr target);
// Binds a Connector request to the other end of this Connector.
- virtual void BindConnectorRequest(mojom::ConnectorRequest request) = 0;
-
- virtual base::WeakPtr<Connector> GetWeakPtr() = 0;
-
- protected:
- virtual void OverrideBinderForTesting(const std::string& service_name,
- 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;
+ void BindConnectorRequest(mojom::ConnectorRequest request);
+
+ base::WeakPtr<Connector> GetWeakPtr();
+
+ private:
+ using BinderOverrideMap = std::map<std::string, TestApi::Binder>;
+
+ void OnConnectionError();
+
+ void OverrideBinderForTesting(const std::string& service_name,
+ const std::string& interface_name,
+ const TestApi::Binder& binder);
+ void ClearBinderOverrides();
+ void SetStartServiceCallback(const StartServiceCallback& callback);
+ void ResetStartServiceCallback();
+
+ bool BindConnectorIfNecessary();
+
+ // Callback passed to mojom methods StartService()/BindInterface().
+ void RunStartServiceCallback(mojom::ConnectResult result,
+ const Identity& user_id);
+
+ mojom::ConnectorPtrInfo unbound_state_;
+ mojom::ConnectorPtr connector_;
+
+ base::ThreadChecker thread_checker_;
+
+ std::map<std::string, BinderOverrideMap> local_binder_overrides_;
+ StartServiceCallback start_service_callback_;
+
+ base::WeakPtrFactory<Connector> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(Connector);
};
} // namespace service_manager
« no previous file with comments | « services/service_manager/public/cpp/BUILD.gn ('k') | services/service_manager/public/cpp/connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698