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