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

Side by Side Diff: mojo/public/cpp/bindings/lib/binding_state.h

Issue 2608163003: Change single-interface mojo bindings to use SequencedTaskRunner. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/sequenced_task_runner.h"
19 #include "mojo/public/cpp/bindings/associated_group.h" 19 #include "mojo/public/cpp/bindings/associated_group.h"
20 #include "mojo/public/cpp/bindings/bindings_export.h" 20 #include "mojo/public/cpp/bindings/bindings_export.h"
21 #include "mojo/public/cpp/bindings/connection_error_callback.h" 21 #include "mojo/public/cpp/bindings/connection_error_callback.h"
22 #include "mojo/public/cpp/bindings/filter_chain.h" 22 #include "mojo/public/cpp/bindings/filter_chain.h"
23 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" 23 #include "mojo/public/cpp/bindings/interface_endpoint_client.h"
24 #include "mojo/public/cpp/bindings/interface_id.h" 24 #include "mojo/public/cpp/bindings/interface_id.h"
25 #include "mojo/public/cpp/bindings/interface_ptr.h" 25 #include "mojo/public/cpp/bindings/interface_ptr.h"
26 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 26 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
27 #include "mojo/public/cpp/bindings/interface_request.h" 27 #include "mojo/public/cpp/bindings/interface_request.h"
28 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 28 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 AssociatedGroup* associated_group() { 72 AssociatedGroup* associated_group() {
73 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; 73 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr;
74 } 74 }
75 75
76 void FlushForTesting(); 76 void FlushForTesting();
77 77
78 void EnableTestingMode(); 78 void EnableTestingMode();
79 79
80 protected: 80 protected:
81 void BindInternal(ScopedMessagePipeHandle handle, 81 void BindInternal(ScopedMessagePipeHandle handle,
82 scoped_refptr<base::SingleThreadTaskRunner> runner, 82 scoped_refptr<base::SequencedTaskRunner> runner,
83 const char* interface_name, 83 const char* interface_name,
84 std::unique_ptr<MessageReceiver> request_validator, 84 std::unique_ptr<MessageReceiver> request_validator,
85 bool passes_associated_kinds, 85 bool passes_associated_kinds,
86 bool has_sync_methods, 86 bool has_sync_methods,
87 MessageReceiverWithResponderStatus* stub, 87 MessageReceiverWithResponderStatus* stub,
88 uint32_t interface_version); 88 uint32_t interface_version);
89 89
90 scoped_refptr<internal::MultiplexRouter> router_; 90 scoped_refptr<internal::MultiplexRouter> router_;
91 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; 91 std::unique_ptr<InterfaceEndpointClient> endpoint_client_;
92 }; 92 };
93 93
94 template <typename Interface, typename ImplRefTraits> 94 template <typename Interface, typename ImplRefTraits>
95 class BindingState : public BindingStateBase { 95 class BindingState : public BindingStateBase {
96 public: 96 public:
97 using ImplPointerType = typename ImplRefTraits::PointerType; 97 using ImplPointerType = typename ImplRefTraits::PointerType;
98 98
99 explicit BindingState(ImplPointerType impl) { 99 explicit BindingState(ImplPointerType impl) {
100 stub_.set_sink(std::move(impl)); 100 stub_.set_sink(std::move(impl));
101 } 101 }
102 102
103 ~BindingState() { Close(); } 103 ~BindingState() { Close(); }
104 104
105 void Bind(ScopedMessagePipeHandle handle, 105 void Bind(ScopedMessagePipeHandle handle,
106 scoped_refptr<base::SingleThreadTaskRunner> runner) { 106 scoped_refptr<base::SequencedTaskRunner> runner) {
107 BindingStateBase::BindInternal( 107 BindingStateBase::BindInternal(
108 std::move(handle), runner, Interface::Name_, 108 std::move(handle), runner, Interface::Name_,
109 base::MakeUnique<typename Interface::RequestValidator_>(), 109 base::MakeUnique<typename Interface::RequestValidator_>(),
110 Interface::PassesAssociatedKinds_, Interface::HasSyncMethods_, &stub_, 110 Interface::PassesAssociatedKinds_, Interface::HasSyncMethods_, &stub_,
111 Interface::Version_); 111 Interface::Version_);
112 if (Interface::PassesAssociatedKinds_) 112 if (Interface::PassesAssociatedKinds_)
113 stub_.serialization_context()->group_controller = router_; 113 stub_.serialization_context()->group_controller = router_;
114 } 114 }
115 115
116 InterfaceRequest<Interface> Unbind() { 116 InterfaceRequest<Interface> Unbind() {
117 endpoint_client_.reset(); 117 endpoint_client_.reset();
118 InterfaceRequest<Interface> request = 118 InterfaceRequest<Interface> request =
119 MakeRequest<Interface>(router_->PassMessagePipe()); 119 MakeRequest<Interface>(router_->PassMessagePipe());
120 router_ = nullptr; 120 router_ = nullptr;
121 return request; 121 return request;
122 } 122 }
123 123
124 Interface* impl() { return ImplRefTraits::GetRawPointer(&stub_.sink()); } 124 Interface* impl() { return ImplRefTraits::GetRawPointer(&stub_.sink()); }
125 125
126 private: 126 private:
127 typename Interface::template Stub_<ImplRefTraits> stub_; 127 typename Interface::template Stub_<ImplRefTraits> stub_;
128 128
129 DISALLOW_COPY_AND_ASSIGN(BindingState); 129 DISALLOW_COPY_AND_ASSIGN(BindingState);
130 }; 130 };
131 131
132 } // namesapce internal 132 } // namesapce internal
133 } // namespace mojo 133 } // namespace mojo
134 134
135 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ 135 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h ('k') | mojo/public/cpp/bindings/lib/binding_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698