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/stream_packet_writer.h" | 5 #include "blimp/net/stream_packet_writer.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/location.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/single_thread_task_runner.h" |
13 #include "base/sys_byteorder.h" | 14 #include "base/sys_byteorder.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" |
14 #include "blimp/common/proto/blimp_message.pb.h" | 16 #include "blimp/common/proto/blimp_message.pb.h" |
15 #include "blimp/net/blimp_connection_statistics.h" | 17 #include "blimp/net/blimp_connection_statistics.h" |
16 #include "blimp/net/common.h" | 18 #include "blimp/net/common.h" |
17 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
18 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
19 #include "net/socket/stream_socket.h" | 21 #include "net/socket/stream_socket.h" |
20 | 22 |
21 namespace blimp { | 23 namespace blimp { |
22 | 24 |
23 std::ostream& operator<<(std::ostream& out, | 25 std::ostream& operator<<(std::ostream& out, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 68 |
67 statistics_->Add(BlimpConnectionStatistics::BYTES_SENT, | 69 statistics_->Add(BlimpConnectionStatistics::BYTES_SENT, |
68 payload_buffer_->BytesRemaining()); | 70 payload_buffer_->BytesRemaining()); |
69 int result = DoWriteLoop(net::OK); | 71 int result = DoWriteLoop(net::OK); |
70 if (result != net::ERR_IO_PENDING) { | 72 if (result != net::ERR_IO_PENDING) { |
71 // Release the payload buffer, since the write operation has completed | 73 // Release the payload buffer, since the write operation has completed |
72 // synchronously. | 74 // synchronously. |
73 payload_buffer_ = nullptr; | 75 payload_buffer_ = nullptr; |
74 | 76 |
75 // Adapt synchronous completion to an asynchronous style. | 77 // Adapt synchronous completion to an asynchronous style. |
76 base::MessageLoop::current()->PostTask(FROM_HERE, | 78 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
77 base::Bind(callback, result)); | 79 base::Bind(callback, result)); |
78 } else { | 80 } else { |
79 callback_ = callback; | 81 callback_ = callback; |
80 } | 82 } |
81 } | 83 } |
82 | 84 |
83 int StreamPacketWriter::DoWriteLoop(int result) { | 85 int StreamPacketWriter::DoWriteLoop(int result) { |
84 DCHECK_NE(net::ERR_IO_PENDING, result); | 86 DCHECK_NE(net::ERR_IO_PENDING, result); |
85 DCHECK_GE(result, 0); | 87 DCHECK_GE(result, 0); |
86 DCHECK_NE(WriteState::IDLE, write_state_); | 88 DCHECK_NE(WriteState::IDLE, write_state_); |
87 | 89 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 150 |
149 // If the write finished, either successfully or by error, inform the | 151 // If the write finished, either successfully or by error, inform the |
150 // caller. | 152 // caller. |
151 if (result != net::ERR_IO_PENDING) { | 153 if (result != net::ERR_IO_PENDING) { |
152 payload_buffer_ = nullptr; | 154 payload_buffer_ = nullptr; |
153 base::ResetAndReturn(&callback_).Run(result); | 155 base::ResetAndReturn(&callback_).Run(result); |
154 } | 156 } |
155 } | 157 } |
156 | 158 |
157 } // namespace blimp | 159 } // namespace blimp |
OLD | NEW |