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_DISPATCHER_H_ | |
6 #define BLIMP_NET_BLIMP_MESSAGE_DISPATCHER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/containers/small_map.h" | |
11 #include "base/threading/thread_checker.h" | |
12 #include "blimp/common/proto/blimp_message.pb.h" | |
13 #include "blimp/net/blimp_message_receiver.h" | |
14 #include "blimp/net/blimp_net_export.h" | |
15 | |
16 namespace blimp { | |
17 | |
18 // Multiplexing BlimpMessageReceiver which routes BlimpMessages to other | |
19 // receivers based on the messages' feature type. | |
20 class BLIMP_NET_EXPORT BlimpMessageDispatcher : public BlimpMessageReceiver { | |
21 public: | |
22 BlimpMessageDispatcher(); | |
23 ~BlimpMessageDispatcher() override; | |
24 | |
25 // Registers a message receiver which will process all messages | |
26 // with the type |type|. | |
Wez
2015/10/09 23:15:34
nit: Suggest "... of the specified |type|."
Kevin M
2015/10/10 00:42:34
Done.
| |
27 // Only one handler may be added per type. | |
28 // | |
29 // The caller must ensure that the lifetime of |handler| exceeds the lifetime | |
30 // of |this|. | |
Wez
2015/10/09 23:15:34
nit: Strictly |handler| only need be valid when On
Kevin M
2015/10/10 00:42:34
Done.
| |
31 void AddReceiver(BlimpMessage::Type type, BlimpMessageReceiver* handler); | |
32 | |
33 // Takes a BlimpMessage and dispatches it to the appropriate tab and | |
34 // feature-specific handler, based on the value of |message.type|. | |
35 // | |
36 // Logs an error if there is no BlimpMessageReceiver registered for | |
37 // |message.type|, or if the BlimpMessageReceiver failed to validate the | |
38 // message. | |
Wez
2015/10/09 23:15:34
This API is part of the BlimpMessageReceiver inter
Kevin M
2015/10/10 00:42:34
Done.
| |
39 bool OnMessage(const BlimpMessage& message) override; | |
40 | |
41 private: | |
42 base::SmallMap<std::map<BlimpMessage::Type, BlimpMessageReceiver*>> | |
43 feature_receiver_map_; | |
44 base::ThreadChecker thread_checker_; | |
Wez
2015/10/09 23:15:34
nit: This seems overkill - I don't think there's a
Kevin M
2015/10/10 00:42:34
OK, I'm still figuring out the right degree of ana
Wez
2015/10/12 23:47:21
Yeah, it's a fine line!
| |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(BlimpMessageDispatcher); | |
47 }; | |
48 | |
49 } // namespace blimp | |
50 | |
51 #endif // BLIMP_NET_BLIMP_MESSAGE_DISPATCHER_H_ | |
OLD | NEW |