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_DEMULTIPLEXER_H_ | |
6 #define BLIMP_NET_BLIMP_MESSAGE_DEMULTIPLEXER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/containers/small_map.h" | |
11 #include "base/macros.h" | |
12 #include "base/threading/thread_checker.h" | |
13 #include "blimp/common/proto/blimp_message.pb.h" | |
14 #include "blimp/net/blimp_message_processor.h" | |
15 #include "blimp/net/blimp_net_export.h" | |
16 | |
17 namespace blimp { | |
18 | |
19 // Multiplexing BlimpMessageProcessor which routes BlimpMessages to message | |
20 // processors based on the specific feature. | |
21 // BlimpMessageDemultiplexer is created on the UI thread, and then used and | |
22 // destroyed on the IO thread. | |
23 class BLIMP_NET_EXPORT BlimpMessageDemultiplexer | |
24 : public BlimpMessageProcessor { | |
25 public: | |
26 BlimpMessageDemultiplexer(); | |
27 ~BlimpMessageDemultiplexer() override; | |
28 | |
29 // Registers a message processor which will receive all messages | |
30 // of the |feature_case| specified. | |
31 // Only one handler may be added per type. | |
32 // | |
33 // |handler| must be valid when ProcessMessage() is called. | |
34 void AddProcessor(BlimpMessage::FeatureCase feature_case, | |
35 BlimpMessageProcessor* handler); | |
36 | |
37 // BlimpMessageProcessor implementation. | |
38 void ProcessMessage(std::unique_ptr<BlimpMessage> message, | |
39 const net::CompletionCallback& callback) override; | |
40 | |
41 private: | |
42 base::SmallMap<std::map<BlimpMessage::FeatureCase, BlimpMessageProcessor*>> | |
43 feature_receiver_map_; | |
44 | |
45 DISALLOW_COPY_AND_ASSIGN(BlimpMessageDemultiplexer); | |
46 }; | |
47 | |
48 } // namespace blimp | |
49 | |
50 #endif // BLIMP_NET_BLIMP_MESSAGE_DEMULTIPLEXER_H_ | |
OLD | NEW |