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 3 // found in the LICENSE file. 4 5 #include "mojo/public/cpp/bindings/filter_chain.h" 6 7 #include <algorithm> 8 9 #include "base/logging.h" 10 11 namespace mojo { 12 13 FilterChain::FilterChain(MessageReceiver* sink) : sink_(sink) { 14 } 15 16 FilterChain::FilterChain(FilterChain&& other) : sink_(other.sink_) { 17 other.sink_ = nullptr; 18 filters_.swap(other.filters_); 19 } 20 21 FilterChain& FilterChain::operator=(FilterChain&& other) { 22 std::swap(sink_, other.sink_); 23 filters_.swap(other.filters_); 24 return *this; 25 } 26 27 FilterChain::~FilterChain() { 28 } 29 30 void FilterChain::SetSink(MessageReceiver* sink) { 31 DCHECK(!sink_); 32 sink_ = sink; 33 } 34 35 bool FilterChain::Accept(Message* message) { 36 DCHECK(sink_); 37 for (auto& filter : filters_) 38 if (!filter->Accept(message)) 39 return false; 40 return sink_->Accept(message); 41 } 42 43 void FilterChain::Append(std::unique_ptr<MessageReceiver> filter) { 44 filters_.emplace_back(std::move(filter)); 45 } 46 47 } // namespace mojo 48