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_demultiplexer.h" | 10 #include "blimp/net/blimp_message_demultiplexer.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 scoped_ptr<BlimpMessageProcessor> BrowserConnectionHandler::RegisterFeature( | 32 scoped_ptr<BlimpMessageProcessor> BrowserConnectionHandler::RegisterFeature( |
33 BlimpMessage::Type type, | 33 BlimpMessage::Type type, |
34 BlimpMessageProcessor* incoming_processor) { | 34 BlimpMessageProcessor* incoming_processor) { |
35 demultiplexer_->AddProcessor(type, incoming_processor); | 35 demultiplexer_->AddProcessor(type, incoming_processor); |
36 return multiplexer_->CreateSenderForType(type); | 36 return multiplexer_->CreateSenderForType(type); |
37 } | 37 } |
38 | 38 |
39 void BrowserConnectionHandler::HandleConnection( | 39 void BrowserConnectionHandler::HandleConnection( |
40 scoped_ptr<BlimpConnection> connection) { | 40 scoped_ptr<BlimpConnection> connection) { |
41 // Since there is only a single Client, assume a newer connection should | 41 VLOG(1) << "HandleConnection " << connection; |
42 // replace an existing one. | 42 |
43 DropCurrentConnection(); | 43 if (connection_) { |
44 // We will be clobbering |connection_| intentionally, so squelch any | |
45 // socket errors that might arise. | |
46 connection_->SetConnectionErrorObserver(nullptr); | |
haibinlu
2015/12/29 00:51:45
why remove "connection_->SetIncomingMessageProcess
Kevin M
2015/12/30 23:08:49
Both are redundant. Deleting |connection_| renders
| |
47 } | |
44 connection_ = std::move(connection); | 48 connection_ = std::move(connection); |
45 connection_->SetConnectionErrorObserver(this); | |
46 | 49 |
47 // Connect the incoming & outgoing message streams. | 50 // Connect the incoming & outgoing message streams. |
51 connection_->SetConnectionErrorObserver(this); | |
haibinlu
2015/12/29 00:51:45
move this up or update the comment above.
Kevin M
2015/12/30 23:08:49
Done.
| |
48 connection_->SetIncomingMessageProcessor(demultiplexer_.get()); | 52 connection_->SetIncomingMessageProcessor(demultiplexer_.get()); |
49 output_buffer_->SetOutputProcessor( | 53 output_buffer_->SetOutputProcessor( |
50 connection_->GetOutgoingMessageProcessor()); | 54 connection_->GetOutgoingMessageProcessor()); |
51 } | 55 } |
52 | 56 |
53 void BrowserConnectionHandler::DropCurrentConnection() { | 57 void BrowserConnectionHandler::OnConnectionError(int error) { |
54 if (!connection_) | 58 VLOG(1) << "OnConnectionError: " << net::ErrorToString(error); |
55 return; | 59 connection_.reset(); |
56 | |
57 connection_->SetConnectionErrorObserver(nullptr); | |
58 connection_->SetIncomingMessageProcessor(nullptr); | |
59 output_buffer_->SetOutputProcessor(nullptr); | 60 output_buffer_->SetOutputProcessor(nullptr); |
60 connection_.reset(); | |
61 } | |
62 | |
63 void BrowserConnectionHandler::OnConnectionError(int error) { | |
64 LOG(WARNING) << "Connection error " << net::ErrorToString(error); | |
65 DropCurrentConnection(); | |
66 } | 61 } |
67 | 62 |
68 } // namespace blimp | 63 } // namespace blimp |
OLD | NEW |