| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/child/websocket_dispatcher.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 #include <map> | |
| 9 | |
| 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" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 WebSocketDispatcher::WebSocketDispatcher() | |
| 19 : channel_id_max_(0), | |
| 20 weak_ptr_factory_(this) {} | |
| 21 | |
| 22 WebSocketDispatcher::~WebSocketDispatcher() {} | |
| 23 | |
| 24 bool WebSocketDispatcher::CanHandleMessage(const IPC::Message& msg) { | |
| 25 switch (msg.type()) { | |
| 26 case WebSocketMsg_AddChannelResponse::ID: | |
| 27 case WebSocketMsg_NotifyStartOpeningHandshake::ID: | |
| 28 case WebSocketMsg_NotifyFinishOpeningHandshake::ID: | |
| 29 case WebSocketMsg_NotifyFailure::ID: | |
| 30 case WebSocketMsg_SendFrame::ID: | |
| 31 case WebSocketMsg_FlowControl::ID: | |
| 32 case WebSocketMsg_DropChannel::ID: | |
| 33 case WebSocketMsg_NotifyClosing::ID: | |
| 34 return true; | |
| 35 default: | |
| 36 return false; | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 int WebSocketDispatcher::AddBridge(WebSocketBridge* bridge) { | |
| 41 ++channel_id_max_; | |
| 42 bridges_.insert(std::make_pair(channel_id_max_, bridge)); | |
| 43 return channel_id_max_; | |
| 44 } | |
| 45 | |
| 46 void WebSocketDispatcher::RemoveBridge(int channel_id) { | |
| 47 std::map<int, WebSocketBridge*>::iterator iter = bridges_.find(channel_id); | |
| 48 if (iter == bridges_.end()) { | |
| 49 DVLOG(1) << "Remove a non-existent bridge(" << channel_id << ")"; | |
| 50 return; | |
| 51 } | |
| 52 bridges_.erase(iter); | |
| 53 } | |
| 54 | |
| 55 bool WebSocketDispatcher::OnMessageReceived(const IPC::Message& msg) { | |
| 56 if (!CanHandleMessage(msg)) | |
| 57 return false; | |
| 58 WebSocketBridge* bridge = GetBridge(msg.routing_id(), msg.type()); | |
| 59 if (!bridge) | |
| 60 return true; | |
| 61 return bridge->OnMessageReceived(msg); | |
| 62 } | |
| 63 | |
| 64 WebSocketBridge* WebSocketDispatcher::GetBridge(int channel_id, uint32_t type) { | |
| 65 std::map<int, WebSocketBridge*>::iterator iter = bridges_.find(channel_id); | |
| 66 if (iter == bridges_.end()) { | |
| 67 DVLOG(1) << "No bridge for channel_id=" << channel_id | |
| 68 << ", type=" << type; | |
| 69 return NULL; | |
| 70 } | |
| 71 return iter->second; | |
| 72 } | |
| 73 | |
| 74 } // namespace content | |
| OLD | NEW |