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_demultiplexer.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 "blimp/common/logging.h" | 10 #include "blimp/common/logging.h" |
11 #include "blimp/net/common.h" | 11 #include "blimp/net/common.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 | 13 |
14 namespace blimp { | 14 namespace blimp { |
15 | 15 |
16 BlimpMessageDemultiplexer::BlimpMessageDemultiplexer() {} | 16 BlimpMessageDemultiplexer::BlimpMessageDemultiplexer() {} |
17 | 17 |
18 BlimpMessageDemultiplexer::~BlimpMessageDemultiplexer() {} | 18 BlimpMessageDemultiplexer::~BlimpMessageDemultiplexer() {} |
19 | 19 |
20 void BlimpMessageDemultiplexer::AddProcessor(BlimpMessage::Type type, | 20 void BlimpMessageDemultiplexer::AddProcessor(BlimpMessage::FeatureCase type, |
21 BlimpMessageProcessor* receiver) { | 21 BlimpMessageProcessor* receiver) { |
22 DCHECK(receiver); | 22 DCHECK(receiver); |
23 if (feature_receiver_map_.find(type) == feature_receiver_map_.end()) { | 23 if (feature_receiver_map_.find(type) == feature_receiver_map_.end()) { |
24 feature_receiver_map_.insert(std::make_pair(type, receiver)); | 24 feature_receiver_map_.insert(std::make_pair(type, receiver)); |
25 } else { | 25 } else { |
26 DLOG(FATAL) << "Handler already registered for type=" << type << "."; | 26 DLOG(FATAL) << "Handler already registered for type=" << type << "."; |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 void BlimpMessageDemultiplexer::ProcessMessage( | 30 void BlimpMessageDemultiplexer::ProcessMessage( |
31 std::unique_ptr<BlimpMessage> message, | 31 std::unique_ptr<BlimpMessage> message, |
32 const net::CompletionCallback& callback) { | 32 const net::CompletionCallback& callback) { |
33 DVLOG(2) << "ProcessMessage : " << *message; | 33 DVLOG(2) << "ProcessMessage : " << *message; |
34 auto receiver_iter = feature_receiver_map_.find(message->type()); | 34 auto receiver_iter = feature_receiver_map_.find(message->feature_case()); |
35 if (receiver_iter == feature_receiver_map_.end()) { | 35 if (receiver_iter == feature_receiver_map_.end()) { |
36 DLOG(ERROR) << "No registered receiver for " << *message << "."; | 36 DLOG(ERROR) << "No registered receiver for " << *message << "."; |
37 if (!callback.is_null()) { | 37 if (!callback.is_null()) { |
38 callback.Run(net::ERR_NOT_IMPLEMENTED); | 38 callback.Run(net::ERR_NOT_IMPLEMENTED); |
39 } | 39 } |
40 return; | 40 return; |
41 } | 41 } |
42 | 42 |
43 DVLOG(2) << "Routed message " << *message << "."; | 43 DVLOG(2) << "Routed message " << *message << "."; |
44 receiver_iter->second->ProcessMessage(std::move(message), callback); | 44 receiver_iter->second->ProcessMessage(std::move(message), callback); |
45 } | 45 } |
46 | 46 |
47 } // namespace blimp | 47 } // namespace blimp |
OLD | NEW |