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

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

Issue 2860943002: Flatten interface_binder.h and callback_binder.h (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/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_
« no previous file with comments | « services/service_manager/public/cpp/binder_registry.h ('k') | services/service_manager/public/cpp/interface_binder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698