Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / child / websocket_dispatcher.cc
blobc762a4a4f7845053340b37099cdaa533705a3cf9
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"
7 #include <stdint.h>
8 #include <map>
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"
14 #include "url/gurl.h"
16 namespace content {
18 WebSocketDispatcher::WebSocketDispatcher() : channel_id_max_(0) {}
20 WebSocketDispatcher::~WebSocketDispatcher() {}
22 int WebSocketDispatcher::AddBridge(WebSocketBridge* bridge) {
23 ++channel_id_max_;
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 << ")";
32 return;
34 bridges_.erase(iter);
37 bool WebSocketDispatcher::OnMessageReceived(const IPC::Message& msg) {
38 switch (msg.type()) {
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:
47 break;
48 default:
49 return false;
52 WebSocketBridge* bridge = GetBridge(msg.routing_id(), msg.type());
53 if (!bridge)
54 return true;
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
62 << ", type=" << type;
63 return NULL;
65 return iter->second;
68 } // namespace content