| Index: services/service_manager/public/cpp/interface_binder.h
|
| diff --git a/services/service_manager/public/cpp/interface_binder.h b/services/service_manager/public/cpp/interface_binder.h
|
| index 51aab0144e5e373c332fc70433f37e1787465d7f..0f4845bab1168e76bd4f73f5c0c66636333606b8 100644
|
| --- a/services/service_manager/public/cpp/interface_binder.h
|
| +++ b/services/service_manager/public/cpp/interface_binder.h
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2015 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.
|
|
|
| @@ -6,7 +6,10 @@
|
| #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_BINDER_H_
|
|
|
| #include <string>
|
| +#include <utility>
|
|
|
| +#include "base/bind.h"
|
| +#include "mojo/public/cpp/bindings/interface_request.h"
|
| #include "mojo/public/cpp/system/message_pipe.h"
|
|
|
| namespace service_manager {
|
| @@ -25,6 +28,67 @@ class InterfaceBinder {
|
| mojo::ScopedMessagePipeHandle handle) = 0;
|
| };
|
|
|
| +template <typename Interface>
|
| +class CallbackBinder : public InterfaceBinder {
|
| + public:
|
| + using BindCallback = base::Callback<void(const BindSourceInfo&,
|
| + mojo::InterfaceRequest<Interface>)>;
|
| +
|
| + CallbackBinder(const BindCallback& callback,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
|
| + : callback_(callback), task_runner_(task_runner) {}
|
| + ~CallbackBinder() override {}
|
| +
|
| + private:
|
| + // InterfaceBinder:
|
| + void BindInterface(const BindSourceInfo& source_info,
|
| + const std::string& interface_name,
|
| + mojo::ScopedMessagePipeHandle handle) override {
|
| + mojo::InterfaceRequest<Interface> request =
|
| + mojo::MakeRequest<Interface>(std::move(handle));
|
| + if (task_runner_) {
|
| + task_runner_->PostTask(FROM_HERE,
|
| + base::Bind(&CallbackBinder::RunCallback, callback_,
|
| + source_info, base::Passed(&request)));
|
| + } else {
|
| + RunCallback(callback_, source_info, std::move(request));
|
| + }
|
| + }
|
| +
|
| + static void RunCallback(const BindCallback& callback,
|
| + const BindSourceInfo& source_info,
|
| + mojo::InterfaceRequest<Interface> request) {
|
| + callback.Run(source_info, std::move(request));
|
| + }
|
| +
|
| + const BindCallback callback_;
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
| + DISALLOW_COPY_AND_ASSIGN(CallbackBinder);
|
| +};
|
| +
|
| +class GenericCallbackBinder : public InterfaceBinder {
|
| + public:
|
| + using BindCallback = base::Callback<void(mojo::ScopedMessagePipeHandle)>;
|
| +
|
| + GenericCallbackBinder(
|
| + const BindCallback& callback,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
|
| + ~GenericCallbackBinder() override;
|
| +
|
| + private:
|
| + // InterfaceBinder:
|
| + void BindInterface(const BindSourceInfo& source_info,
|
| + const std::string& interface_name,
|
| + mojo::ScopedMessagePipeHandle handle) override;
|
| +
|
| + static void RunCallback(const BindCallback& callback,
|
| + mojo::ScopedMessagePipeHandle client_handle);
|
| +
|
| + const BindCallback callback_;
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
| + DISALLOW_COPY_AND_ASSIGN(GenericCallbackBinder);
|
| +};
|
| +
|
| } // namespace service_manager
|
|
|
| #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_BINDER_H_
|
|
|