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_reader.h" | 5 #include "blimp/net/stream_packet_reader.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/weak_ptr.h" | 12 #include "base/memory/weak_ptr.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/net/blimp_connection_statistics.h" | 16 #include "blimp/net/blimp_connection_statistics.h" |
15 #include "blimp/net/common.h" | 17 #include "blimp/net/common.h" |
16 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
17 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
18 #include "net/socket/stream_socket.h" | 20 #include "net/socket/stream_socket.h" |
19 | 21 |
20 namespace blimp { | 22 namespace blimp { |
21 | 23 |
22 std::ostream& operator<<(std::ostream& out, | 24 std::ostream& operator<<(std::ostream& out, |
23 const StreamPacketReader::ReadState state) { | 25 const StreamPacketReader::ReadState state) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 payload_buffer_->set_offset(0); | 63 payload_buffer_->set_offset(0); |
62 read_state_ = ReadState::HEADER; | 64 read_state_ = ReadState::HEADER; |
63 | 65 |
64 int result = DoReadLoop(net::OK); | 66 int result = DoReadLoop(net::OK); |
65 if (result != net::ERR_IO_PENDING) { | 67 if (result != net::ERR_IO_PENDING) { |
66 // Release the payload buffer, since the read operation has completed | 68 // Release the payload buffer, since the read operation has completed |
67 // synchronously. | 69 // synchronously. |
68 payload_buffer_ = nullptr; | 70 payload_buffer_ = nullptr; |
69 | 71 |
70 // Adapt synchronous completion to an asynchronous style. | 72 // Adapt synchronous completion to an asynchronous style. |
71 base::MessageLoop::current()->PostTask( | 73 base::ThreadTaskRunnerHandle::Get()->PostTask( |
72 FROM_HERE, | 74 FROM_HERE, |
73 base::Bind(callback, result == net::OK ? payload_size_ : result)); | 75 base::Bind(callback, result == net::OK ? payload_size_ : result)); |
74 } else { | 76 } else { |
75 callback_ = callback; | 77 callback_ = callback; |
76 } | 78 } |
77 } | 79 } |
78 | 80 |
79 int StreamPacketReader::DoReadLoop(int result) { | 81 int StreamPacketReader::DoReadLoop(int result) { |
80 DCHECK_NE(net::ERR_IO_PENDING, result); | 82 DCHECK_NE(net::ERR_IO_PENDING, result); |
81 DCHECK_GE(result, 0); | 83 DCHECK_GE(result, 0); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // If all reading completed, either successfully or by error, inform the | 170 // If all reading completed, either successfully or by error, inform the |
169 // caller. | 171 // caller. |
170 if (result != net::ERR_IO_PENDING) { | 172 if (result != net::ERR_IO_PENDING) { |
171 payload_buffer_ = nullptr; | 173 payload_buffer_ = nullptr; |
172 base::ResetAndReturn(&callback_) | 174 base::ResetAndReturn(&callback_) |
173 .Run(result == net::OK ? payload_size_ : result); | 175 .Run(result == net::OK ? payload_size_ : result); |
174 } | 176 } |
175 } | 177 } |
176 | 178 |
177 } // namespace blimp | 179 } // namespace blimp |
OLD | NEW |