// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDER_MAP_H_ #define MOJO_PUBLIC_CPP_BINDINGS_BINDER_MAP_H_ #include <map> #include <string> #include <type_traits> #include <vector> #include "base/component_export.h" #include "base/containers/contains.h" #include "base/functional/callback.h" #include "base/memory/scoped_refptr.h" #include "base/task/sequenced_task_runner.h" #include "mojo/public/cpp/bindings/generic_pending_receiver.h" #include "mojo/public/cpp/bindings/lib/binder_map_internal.h" namespace mojo { // BinderMapWithContext is a helper class that maintains a registry of // callbacks that bind receivers for arbitrary Mojo interfaces. By default the // map is empty and cannot bind any interfaces. // // Call |Add()| to register a new binder for a specific interface. // Call |TryBind()| to attempt to run a registered binder on the generic // input receiver. If a suitable binder is found, it will take ownership of the // receiver. // // If a non-void ContextType is specified, registered callbacks must accept an // additional ContextType argument, and each invocation of |TryBind()| must // provide such a value. // // NOTE: Most common uses of BinderMapWithContext do not require a context value // per bind request. Use the BinderMap alias defined below this class in such // cases. template <typename ContextType> class BinderMapWithContext { … }; // Common alias for BinderMapWithContext that has no context. Binders added to // this type of map will only take a single PendingReceiver<T> argument (or a // GenericPendingReceiver). class BinderMap : public BinderMapWithContext<void> { … }; } // namespace mojo #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDER_MAP_H_