| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/net/blimp_message_output_buffer.h" | 5 #include "blimp/net/blimp_message_output_buffer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/location.h" |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "blimp/common/logging.h" | 14 #include "blimp/common/logging.h" |
| 13 #include "blimp/common/proto/blimp_message.pb.h" | 15 #include "blimp/common/proto/blimp_message.pb.h" |
| 14 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 15 | 17 |
| 16 namespace blimp { | 18 namespace blimp { |
| 17 | 19 |
| 18 BlimpMessageOutputBuffer::BlimpMessageOutputBuffer(int max_buffer_size_bytes) | 20 BlimpMessageOutputBuffer::BlimpMessageOutputBuffer(int max_buffer_size_bytes) |
| 19 : max_buffer_size_bytes_(max_buffer_size_bytes) {} | 21 : max_buffer_size_bytes_(max_buffer_size_bytes) {} |
| 20 | 22 |
| 21 BlimpMessageOutputBuffer::~BlimpMessageOutputBuffer() {} | 23 BlimpMessageOutputBuffer::~BlimpMessageOutputBuffer() {} |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // write callbacks, if set. | 99 // write callbacks, if set. |
| 98 while (!ack_buffer_.empty() && | 100 while (!ack_buffer_.empty() && |
| 99 ack_buffer_.front()->message->message_id() <= message_id) { | 101 ack_buffer_.front()->message->message_id() <= message_id) { |
| 100 const BufferEntry& ack_entry = *ack_buffer_.front(); | 102 const BufferEntry& ack_entry = *ack_buffer_.front(); |
| 101 current_buffer_size_bytes_ -= ack_entry.message->GetCachedSize(); | 103 current_buffer_size_bytes_ -= ack_entry.message->GetCachedSize(); |
| 102 DCHECK_GE(current_buffer_size_bytes_, 0); | 104 DCHECK_GE(current_buffer_size_bytes_, 0); |
| 103 VLOG(3) << "Buffer size: " << current_buffer_size_bytes_ | 105 VLOG(3) << "Buffer size: " << current_buffer_size_bytes_ |
| 104 << " (max=" << current_buffer_size_bytes_ << ")"; | 106 << " (max=" << current_buffer_size_bytes_ << ")"; |
| 105 | 107 |
| 106 if (!ack_entry.callback.is_null()) { | 108 if (!ack_entry.callback.is_null()) { |
| 107 base::MessageLoop::current()->PostTask( | 109 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 108 FROM_HERE, base::Bind(ack_entry.callback, net::OK)); | 110 FROM_HERE, base::Bind(ack_entry.callback, net::OK)); |
| 109 } | 111 } |
| 110 | 112 |
| 111 ack_buffer_.pop_front(); | 113 ack_buffer_.pop_front(); |
| 112 } | 114 } |
| 113 | 115 |
| 114 // An empty buffer should have a zero-byte footprint. | 116 // An empty buffer should have a zero-byte footprint. |
| 115 DCHECK(current_buffer_size_bytes_ > 0 || | 117 DCHECK(current_buffer_size_bytes_ > 0 || |
| 116 (ack_buffer_.empty() && write_buffer_.empty())) | 118 (ack_buffer_.empty() && write_buffer_.empty())) |
| 117 << "Expected zero-length buffer size, was " << current_buffer_size_bytes_ | 119 << "Expected zero-length buffer size, was " << current_buffer_size_bytes_ |
| (...skipping 30 matching lines...) Expand all Loading... |
| 148 | 150 |
| 149 VLOG(2) << "Write result=" << net::ErrorToString(result); | 151 VLOG(2) << "Write result=" << net::ErrorToString(result); |
| 150 if (result == net::OK) { | 152 if (result == net::OK) { |
| 151 ack_buffer_.push_back(std::move(write_buffer_.front())); | 153 ack_buffer_.push_back(std::move(write_buffer_.front())); |
| 152 write_buffer_.pop_front(); | 154 write_buffer_.pop_front(); |
| 153 WriteNextMessageIfReady(); | 155 WriteNextMessageIfReady(); |
| 154 } | 156 } |
| 155 } | 157 } |
| 156 | 158 |
| 157 } // namespace blimp | 159 } // namespace blimp |
| OLD | NEW |