| 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/browser_connection_handler.h" | 5 #include "blimp/net/browser_connection_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "blimp/net/blimp_connection.h" | 9 #include "blimp/net/blimp_connection.h" |
| 10 #include "blimp/net/blimp_message_checkpointer.h" | 10 #include "blimp/net/blimp_message_checkpointer.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 scoped_ptr<BlimpMessageProcessor> BrowserConnectionHandler::RegisterFeature( | 36 scoped_ptr<BlimpMessageProcessor> BrowserConnectionHandler::RegisterFeature( |
| 37 BlimpMessage::Type type, | 37 BlimpMessage::Type type, |
| 38 BlimpMessageProcessor* incoming_processor) { | 38 BlimpMessageProcessor* incoming_processor) { |
| 39 demultiplexer_->AddProcessor(type, incoming_processor); | 39 demultiplexer_->AddProcessor(type, incoming_processor); |
| 40 return multiplexer_->CreateSenderForType(type); | 40 return multiplexer_->CreateSenderForType(type); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void BrowserConnectionHandler::HandleConnection( | 43 void BrowserConnectionHandler::HandleConnection( |
| 44 scoped_ptr<BlimpConnection> connection) { | 44 scoped_ptr<BlimpConnection> connection) { |
| 45 // Since there is only a single Client, assume a newer connection should | 45 DCHECK(connection); |
| 46 // replace an existing one. | 46 VLOG(1) << "HandleConnection " << connection; |
| 47 DropCurrentConnection(); | 47 |
| 48 if (connection_) { |
| 49 DropCurrentConnection(); |
| 50 } |
| 48 connection_ = std::move(connection); | 51 connection_ = std::move(connection); |
| 49 connection_->SetConnectionErrorObserver(this); | |
| 50 | 52 |
| 51 // Connect the incoming & outgoing message streams. | 53 // Hook up message streams to the connection. |
| 52 connection_->SetIncomingMessageProcessor(checkpointer_.get()); | 54 connection_->SetIncomingMessageProcessor(demultiplexer_.get()); |
| 53 output_buffer_->SetOutputProcessor( | 55 output_buffer_->SetOutputProcessor( |
| 54 connection_->GetOutgoingMessageProcessor()); | 56 connection_->GetOutgoingMessageProcessor()); |
| 57 connection_->AddConnectionErrorObserver(this); |
| 58 } |
| 59 |
| 60 void BrowserConnectionHandler::OnConnectionError(int error) { |
| 61 DropCurrentConnection(); |
| 55 } | 62 } |
| 56 | 63 |
| 57 void BrowserConnectionHandler::DropCurrentConnection() { | 64 void BrowserConnectionHandler::DropCurrentConnection() { |
| 58 if (!connection_) | 65 DCHECK(connection_); |
| 59 return; | |
| 60 | |
| 61 connection_->SetConnectionErrorObserver(nullptr); | |
| 62 connection_->SetIncomingMessageProcessor(nullptr); | |
| 63 output_buffer_->SetOutputProcessor(nullptr); | 66 output_buffer_->SetOutputProcessor(nullptr); |
| 64 connection_.reset(); | 67 connection_.reset(); |
| 65 } | 68 } |
| 66 | 69 |
| 67 void BrowserConnectionHandler::OnConnectionError(int error) { | |
| 68 LOG(WARNING) << "Connection error " << net::ErrorToString(error); | |
| 69 DropCurrentConnection(); | |
| 70 } | |
| 71 | |
| 72 } // namespace blimp | 70 } // namespace blimp |
| OLD | NEW |