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/blimp_message_multiplexer.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/memory/ptr_util.h" | |
9 #include "blimp/common/create_blimp_message.h" | |
10 #include "blimp/common/proto/blimp_message.pb.h" | |
11 #include "blimp/net/blimp_message_processor.h" | |
12 | |
13 namespace blimp { | |
14 namespace { | |
15 | |
16 class MultiplexedSender : public BlimpMessageProcessor { | |
17 public: | |
18 MultiplexedSender(base::WeakPtr<BlimpMessageProcessor> output_processor, | |
19 BlimpMessage::FeatureCase feature_case); | |
20 ~MultiplexedSender() override; | |
21 | |
22 // BlimpMessageProcessor implementation. | |
23 // |message.feature_case|, if set, must match the sender's |feature_case_|. | |
24 void ProcessMessage(std::unique_ptr<BlimpMessage> message, | |
25 const net::CompletionCallback& callback) override; | |
26 | |
27 private: | |
28 base::WeakPtr<BlimpMessageProcessor> output_processor_; | |
29 BlimpMessage::FeatureCase feature_case_; | |
30 | |
31 DISALLOW_COPY_AND_ASSIGN(MultiplexedSender); | |
32 }; | |
33 | |
34 MultiplexedSender::MultiplexedSender( | |
35 base::WeakPtr<BlimpMessageProcessor> output_processor, | |
36 BlimpMessage::FeatureCase feature_case) | |
37 : output_processor_(output_processor), feature_case_(feature_case) {} | |
38 | |
39 MultiplexedSender::~MultiplexedSender() {} | |
40 | |
41 void MultiplexedSender::ProcessMessage( | |
42 std::unique_ptr<BlimpMessage> message, | |
43 const net::CompletionCallback& callback) { | |
44 DCHECK_EQ(feature_case_, message->feature_case()); | |
45 output_processor_->ProcessMessage(std::move(message), callback); | |
46 } | |
47 | |
48 } // namespace | |
49 | |
50 BlimpMessageMultiplexer::BlimpMessageMultiplexer( | |
51 BlimpMessageProcessor* output_processor) | |
52 : output_weak_factory_(output_processor) {} | |
53 | |
54 BlimpMessageMultiplexer::~BlimpMessageMultiplexer() {} | |
55 | |
56 std::unique_ptr<BlimpMessageProcessor> BlimpMessageMultiplexer::CreateSender( | |
57 BlimpMessage::FeatureCase feature_case) { | |
58 return base::MakeUnique<MultiplexedSender>(output_weak_factory_.GetWeakPtr(), | |
59 feature_case); | |
60 } | |
61 } // namespace blimp | |
OLD | NEW |