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/lib/filter_chain.h" 6 7 #include <algorithm> 8 9 #include "base/logging.h" 10 11 namespace mojo { 12 namespace internal { 13 FilterChain(MessageReceiver * sink)14FilterChain::FilterChain(MessageReceiver* sink) : sink_(sink) { 15 } 16 FilterChain(FilterChain && other)17FilterChain::FilterChain(FilterChain&& other) : sink_(other.sink_) { 18 other.sink_ = nullptr; 19 filters_.swap(other.filters_); 20 } 21 operator =(FilterChain && other)22FilterChain& FilterChain::operator=(FilterChain&& other) { 23 std::swap(sink_, other.sink_); 24 filters_.swap(other.filters_); 25 return *this; 26 } 27 ~FilterChain()28FilterChain::~FilterChain() { 29 for (std::vector<MessageFilter*>::iterator iter = filters_.begin(); 30 iter != filters_.end(); 31 ++iter) { 32 delete *iter; 33 } 34 } 35 SetSink(MessageReceiver * sink)36void FilterChain::SetSink(MessageReceiver* sink) { 37 DCHECK(!sink_); 38 sink_ = sink; 39 if (!filters_.empty()) 40 filters_.back()->set_sink(sink); 41 } 42 GetHead()43MessageReceiver* FilterChain::GetHead() { 44 DCHECK(sink_); 45 return filters_.empty() ? sink_ : filters_.front(); 46 } 47 48 } // namespace internal 49 } // namespace mojo 50