Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2307)

Unified Diff: blimp/net/blimp_connection.cc

Issue 1876983002: Use Chromium BUILD to approximate Blimp protocol version, and check it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Route EndConnection to OnConnectionError notifications Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/net/blimp_connection.cc
diff --git a/blimp/net/blimp_connection.cc b/blimp/net/blimp_connection.cc
index e8f3c68cc376131814ccd41bcf308c8950a2ce91..c177cd580b9d50ab7b41438758ae98aa9b2d456d 100644
--- a/blimp/net/blimp_connection.cc
+++ b/blimp/net/blimp_connection.cc
@@ -99,12 +99,47 @@ void BlimpMessageSender::OnWritePacketComplete(int result) {
} // namespace
+class BlimpConnection::EndConnectionHandler
Kevin M 2016/05/25 21:19:19 Comment on the class' purpose?
Wez 2016/05/25 23:11:36 Done.
+ : public BlimpMessageProcessor {
+ public:
+ explicit EndConnectionHandler(BlimpConnection* connection)
+ : connection_(connection), message_handler_(nullptr) {}
+
+ void set_message_handler(BlimpMessageProcessor* message_handler) {
+ message_handler_ = message_handler;
+ }
+
+ // BlimpMessageProcessor implementation.
+ void ProcessMessage(std::unique_ptr<BlimpMessage> message,
+ const net::CompletionCallback& callback) override {
+ if (message->has_protocol_control() &&
+ message->protocol_control().has_end_connection()) {
+ // Report the EndConnection reason to connection error observers.
+ connection_->OnConnectionError(
+ message->protocol_control().end_connection().reason());
+
+ // Caller is responsible for ensuring |callback| is still safe to call.
+ callback.Run(message->protocol_control().end_connection().reason());
+ return;
+ }
+
+ message_handler_->ProcessMessage(std::move(message), callback);
+ }
+
+ private:
+ BlimpConnection* connection_;
+ BlimpMessageProcessor* message_handler_;
Kevin M 2016/05/25 21:19:19 Document the role of |message_handler_|?
Wez 2016/05/25 23:11:37 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(EndConnectionHandler);
+};
+
BlimpConnection::BlimpConnection(std::unique_ptr<PacketReader> reader,
std::unique_ptr<PacketWriter> writer)
: reader_(std::move(reader)),
message_pump_(new BlimpMessagePump(reader_.get())),
writer_(std::move(writer)),
- outgoing_msg_processor_(new BlimpMessageSender(writer_.get())) {
+ outgoing_msg_processor_(new BlimpMessageSender(writer_.get())),
+ end_connection_handler_(new EndConnectionHandler(this)) {
DCHECK(writer_);
// Observe the connection errors received by any of this connection's network
@@ -133,7 +168,9 @@ void BlimpConnection::RemoveConnectionErrorObserver(
void BlimpConnection::SetIncomingMessageProcessor(
BlimpMessageProcessor* processor) {
- message_pump_->SetMessageProcessor(processor);
+ end_connection_handler_->set_message_handler(processor);
+ message_pump_->SetMessageProcessor(processor ? end_connection_handler_.get()
+ : nullptr);
}
BlimpMessageProcessor* BlimpConnection::GetOutgoingMessageProcessor() {

Powered by Google App Engine
This is Rietveld 408576698