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

Side by Side Diff: content/child/websocket_dispatcher.cc

Issue 2000113002: Delegate WebSocket message handlers to the loading task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address on reviews Created 4 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/websocket_dispatcher.h" 5 #include "content/child/websocket_dispatcher.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <map> 8 #include <map>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 17 matching lines...) Expand all
28 void WebSocketDispatcher::RemoveBridge(int channel_id) { 28 void WebSocketDispatcher::RemoveBridge(int channel_id) {
29 std::map<int, WebSocketBridge*>::iterator iter = bridges_.find(channel_id); 29 std::map<int, WebSocketBridge*>::iterator iter = bridges_.find(channel_id);
30 if (iter == bridges_.end()) { 30 if (iter == bridges_.end()) {
31 DVLOG(1) << "Remove a non-existent bridge(" << channel_id << ")"; 31 DVLOG(1) << "Remove a non-existent bridge(" << channel_id << ")";
32 return; 32 return;
33 } 33 }
34 bridges_.erase(iter); 34 bridges_.erase(iter);
35 } 35 }
36 36
37 bool WebSocketDispatcher::OnMessageReceived(const IPC::Message& msg) { 37 bool WebSocketDispatcher::OnMessageReceived(const IPC::Message& msg) {
38 if (!CanHandleMessage(msg))
39 return false;
40 WebSocketBridge* bridge = GetBridge(msg.routing_id(), msg.type());
41 if (!bridge)
42 return true;
43 return bridge->OnMessageReceived(msg);
44 }
45
46 bool WebSocketDispatcher::CanHandleMessage(const IPC::Message& msg) const {
38 switch (msg.type()) { 47 switch (msg.type()) {
39 case WebSocketMsg_AddChannelResponse::ID: 48 case WebSocketMsg_AddChannelResponse::ID:
40 case WebSocketMsg_NotifyStartOpeningHandshake::ID: 49 case WebSocketMsg_NotifyStartOpeningHandshake::ID:
41 case WebSocketMsg_NotifyFinishOpeningHandshake::ID: 50 case WebSocketMsg_NotifyFinishOpeningHandshake::ID:
42 case WebSocketMsg_NotifyFailure::ID: 51 case WebSocketMsg_NotifyFailure::ID:
43 case WebSocketMsg_SendFrame::ID: 52 case WebSocketMsg_SendFrame::ID:
44 case WebSocketMsg_FlowControl::ID: 53 case WebSocketMsg_FlowControl::ID:
45 case WebSocketMsg_DropChannel::ID: 54 case WebSocketMsg_DropChannel::ID:
46 case WebSocketMsg_NotifyClosing::ID: 55 case WebSocketMsg_NotifyClosing::ID:
47 break; 56 return true;
48 default: 57 default:
49 return false; 58 return false;
50 } 59 }
51
52 WebSocketBridge* bridge = GetBridge(msg.routing_id(), msg.type());
53 if (!bridge)
54 return true;
55 return bridge->OnMessageReceived(msg);
56 } 60 }
57 61
58 WebSocketBridge* WebSocketDispatcher::GetBridge(int channel_id, uint32_t type) { 62 WebSocketBridge* WebSocketDispatcher::GetBridge(int channel_id, uint32_t type) {
59 std::map<int, WebSocketBridge*>::iterator iter = bridges_.find(channel_id); 63 std::map<int, WebSocketBridge*>::iterator iter = bridges_.find(channel_id);
60 if (iter == bridges_.end()) { 64 if (iter == bridges_.end()) {
61 DVLOG(1) << "No bridge for channel_id=" << channel_id 65 DVLOG(1) << "No bridge for channel_id=" << channel_id
62 << ", type=" << type; 66 << ", type=" << type;
63 return NULL; 67 return NULL;
64 } 68 }
65 return iter->second; 69 return iter->second;
66 } 70 }
67 71
68 } // namespace content 72 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698