| 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 #ifndef BLIMP_NET_BROWSER_CONNECTION_HANDLER_H_ | |
| 6 #define BLIMP_NET_BROWSER_CONNECTION_HANDLER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "blimp/common/proto/blimp_message.pb.h" | |
| 12 #include "blimp/net/blimp_net_export.h" | |
| 13 #include "blimp/net/connection_error_observer.h" | |
| 14 #include "blimp/net/connection_handler.h" | |
| 15 | |
| 16 namespace blimp { | |
| 17 | |
| 18 class BlimpConnection; | |
| 19 class BlimpMessageCheckpointer; | |
| 20 class BlimpMessageDemultiplexer; | |
| 21 class BlimpMessageMultiplexer; | |
| 22 class BlimpMessageOutputBuffer; | |
| 23 class BlimpMessageProcessor; | |
| 24 | |
| 25 // Routes incoming messages to their respective features, and buffers and sends | |
| 26 // messages out via underlying BlimpConnection. | |
| 27 // A BrowserConnectionHandler is created on browser startup, and persists for | |
| 28 // the lifetime of the application. | |
| 29 // BrowserConnectionHandler is created on the UI thread, and then used and | |
| 30 // destroyed on the IO thread. | |
| 31 class BLIMP_NET_EXPORT BrowserConnectionHandler | |
| 32 : public ConnectionHandler, | |
| 33 public ConnectionErrorObserver { | |
| 34 public: | |
| 35 BrowserConnectionHandler(); | |
| 36 ~BrowserConnectionHandler() override; | |
| 37 | |
| 38 // Registers a message processor which will receive all messages of the | |
| 39 // |feature_case| specified. Only one handler may be added per feature. | |
| 40 // That caller must ensure |incoming_processor| remains valid while | |
| 41 // this object is in-use. | |
| 42 // | |
| 43 // Returns a BlimpMessageProcessor object for sending messages for a given | |
| 44 // feature. | |
| 45 virtual std::unique_ptr<BlimpMessageProcessor> RegisterFeature( | |
| 46 BlimpMessage::FeatureCase feature_case, | |
| 47 BlimpMessageProcessor* incoming_processor); | |
| 48 | |
| 49 // ConnectionHandler implementation. | |
| 50 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; | |
| 51 | |
| 52 // ConnectionErrorObserver implementation. | |
| 53 void OnConnectionError(int error) override; | |
| 54 | |
| 55 void DropCurrentConnection(); | |
| 56 | |
| 57 private: | |
| 58 // Routes incoming messages to the relevant feature-specific handlers. | |
| 59 std::unique_ptr<BlimpMessageDemultiplexer> demultiplexer_; | |
| 60 | |
| 61 // Provides buffering of outgoing messages, for use in session-recovery. | |
| 62 std::unique_ptr<BlimpMessageOutputBuffer> output_buffer_; | |
| 63 | |
| 64 // Routes outgoing messages from feature-specific handlers to a single | |
| 65 // message stream. | |
| 66 std::unique_ptr<BlimpMessageMultiplexer> multiplexer_; | |
| 67 | |
| 68 // Dispatches checkpoint/ACK messages to the outgoing processor, as the | |
| 69 // incoming processor completes processing them. | |
| 70 std::unique_ptr<BlimpMessageCheckpointer> checkpointer_; | |
| 71 | |
| 72 // Holds network resources while there is a Client connected. | |
| 73 std::unique_ptr<BlimpConnection> connection_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(BrowserConnectionHandler); | |
| 76 }; | |
| 77 | |
| 78 } // namespace blimp | |
| 79 | |
| 80 #endif // BLIMP_NET_BROWSER_CONNECTION_HANDLER_H_ | |
| OLD | NEW |