| 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 before |
| 157 // dispatch. If a filter returns |false| from Accept(), the message is not |
| 158 // dispatched and the pipe is closed. Filters cannot be removed. |
| 159 void AddFilter(std::unique_ptr<MessageReceiver> filter) { |
| 160 DCHECK(is_bound()); |
| 161 internal_state_.AddFilter(std::move(filter)); |
| 162 } |
| 163 |
| 155 // Whether there are any associated interfaces running on the pipe currently. | 164 // Whether there are any associated interfaces running on the pipe currently. |
| 156 bool HasAssociatedInterfaces() const { | 165 bool HasAssociatedInterfaces() const { |
| 157 return internal_state_.HasAssociatedInterfaces(); | 166 return internal_state_.HasAssociatedInterfaces(); |
| 158 } | 167 } |
| 159 | 168 |
| 160 // Stops processing incoming messages until | 169 // Stops processing incoming messages until |
| 161 // ResumeIncomingMethodCallProcessing(), or WaitForIncomingMethodCall(). | 170 // ResumeIncomingMethodCallProcessing(), or WaitForIncomingMethodCall(). |
| 162 // Outgoing messages are still sent. | 171 // Outgoing messages are still sent. |
| 163 // | 172 // |
| 164 // No errors are detected on the message pipe while paused. | 173 // 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: | 254 private: |
| 246 internal::BindingState<Interface, Interface::PassesAssociatedKinds_> | 255 internal::BindingState<Interface, Interface::PassesAssociatedKinds_> |
| 247 internal_state_; | 256 internal_state_; |
| 248 | 257 |
| 249 DISALLOW_COPY_AND_ASSIGN(Binding); | 258 DISALLOW_COPY_AND_ASSIGN(Binding); |
| 250 }; | 259 }; |
| 251 | 260 |
| 252 } // namespace mojo | 261 } // namespace mojo |
| 253 | 262 |
| 254 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ | 263 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ |
| OLD | NEW |