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

Unified Diff: mojo/public/cpp/bindings/lib/interface_ptr_state.h

Issue 2498743002: Mojo: introducing a thread safe interface pointer. (Closed)
Patch Set: Mojo: introducing a thread safe interface pointer. Created 4 years, 1 month 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: mojo/public/cpp/bindings/lib/interface_ptr_state.h
diff --git a/mojo/public/cpp/bindings/lib/interface_ptr_state.h b/mojo/public/cpp/bindings/lib/interface_ptr_state.h
index 83379521c6cb103d471efcd73c9ea9ccb8d437ea..a08b6853b099a1ba8f1a35c09b673ba1c0409c15 100644
--- a/mojo/public/cpp/bindings/lib/interface_ptr_state.h
+++ b/mojo/public/cpp/bindings/lib/interface_ptr_state.h
@@ -18,6 +18,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "mojo/public/cpp/bindings/associated_group.h"
#include "mojo/public/cpp/bindings/connection_error_callback.h"
@@ -209,7 +210,7 @@ class InterfacePtrState<Interface, false> {
template <typename Interface>
class InterfacePtrState<Interface, true> {
public:
- InterfacePtrState() : version_(0u) {}
+ InterfacePtrState() : version_(0u), weak_ptr_factory_(this) {}
~InterfacePtrState() {
endpoint_client_.reset();
@@ -331,6 +332,17 @@ class InterfacePtrState<Interface, true> {
router_->EnableTestingMode();
}
+ base::Callback<void(Message)> GetThreadSafePtrAcceptCallback() {
+ return base::Bind(&InterfacePtrState::ForwardMessage,
+ weak_ptr_factory_.GetWeakPtr());
+ }
+
+ base::Callback<void(Message, std::unique_ptr<MessageReceiver>)>
+ GetThreadSafePtrAcceptWithResponderCallback() {
+ return base::Bind(&InterfacePtrState::ForwardMessageWithResponder,
+ weak_ptr_factory_.GetWeakPtr());
+ }
+
private:
using Proxy = typename Interface::Proxy_;
@@ -361,10 +373,8 @@ class InterfacePtrState<Interface, true> {
// will not be used.
0u));
proxy_.reset(new Proxy(endpoint_client_.get()));
- if (Interface::PassesAssociatedKinds_) {
- proxy_->serialization_context()->group_controller =
- endpoint_client_->group_controller();
- }
+ if (Interface::PassesAssociatedKinds_)
+ proxy_->set_group_controller(endpoint_client_->group_controller());
}
void OnQueryVersion(const base::Callback<void(uint32_t)>& callback,
@@ -373,6 +383,17 @@ class InterfacePtrState<Interface, true> {
callback.Run(version);
}
+ void ForwardMessage(Message message) {
+ ConfigureProxyIfNecessary();
+ endpoint_client_->Accept(&message);
+ }
+
+ void ForwardMessageWithResponder(Message message,
+ std::unique_ptr<MessageReceiver> responder) {
+ ConfigureProxyIfNecessary();
+ endpoint_client_->AcceptWithResponder(&message, responder.release());
+ }
+
scoped_refptr<MultiplexRouter> router_;
std::unique_ptr<InterfaceEndpointClient> endpoint_client_;
@@ -386,6 +407,8 @@ class InterfacePtrState<Interface, true> {
uint32_t version_;
+ base::WeakPtrFactory<InterfacePtrState> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(InterfacePtrState);
};

Powered by Google App Engine
This is Rietveld 408576698