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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/net/blimp_message_dispatcher.cc
diff --git a/blimp/net/blimp_message_dispatcher.cc b/blimp/net/blimp_message_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8c07c9f3bd566feecc9bf98fb637c6af2bea085d
--- /dev/null
+++ b/blimp/net/blimp_message_dispatcher.cc
@@ -0,0 +1,45 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/net/blimp_message_dispatcher.h"
+
+#include <string>
+
+#include "base/strings/stringprintf.h"
+
+namespace blimp {
+namespace {
+
+std::string BlimpMessageToDebugString(const BlimpMessage& message) {
+ return base::StringPrintf("<message type=%d>", message.type());
+}
+
+} // namespace
+
+BlimpMessageDispatcher::BlimpMessageDispatcher() {}
+
+BlimpMessageDispatcher::~BlimpMessageDispatcher() {}
+
+void BlimpMessageDispatcher::AddReceiver(BlimpMessage::Type type,
+ BlimpMessageReceiver* receiver) {
+ DCHECK(receiver);
+ if (feature_receiver_map_.find(type) == feature_receiver_map_.end()) {
+ feature_receiver_map_.insert(std::make_pair(type, receiver));
+ } else {
+ DLOG(FATAL) << "Handler already registered for type=" << type << ".";
+ }
+}
+
+net::Error BlimpMessageDispatcher::OnBlimpMessage(const BlimpMessage& message) {
+ auto receiver_iter = feature_receiver_map_.find(message.type());
+ if (receiver_iter == feature_receiver_map_.end()) {
+ DLOG(FATAL) << "No registered receiver for "
+ << BlimpMessageToDebugString(message) << ".";
+ return net::ERR_NOT_IMPLEMENTED;
+ }
+
+ return receiver_iter->second->OnBlimpMessage(message);
+}
+
+} // namespace blimp
« 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