OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "blimp/net/browser_connection_handler.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/macros.h" | |
11 #include "blimp/net/blimp_connection.h" | |
12 #include "blimp/net/blimp_message_checkpointer.h" | |
13 #include "blimp/net/blimp_message_demultiplexer.h" | |
14 #include "blimp/net/blimp_message_multiplexer.h" | |
15 #include "blimp/net/blimp_message_output_buffer.h" | |
16 #include "blimp/net/blimp_message_processor.h" | |
17 #include "net/base/net_errors.h" | |
18 | |
19 namespace blimp { | |
20 namespace { | |
21 | |
22 // Maximum footprint of the output buffer. | |
23 // TODO(kmarshall): Use a value that's computed from the platform. | |
24 const int kMaxBufferSizeBytes = 32 * 1024 * 1024; | |
25 | |
26 } // namespace | |
27 | |
28 BrowserConnectionHandler::BrowserConnectionHandler() | |
29 : demultiplexer_(new BlimpMessageDemultiplexer), | |
30 output_buffer_(new BlimpMessageOutputBuffer(kMaxBufferSizeBytes)), | |
31 multiplexer_(new BlimpMessageMultiplexer(output_buffer_.get())), | |
32 checkpointer_(new BlimpMessageCheckpointer(demultiplexer_.get(), | |
33 output_buffer_.get(), | |
34 output_buffer_.get())) {} | |
35 | |
36 BrowserConnectionHandler::~BrowserConnectionHandler() {} | |
37 | |
38 std::unique_ptr<BlimpMessageProcessor> | |
39 BrowserConnectionHandler::RegisterFeature( | |
40 BlimpMessage::FeatureCase feature_case, | |
41 BlimpMessageProcessor* incoming_processor) { | |
42 demultiplexer_->AddProcessor(feature_case, incoming_processor); | |
43 return multiplexer_->CreateSender(feature_case); | |
44 } | |
45 | |
46 void BrowserConnectionHandler::HandleConnection( | |
47 std::unique_ptr<BlimpConnection> connection) { | |
48 DCHECK(connection); | |
49 VLOG(1) << "HandleConnection " << connection.get(); | |
50 | |
51 if (connection_) { | |
52 DropCurrentConnection(); | |
53 } | |
54 connection_ = std::move(connection); | |
55 | |
56 // Hook up message streams to the connection. | |
57 connection_->SetIncomingMessageProcessor(checkpointer_.get()); | |
58 output_buffer_->SetOutputProcessor( | |
59 connection_->GetOutgoingMessageProcessor()); | |
60 connection_->AddConnectionErrorObserver(this); | |
61 } | |
62 | |
63 void BrowserConnectionHandler::OnConnectionError(int error) { | |
64 DropCurrentConnection(); | |
65 } | |
66 | |
67 void BrowserConnectionHandler::DropCurrentConnection() { | |
68 if (!connection_) { | |
69 return; | |
70 } | |
71 | |
72 output_buffer_->SetOutputProcessor(nullptr); | |
73 connection_.reset(); | |
74 } | |
75 | |
76 } // namespace blimp | |
OLD | NEW |