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_BLIMP_MESSAGE_MULTIPLEXER_H_ |
| 6 #define BLIMP_NET_BLIMP_MESSAGE_MULTIPLEXER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "blimp/common/proto/blimp_message.pb.h" |
| 12 #include "blimp/net/blimp_message_processor.h" |
| 13 #include "blimp/net/blimp_net_export.h" |
| 14 #include "net/base/completion_callback.h" |
| 15 |
| 16 namespace blimp { |
| 17 |
| 18 class BlimpConnection; |
| 19 |
| 20 // Creates MessageProcessors that receive outgoing messages and multiplex them |
| 21 // on to a single output message processor. |
| 22 class BLIMP_NET_EXPORT BlimpMessageMultiplexer { |
| 23 public: |
| 24 // |output_processor|: A pointer to the MessageProcessor that will receive the |
| 25 // multiplexed message stream. |
| 26 explicit BlimpMessageMultiplexer( |
| 27 base::WeakPtr<BlimpMessageProcessor> output_processor); |
| 28 |
| 29 ~BlimpMessageMultiplexer(); |
| 30 |
| 31 // Creates a BlimpMessageProcessor object for sending messages of type |type|. |
| 32 // Any number of senders can be created at a time for a given type. |
| 33 scoped_ptr<BlimpMessageProcessor> CreateSenderForType( |
| 34 BlimpMessage::Type type); |
| 35 |
| 36 private: |
| 37 class MultiplexedSender : public BlimpMessageProcessor { |
| 38 public: |
| 39 MultiplexedSender(base::WeakPtr<BlimpMessageProcessor> output_processor, |
| 40 BlimpMessage::Type type); |
| 41 ~MultiplexedSender() override; |
| 42 |
| 43 // BlimpMessageProcessor implementation. |
| 44 // |message.type| should not be set at the time of calling ProcessMessage. |
| 45 void ProcessMessage(const BlimpMessage& message, |
| 46 const net::CompletionCallback& callback) override; |
| 47 |
| 48 private: |
| 49 base::WeakPtr<BlimpMessageProcessor> output_processor_; |
| 50 BlimpMessage::Type type_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(MultiplexedSender); |
| 53 }; |
| 54 friend class MultiplexedSender; |
| 55 |
| 56 base::WeakPtr<BlimpMessageProcessor> output_processor_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(BlimpMessageMultiplexer); |
| 59 }; |
| 60 |
| 61 } // namespace blimp |
| 62 |
| 63 #endif // BLIMP_NET_BLIMP_MESSAGE_MULTIPLEXER_H_ |
OLD | NEW |