Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BINDING_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "mojo/public/cpp/bindings/interface_ptr.h" | 15 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 16 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 16 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 17 #include "mojo/public/cpp/bindings/interface_request.h" | 17 #include "mojo/public/cpp/bindings/interface_request.h" |
| 18 #include "mojo/public/cpp/bindings/lib/binding_state.h" | 18 #include "mojo/public/cpp/bindings/lib/binding_state.h" |
| 19 #include "mojo/public/cpp/system/core.h" | 19 #include "mojo/public/cpp/system/core.h" |
| 20 | 20 |
| 21 namespace mojo { | 21 namespace mojo { |
| 22 | 22 |
| 23 class AssociatedGroup; | 23 class AssociatedGroup; |
| 24 class MessageReceiver; | |
| 24 | 25 |
| 25 // Represents the binding of an interface implementation to a message pipe. | 26 // Represents the binding of an interface implementation to a message pipe. |
| 26 // When the |Binding| object is destroyed, the binding between the message pipe | 27 // When the |Binding| object is destroyed, the binding between the message pipe |
| 27 // and the interface is torn down and the message pipe is closed, leaving the | 28 // and the interface is torn down and the message pipe is closed, leaving the |
| 28 // interface implementation in an unbound state. | 29 // interface implementation in an unbound state. |
| 29 // | 30 // |
| 30 // Example: | 31 // Example: |
| 31 // | 32 // |
| 32 // #include "foo.mojom.h" | 33 // #include "foo.mojom.h" |
| 33 // | 34 // |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 146 |
| 146 // Completes a binding that was constructed with only an interface | 147 // Completes a binding that was constructed with only an interface |
| 147 // implementation by removing the message pipe endpoint from |request| and | 148 // implementation by removing the message pipe endpoint from |request| and |
| 148 // binding it to the previously specified implementation. | 149 // binding it to the previously specified implementation. |
| 149 void Bind(InterfaceRequest<Interface> request, | 150 void Bind(InterfaceRequest<Interface> request, |
| 150 scoped_refptr<base::SingleThreadTaskRunner> runner = | 151 scoped_refptr<base::SingleThreadTaskRunner> runner = |
| 151 base::ThreadTaskRunnerHandle::Get()) { | 152 base::ThreadTaskRunnerHandle::Get()) { |
| 152 Bind(request.PassMessagePipe(), std::move(runner)); | 153 Bind(request.PassMessagePipe(), std::move(runner)); |
| 153 } | 154 } |
| 154 | 155 |
| 156 // Adds a message filter to be notified of each incoming message and | |
| 157 // optionally prevent it from being dispatched. Filters cannot be removed. | |
|
yzshen1
2016/08/24 20:47:55
Returning false not just prevents the message from
Ken Rockot(use gerrit already)
2016/08/24 20:56:38
Done
| |
| 158 void AddFilter(std::unique_ptr<MessageReceiver> filter) { | |
| 159 DCHECK(is_bound()); | |
| 160 internal_state_.AddFilter(std::move(filter)); | |
| 161 } | |
| 162 | |
| 155 // Whether there are any associated interfaces running on the pipe currently. | 163 // Whether there are any associated interfaces running on the pipe currently. |
| 156 bool HasAssociatedInterfaces() const { | 164 bool HasAssociatedInterfaces() const { |
| 157 return internal_state_.HasAssociatedInterfaces(); | 165 return internal_state_.HasAssociatedInterfaces(); |
| 158 } | 166 } |
| 159 | 167 |
| 160 // Stops processing incoming messages until | 168 // Stops processing incoming messages until |
| 161 // ResumeIncomingMethodCallProcessing(), or WaitForIncomingMethodCall(). | 169 // ResumeIncomingMethodCallProcessing(), or WaitForIncomingMethodCall(). |
| 162 // Outgoing messages are still sent. | 170 // Outgoing messages are still sent. |
| 163 // | 171 // |
| 164 // No errors are detected on the message pipe while paused. | 172 // No errors are detected on the message pipe while paused. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 private: | 253 private: |
| 246 internal::BindingState<Interface, Interface::PassesAssociatedKinds_> | 254 internal::BindingState<Interface, Interface::PassesAssociatedKinds_> |
| 247 internal_state_; | 255 internal_state_; |
| 248 | 256 |
| 249 DISALLOW_COPY_AND_ASSIGN(Binding); | 257 DISALLOW_COPY_AND_ASSIGN(Binding); |
| 250 }; | 258 }; |
| 251 | 259 |
| 252 } // namespace mojo | 260 } // namespace mojo |
| 253 | 261 |
| 254 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ | 262 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ |
| OLD | NEW |