OLD | NEW |
---|---|
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/bind.h" | |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "content/child/websocket_bridge.h" | 12 #include "content/child/websocket_bridge.h" |
12 #include "content/common/websocket_messages.h" | 13 #include "content/common/websocket_messages.h" |
13 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 WebSocketDispatcher::WebSocketDispatcher() : channel_id_max_(0) {} | 19 WebSocketDispatcher::WebSocketDispatcher() : channel_id_max_(0) { |
20 } | |
19 | 21 |
20 WebSocketDispatcher::~WebSocketDispatcher() {} | 22 WebSocketDispatcher::~WebSocketDispatcher() {} |
21 | 23 |
22 int WebSocketDispatcher::AddBridge(WebSocketBridge* bridge) { | 24 int WebSocketDispatcher::AddBridge(WebSocketBridge* bridge) { |
23 ++channel_id_max_; | 25 ++channel_id_max_; |
24 bridges_.insert(std::make_pair(channel_id_max_, bridge)); | 26 bridges_.insert(std::make_pair(channel_id_max_, bridge)); |
25 return channel_id_max_; | 27 return channel_id_max_; |
26 } | 28 } |
27 | 29 |
28 void WebSocketDispatcher::RemoveBridge(int channel_id) { | 30 void WebSocketDispatcher::RemoveBridge(int channel_id) { |
(...skipping 13 matching lines...) Expand all Loading... | |
42 case WebSocketMsg_NotifyFailure::ID: | 44 case WebSocketMsg_NotifyFailure::ID: |
43 case WebSocketMsg_SendFrame::ID: | 45 case WebSocketMsg_SendFrame::ID: |
44 case WebSocketMsg_FlowControl::ID: | 46 case WebSocketMsg_FlowControl::ID: |
45 case WebSocketMsg_DropChannel::ID: | 47 case WebSocketMsg_DropChannel::ID: |
46 case WebSocketMsg_NotifyClosing::ID: | 48 case WebSocketMsg_NotifyClosing::ID: |
47 break; | 49 break; |
48 default: | 50 default: |
49 return false; | 51 return false; |
50 } | 52 } |
51 | 53 |
54 loading_task_runner_->PostTask(FROM_HERE, | |
Sami
2016/05/23 09:56:07
I guess what will end up happening here is that On
| |
55 base::Bind(&WebSocketDispatcher::OnMessageReceivedOnLoadingTaskRunner, | |
56 base::Unretained(this), msg)); | |
57 return true; | |
58 } | |
59 | |
60 void WebSocketDispatcher::SetLoadingTaskRunner( | |
61 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner) { | |
62 loading_task_runner_ = loading_task_runner; | |
63 } | |
64 | |
65 void WebSocketDispatcher::OnMessageReceivedOnLoadingTaskRunner( | |
66 IPC::Message msg) { | |
52 WebSocketBridge* bridge = GetBridge(msg.routing_id(), msg.type()); | 67 WebSocketBridge* bridge = GetBridge(msg.routing_id(), msg.type()); |
53 if (!bridge) | 68 if (bridge) |
54 return true; | 69 bridge->OnMessageReceived(msg); |
55 return bridge->OnMessageReceived(msg); | |
56 } | 70 } |
57 | 71 |
58 WebSocketBridge* WebSocketDispatcher::GetBridge(int channel_id, uint32_t type) { | 72 WebSocketBridge* WebSocketDispatcher::GetBridge(int channel_id, uint32_t type) { |
59 std::map<int, WebSocketBridge*>::iterator iter = bridges_.find(channel_id); | 73 std::map<int, WebSocketBridge*>::iterator iter = bridges_.find(channel_id); |
60 if (iter == bridges_.end()) { | 74 if (iter == bridges_.end()) { |
61 DVLOG(1) << "No bridge for channel_id=" << channel_id | 75 DVLOG(1) << "No bridge for channel_id=" << channel_id |
62 << ", type=" << type; | 76 << ", type=" << type; |
63 return NULL; | 77 return NULL; |
64 } | 78 } |
65 return iter->second; | 79 return iter->second; |
66 } | 80 } |
67 | 81 |
68 } // namespace content | 82 } // namespace content |
OLD | NEW |