Home | History | Annotate | Download | only in lib
      1 // Copyright 2013 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/bindings/lib/message_queue.h"
      6 
      7 #include <assert.h>
      8 #include <stddef.h>
      9 
     10 #include "mojo/public/bindings/lib/message.h"
     11 
     12 namespace mojo {
     13 
     14 MessageQueue::MessageQueue() {
     15 }
     16 
     17 MessageQueue::~MessageQueue() {
     18   while (!queue_.empty())
     19     Pop();
     20 }
     21 
     22 bool MessageQueue::IsEmpty() const {
     23   return queue_.empty();
     24 }
     25 
     26 Message* MessageQueue::Peek() {
     27   assert(!queue_.empty());
     28   return queue_.front();
     29 }
     30 
     31 void MessageQueue::Push(Message* message) {
     32   queue_.push(new Message());
     33   queue_.back()->Swap(message);
     34 }
     35 
     36 void MessageQueue::Pop(Message* message) {
     37   assert(!queue_.empty());
     38   queue_.front()->Swap(message);
     39   Pop();
     40 }
     41 
     42 void MessageQueue::Pop() {
     43   assert(!queue_.empty());
     44   delete queue_.front();
     45   queue_.pop();
     46 }
     47 
     48 }  // namespace mojo
     49