Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3971)

Unified Diff: blimp/net/blimp_message_multiplexer.h

Issue 1429193002: Add interfaces for most major Blimp net components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address wez's feedback. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/net/blimp_message_multiplexer.h
diff --git a/blimp/net/blimp_message_multiplexer.h b/blimp/net/blimp_message_multiplexer.h
new file mode 100644
index 0000000000000000000000000000000000000000..e01a1743c171c6449063bd0c22d10221684881af
--- /dev/null
+++ b/blimp/net/blimp_message_multiplexer.h
@@ -0,0 +1,63 @@
+// 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_BLIMP_MESSAGE_MULTIPLEXER_H_
+#define BLIMP_NET_BLIMP_MESSAGE_MULTIPLEXER_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "blimp/common/proto/blimp_message.pb.h"
+#include "blimp/net/blimp_message_processor.h"
+#include "blimp/net/blimp_net_export.h"
+#include "net/base/completion_callback.h"
+
+namespace blimp {
+
+class BlimpConnection;
+
+// Creates MessageProcessors that receive outgoing messages and multiplex them
+// on to a single output message processor.
+class BLIMP_NET_EXPORT BlimpMessageMultiplexer {
+ public:
+ // |output_processor|: A pointer to the MessageProcessor that will receive the
+ // multiplexed message stream.
+ explicit BlimpMessageMultiplexer(
+ base::WeakPtr<BlimpMessageProcessor> output_processor);
+
+ ~BlimpMessageMultiplexer();
+
+ // Creates a BlimpMessageProcessor object for sending messages of type |type|.
+ // Any number of senders can be created at a time for a given type.
+ scoped_ptr<BlimpMessageProcessor> CreateSenderForType(
+ BlimpMessage::Type type);
+
+ private:
+ class MultiplexedSender : public BlimpMessageProcessor {
+ public:
+ MultiplexedSender(base::WeakPtr<BlimpMessageProcessor> output_processor,
+ BlimpMessage::Type type);
+ ~MultiplexedSender() override;
+
+ // BlimpMessageProcessor implementation.
+ // |message.type| should not be set at the time of calling ProcessMessage.
+ void ProcessMessage(const BlimpMessage& message,
+ const net::CompletionCallback& callback) override;
+
+ private:
+ base::WeakPtr<BlimpMessageProcessor> output_processor_;
+ BlimpMessage::Type type_;
+
+ DISALLOW_COPY_AND_ASSIGN(MultiplexedSender);
+ };
+ friend class MultiplexedSender;
+
+ base::WeakPtr<BlimpMessageProcessor> output_processor_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlimpMessageMultiplexer);
+};
+
+} // namespace blimp
+
+#endif // BLIMP_NET_BLIMP_MESSAGE_MULTIPLEXER_H_

Powered by Google App Engine
This is Rietveld 408576698