1 // Copyright 2013 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.
5 #include "content/child/websocket_dispatcher.h"
10 #include "base/logging.h"
11 #include "content/child/websocket_bridge.h"
12 #include "content/common/websocket_messages.h"
13 #include "ipc/ipc_message.h"
18 WebSocketDispatcher::WebSocketDispatcher() : channel_id_max_(0) {}
20 WebSocketDispatcher::~WebSocketDispatcher() {}
22 int WebSocketDispatcher::AddBridge(WebSocketBridge
* bridge
) {
24 bridges_
.insert(std::make_pair(channel_id_max_
, bridge
));
25 return channel_id_max_
;
28 void WebSocketDispatcher::RemoveBridge(int channel_id
) {
29 std::map
<int, WebSocketBridge
*>::iterator iter
= bridges_
.find(channel_id
);
30 if (iter
== bridges_
.end()) {
31 DVLOG(1) << "Remove a non-existent bridge(" << channel_id
<< ")";
37 bool WebSocketDispatcher::OnMessageReceived(const IPC::Message
& msg
) {
39 case WebSocketMsg_AddChannelResponse::ID
:
40 case WebSocketMsg_NotifyStartOpeningHandshake::ID
:
41 case WebSocketMsg_NotifyFinishOpeningHandshake::ID
:
42 case WebSocketMsg_NotifyFailure::ID
:
43 case WebSocketMsg_SendFrame::ID
:
44 case WebSocketMsg_FlowControl::ID
:
45 case WebSocketMsg_DropChannel::ID
:
46 case WebSocketMsg_NotifyClosing::ID
:
52 WebSocketBridge
* bridge
= GetBridge(msg
.routing_id(), msg
.type());
55 return bridge
->OnMessageReceived(msg
);
58 WebSocketBridge
* WebSocketDispatcher::GetBridge(int channel_id
, uint32 type
) {
59 std::map
<int, WebSocketBridge
*>::iterator iter
= bridges_
.find(channel_id
);
60 if (iter
== bridges_
.end()) {
61 DVLOG(1) << "No bridge for channel_id=" << channel_id
68 } // namespace content