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