summaryrefslogtreecommitdiffstats
path: root/blimp/net/browser_connection_handler.h
diff options
context:
space:
mode:
authorhaibinlu <haibinlu@chromium.org>2015-11-30 11:29:31 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-30 19:30:14 +0000
commitbb8daabd6eb7a86d9f5cd2c8b624167f4db8bf57 (patch)
tree5b0183ab04714f5a7782e747816cac00e312a0ee /blimp/net/browser_connection_handler.h
parent2a5ba73614715abd6a924bb34e255847ea84b6d4 (diff)
downloadchromium_src-bb8daabd6eb7a86d9f5cd2c8b624167f4db8bf57.zip
chromium_src-bb8daabd6eb7a86d9f5cd2c8b624167f4db8bf57.tar.gz
chromium_src-bb8daabd6eb7a86d9f5cd2c8b624167f4db8bf57.tar.bz2
[Blimp Net] Adds BrowserConnectionHandler.
It Contains a demultiplexer for routing incoming messages to their respective features, and a multiplexer/buffer object for writing outgoing messages. It is created on browser startup, and persists for the lifetime of the application. BUG=561207 Review URL: https://codereview.chromium.org/1474583002 Cr-Commit-Position: refs/heads/master@{#362192}
Diffstat (limited to 'blimp/net/browser_connection_handler.h')
-rw-r--r--blimp/net/browser_connection_handler.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/blimp/net/browser_connection_handler.h b/blimp/net/browser_connection_handler.h
new file mode 100644
index 0000000..d739e50
--- /dev/null
+++ b/blimp/net/browser_connection_handler.h
@@ -0,0 +1,70 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BLIMP_NET_BROWSER_CONNECTION_HANDLER_H_
+#define BLIMP_NET_BROWSER_CONNECTION_HANDLER_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "blimp/common/proto/blimp_message.pb.h"
+#include "blimp/net/blimp_net_export.h"
+#include "blimp/net/connection_error_observer.h"
+#include "blimp/net/connection_handler.h"
+
+namespace blimp {
+
+class BlimpConnection;
+class BlimpMessageDemultiplexer;
+class BlimpMessageMultiplexer;
+class BlimpMessageOutputBuffer;
+class BlimpMessageProcessor;
+
+// Routes incoming messages to their respective features, and buffers and sends
+// messages out via underlying BlimpConnection.
+// A BrowserConnectionHandler is created on browser startup, and persists for
+// the lifetime of the application.
+class BLIMP_NET_EXPORT BrowserConnectionHandler
+ : public ConnectionHandler,
+ public ConnectionErrorObserver {
+ BrowserConnectionHandler();
+ ~BrowserConnectionHandler() override;
+
+ // Registers a message processor which will receive all messages of the |type|
+ // specified. Only one handler may be added per type.
+ // That caller must ensure |incoming_processor| remains valid while
+ // this object is in-use.
+ //
+ // Returns a BlimpMessageProcessor object for sending messages of type |type|.
+ scoped_ptr<BlimpMessageProcessor> RegisterFeature(
+ BlimpMessage::Type type,
+ BlimpMessageProcessor* incoming_processor);
+
+ // ConnectionHandler implementation.
+ void HandleConnection(scoped_ptr<BlimpConnection> connection) override;
+
+ // ConnectionErrorObserver implementation.
+ void OnConnectionError(int error) override;
+
+ private:
+ void DropCurrentConnection();
+
+ // Holds network resources while there is a Client connected.
+ scoped_ptr<BlimpConnection> connection_;
+
+ // Routes incoming messages to the relevant feature-specific handlers.
+ scoped_ptr<BlimpMessageDemultiplexer> demultiplexer_;
+
+ // Provides buffering of outgoing messages, for use in session-recovery.
+ scoped_ptr<BlimpMessageOutputBuffer> output_buffer_;
+
+ // Routes outgoing messages from feature-specific handlers to a single
+ // message stream.
+ scoped_ptr<BlimpMessageMultiplexer> multiplexer_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserConnectionHandler);
+};
+
+} // namespace blimp
+
+#endif // BLIMP_NET_BROWSER_CONNECTION_HANDLER_H_