Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: blimp/net/blimp_message_dispatcher.cc

Issue 1324263003: Blimp: create MessageDispatcher class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp-protos
Patch Set: Resolve naming collision for "net" Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « blimp/net/blimp_message_dispatcher.h ('k') | blimp/net/blimp_message_dispatcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « blimp/net/blimp_message_dispatcher.h ('k') | blimp/net/blimp_message_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698