OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "blimp/net/blimp_message_dispatcher.h" | 5 #include "blimp/net/blimp_message_demultiplexer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "net/base/net_errors.h" | |
10 | 11 |
11 namespace blimp { | 12 namespace blimp { |
12 namespace { | 13 namespace { |
13 | 14 |
14 std::string BlimpMessageToDebugString(const BlimpMessage& message) { | 15 std::string BlimpMessageToDebugString(const BlimpMessage& message) { |
15 return base::StringPrintf("<message type=%d>", message.type()); | 16 return base::StringPrintf("<message type=%d>", message.type()); |
16 } | 17 } |
17 | 18 |
18 } // namespace | 19 } // namespace |
19 | 20 |
20 BlimpMessageDispatcher::BlimpMessageDispatcher() {} | 21 BlimpMessageDemultiplexer::BlimpMessageDemultiplexer() {} |
21 | 22 |
22 BlimpMessageDispatcher::~BlimpMessageDispatcher() {} | 23 BlimpMessageDemultiplexer::~BlimpMessageDemultiplexer() {} |
23 | 24 |
24 void BlimpMessageDispatcher::AddReceiver(BlimpMessage::Type type, | 25 void BlimpMessageDemultiplexer::AddProcessor(BlimpMessage::Type type, |
25 BlimpMessageReceiver* receiver) { | 26 BlimpMessageProcessor* receiver) { |
26 DCHECK(receiver); | 27 DCHECK(receiver); |
27 if (feature_receiver_map_.find(type) == feature_receiver_map_.end()) { | 28 if (feature_receiver_map_.find(type) == feature_receiver_map_.end()) { |
28 feature_receiver_map_.insert(std::make_pair(type, receiver)); | 29 feature_receiver_map_.insert(std::make_pair(type, receiver)); |
29 } else { | 30 } else { |
30 DLOG(FATAL) << "Handler already registered for type=" << type << "."; | 31 DLOG(FATAL) << "Handler already registered for type=" << type << "."; |
31 } | 32 } |
32 } | 33 } |
33 | 34 |
34 net::Error BlimpMessageDispatcher::OnBlimpMessage(const BlimpMessage& message) { | 35 void BlimpMessageDemultiplexer::ProcessMessage( |
36 const BlimpMessage& message, | |
37 const net::CompletionCallback& callback) { | |
35 auto receiver_iter = feature_receiver_map_.find(message.type()); | 38 auto receiver_iter = feature_receiver_map_.find(message.type()); |
36 if (receiver_iter == feature_receiver_map_.end()) { | 39 if (receiver_iter == feature_receiver_map_.end()) { |
37 DLOG(FATAL) << "No registered receiver for " | 40 DLOG(FATAL) << "No registered receiver for " |
38 << BlimpMessageToDebugString(message) << "."; | 41 << BlimpMessageToDebugString(message) << "."; |
39 return net::ERR_NOT_IMPLEMENTED; | 42 callback.Run(net::ERR_NOT_IMPLEMENTED); |
Wez
2015/11/12 03:45:56
nit: Cope w/ null callback?
Kevin M
2015/11/12 19:03:47
Done.
| |
40 } | 43 } |
41 | 44 |
42 return receiver_iter->second->OnBlimpMessage(message); | 45 receiver_iter->second->ProcessMessage(message, callback); |
43 } | 46 } |
44 | 47 |
45 } // namespace blimp | 48 } // namespace blimp |
OLD | NEW |