| 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_dispatcher.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 | |
| 11 namespace blimp { | |
| 12 namespace { | |
| 13 | |
| 14 std::string BlimpMessageToDebugString(const BlimpMessage& message) { | |
| 15 return base::StringPrintf("<message type=%d>", message.type()); | |
| 16 } | |
| 17 | |
| 18 } // namespace | |
| 19 | |
| 20 BlimpMessageDispatcher::BlimpMessageDispatcher() {} | |
| 21 | |
| 22 BlimpMessageDispatcher::~BlimpMessageDispatcher() {} | |
| 23 | |
| 24 void BlimpMessageDispatcher::AddReceiver(BlimpMessage::Type type, | |
| 25 BlimpMessageReceiver* receiver) { | |
| 26 DCHECK(receiver); | |
| 27 if (feature_receiver_map_.find(type) == feature_receiver_map_.end()) { | |
| 28 feature_receiver_map_.insert(std::make_pair(type, receiver)); | |
| 29 } else { | |
| 30 DLOG(FATAL) << "Handler already registered for type=" << type << "."; | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 net::Error BlimpMessageDispatcher::OnBlimpMessage(const BlimpMessage& message) { | |
| 35 auto receiver_iter = feature_receiver_map_.find(message.type()); | |
| 36 if (receiver_iter == feature_receiver_map_.end()) { | |
| 37 DLOG(FATAL) << "No registered receiver for " | |
| 38 << BlimpMessageToDebugString(message) << "."; | |
| 39 return net::ERR_NOT_IMPLEMENTED; | |
| 40 } | |
| 41 | |
| 42 return receiver_iter->second->OnBlimpMessage(message); | |
| 43 } | |
| 44 | |
| 45 } // namespace blimp | |
| OLD | NEW |