| 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_SET_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_SET_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_SET_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_SET_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // context associated with the specific binding which received the message or | 88 // context associated with the specific binding which received the message or |
| 89 // error. Use AddBinding() to associated a context with a specific binding. | 89 // error. Use AddBinding() to associated a context with a specific binding. |
| 90 // | 90 // |
| 91 // Note that this may ONLY be called if the BindingSet was constructed with | 91 // Note that this may ONLY be called if the BindingSet was constructed with |
| 92 // |BindingSetDispatchMode::WITH_CONTEXT|. | 92 // |BindingSetDispatchMode::WITH_CONTEXT|. |
| 93 void* dispatch_context() const { | 93 void* dispatch_context() const { |
| 94 DCHECK(SupportsContext()); | 94 DCHECK(SupportsContext()); |
| 95 return dispatch_context_; | 95 return dispatch_context_; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void FlushForTesting() { |
| 99 for (auto& binding : bindings_) { |
| 100 binding.first->FlushForTesting(); |
| 101 } |
| 102 } |
| 103 |
| 98 private: | 104 private: |
| 99 friend class Entry; | 105 friend class Entry; |
| 100 | 106 |
| 101 class Entry { | 107 class Entry { |
| 102 public: | 108 public: |
| 103 Entry(Interface* impl, | 109 Entry(Interface* impl, |
| 104 RequestType request, | 110 RequestType request, |
| 105 BindingSet* binding_set, | 111 BindingSet* binding_set, |
| 106 void* context) | 112 void* context) |
| 107 : binding_(impl, std::move(request)), | 113 : binding_(impl, std::move(request)), |
| 108 binding_set_(binding_set), | 114 binding_set_(binding_set), |
| 109 context_(context) { | 115 context_(context) { |
| 110 if (binding_set->SupportsContext()) | 116 if (binding_set->SupportsContext()) |
| 111 binding_.AddFilter(base::MakeUnique<DispatchFilter>(this)); | 117 binding_.AddFilter(base::MakeUnique<DispatchFilter>(this)); |
| 112 binding_.set_connection_error_handler(base::Bind( | 118 binding_.set_connection_error_handler(base::Bind( |
| 113 &Entry::OnConnectionError, base::Unretained(this))); | 119 &Entry::OnConnectionError, base::Unretained(this))); |
| 114 } | 120 } |
| 115 | 121 |
| 122 void FlushForTesting() { binding_.FlushForTesting(); } |
| 123 |
| 116 private: | 124 private: |
| 117 class DispatchFilter : public MessageReceiver { | 125 class DispatchFilter : public MessageReceiver { |
| 118 public: | 126 public: |
| 119 explicit DispatchFilter(Entry* entry) : entry_(entry) {} | 127 explicit DispatchFilter(Entry* entry) : entry_(entry) {} |
| 120 ~DispatchFilter() override {} | 128 ~DispatchFilter() override {} |
| 121 | 129 |
| 122 private: | 130 private: |
| 123 // MessageReceiver: | 131 // MessageReceiver: |
| 124 bool Accept(Message* message) override { | 132 bool Accept(Message* message) override { |
| 125 entry_->WillDispatch(); | 133 entry_->WillDispatch(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 base::Closure error_handler_; | 179 base::Closure error_handler_; |
| 172 std::map<Entry*, std::unique_ptr<Entry>> bindings_; | 180 std::map<Entry*, std::unique_ptr<Entry>> bindings_; |
| 173 void* dispatch_context_ = nullptr; | 181 void* dispatch_context_ = nullptr; |
| 174 | 182 |
| 175 DISALLOW_COPY_AND_ASSIGN(BindingSet); | 183 DISALLOW_COPY_AND_ASSIGN(BindingSet); |
| 176 }; | 184 }; |
| 177 | 185 |
| 178 } // namespace mojo | 186 } // namespace mojo |
| 179 | 187 |
| 180 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_SET_H_ | 188 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_SET_H_ |
| OLD | NEW |