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_connection.h" | 5 #include "blimp/net/blimp_connection.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.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 "blimp/net/blimp_message_processor.h" | 16 #include "blimp/net/blimp_message_processor.h" |
15 #include "blimp/net/blimp_message_pump.h" | 17 #include "blimp/net/blimp_message_pump.h" |
16 #include "blimp/net/common.h" | 18 #include "blimp/net/common.h" |
17 #include "blimp/net/connection_error_observer.h" | 19 #include "blimp/net/connection_error_observer.h" |
18 #include "blimp/net/packet_reader.h" | 20 #include "blimp/net/message_port.h" |
19 #include "blimp/net/packet_writer.h" | 21 #include "blimp/net/packet_writer.h" |
20 #include "net/base/completion_callback.h" | 22 #include "net/base/completion_callback.h" |
21 | 23 |
22 namespace blimp { | 24 namespace blimp { |
23 | 25 |
24 // Forwards incoming blimp messages to PacketWriter. | 26 // Forwards incoming blimp messages to PacketWriter. |
25 class BlimpMessageSender : public BlimpMessageProcessor { | 27 class BlimpMessageSender : public BlimpMessageProcessor { |
26 public: | 28 public: |
27 explicit BlimpMessageSender(PacketWriter* writer); | 29 explicit BlimpMessageSender(PacketWriter* writer); |
28 ~BlimpMessageSender() override; | 30 ~BlimpMessageSender() override; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 message->protocol_control().end_connection().reason()); | 145 message->protocol_control().end_connection().reason()); |
144 | 146 |
145 // Caller must ensure |callback| safe to call after OnConnectionError. | 147 // Caller must ensure |callback| safe to call after OnConnectionError. |
146 callback.Run(message->protocol_control().end_connection().reason()); | 148 callback.Run(message->protocol_control().end_connection().reason()); |
147 return; | 149 return; |
148 } | 150 } |
149 | 151 |
150 message_handler_->ProcessMessage(std::move(message), callback); | 152 message_handler_->ProcessMessage(std::move(message), callback); |
151 } | 153 } |
152 | 154 |
153 BlimpConnection::BlimpConnection(std::unique_ptr<PacketReader> reader, | 155 BlimpConnection::BlimpConnection(std::unique_ptr<MessagePort> message_port) |
154 std::unique_ptr<PacketWriter> writer) | 156 : message_port_(std::move(message_port)), |
155 : reader_(std::move(reader)), | 157 message_pump_(new BlimpMessagePump(message_port_->reader())), |
156 message_pump_(new BlimpMessagePump(reader_.get())), | 158 outgoing_msg_processor_(new BlimpMessageSender(message_port_->writer())), |
157 writer_(std::move(writer)), | |
158 outgoing_msg_processor_(new BlimpMessageSender(writer_.get())), | |
159 end_connection_filter_(new EndConnectionFilter(this)) { | 159 end_connection_filter_(new EndConnectionFilter(this)) { |
160 DCHECK(writer_); | |
161 DCHECK(reader_); | |
162 | |
163 message_pump_->set_error_observer(this); | 160 message_pump_->set_error_observer(this); |
164 outgoing_msg_processor_->set_error_observer(this); | 161 outgoing_msg_processor_->set_error_observer(this); |
165 } | 162 } |
166 | 163 |
167 BlimpConnection::BlimpConnection() {} | 164 BlimpConnection::BlimpConnection() {} |
168 | 165 |
169 BlimpConnection::~BlimpConnection() { | 166 BlimpConnection::~BlimpConnection() { |
170 VLOG(1) << "BlimpConnection destroyed."; | 167 VLOG(1) << "BlimpConnection destroyed."; |
171 } | 168 } |
172 | 169 |
(...skipping 20 matching lines...) Expand all Loading... |
193 | 190 |
194 void BlimpConnection::OnConnectionError(int error) { | 191 void BlimpConnection::OnConnectionError(int error) { |
195 VLOG(1) << "OnConnectionError, error=" << error; | 192 VLOG(1) << "OnConnectionError, error=" << error; |
196 | 193 |
197 // Propagate the error to all observers. | 194 // Propagate the error to all observers. |
198 FOR_EACH_OBSERVER(ConnectionErrorObserver, error_observers_, | 195 FOR_EACH_OBSERVER(ConnectionErrorObserver, error_observers_, |
199 OnConnectionError(error)); | 196 OnConnectionError(error)); |
200 } | 197 } |
201 | 198 |
202 } // namespace blimp | 199 } // namespace blimp |
OLD | NEW |