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