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

Side by Side Diff: content/browser/renderer_host/websocket_dispatcher_host.cc

Issue 26544003: Make net::WebSocketChannel deletion safe and enable new IPCs (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add missing "virtual" keyword Created 7 years, 2 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/browser/renderer_host/websocket_dispatcher_host.h" 5 #include "content/browser/renderer_host/websocket_dispatcher_host.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "content/browser/renderer_host/websocket_host.h" 12 #include "content/browser/renderer_host/websocket_host.h"
13 #include "content/common/websocket_messages.h" 13 #include "content/common/websocket_messages.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 namespace {
18
19 typedef WebSocketDispatcherHost::WebSocketHostState WebSocketHostState;
jochen (gone - plz use gerrit) 2013/10/23 14:01:28 I find this a bit confusing
Adam Rice 2013/10/24 02:22:23 It's just to avoid having WebSocketDispatcherHost:
20
21 } // namespace
22
17 WebSocketDispatcherHost::WebSocketDispatcherHost( 23 WebSocketDispatcherHost::WebSocketDispatcherHost(
18 const GetRequestContextCallback& get_context_callback) 24 const GetRequestContextCallback& get_context_callback)
19 : get_context_callback_(get_context_callback), 25 : get_context_callback_(get_context_callback),
20 websocket_host_factory_( 26 websocket_host_factory_(
21 base::Bind(&WebSocketDispatcherHost::CreateWebSocketHost, 27 base::Bind(&WebSocketDispatcherHost::CreateWebSocketHost,
22 base::Unretained(this))) {} 28 base::Unretained(this))) {}
23 29
24 WebSocketDispatcherHost::WebSocketDispatcherHost( 30 WebSocketDispatcherHost::WebSocketDispatcherHost(
25 const GetRequestContextCallback& get_context_callback, 31 const GetRequestContextCallback& get_context_callback,
26 const WebSocketHostFactory& websocket_host_factory) 32 const WebSocketHostFactory& websocket_host_factory)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return true; // We handled the message (by ignoring it). 72 return true; // We handled the message (by ignoring it).
67 } 73 }
68 return host->OnMessageReceived(message, message_was_ok); 74 return host->OnMessageReceived(message, message_was_ok);
69 } 75 }
70 76
71 WebSocketHost* WebSocketDispatcherHost::GetHost(int routing_id) const { 77 WebSocketHost* WebSocketDispatcherHost::GetHost(int routing_id) const {
72 WebSocketHostTable::const_iterator it = hosts_.find(routing_id); 78 WebSocketHostTable::const_iterator it = hosts_.find(routing_id);
73 return it == hosts_.end() ? NULL : it->second; 79 return it == hosts_.end() ? NULL : it->second;
74 } 80 }
75 81
76 void WebSocketDispatcherHost::SendOrDrop(IPC::Message* message) { 82 WebSocketHostState WebSocketDispatcherHost::SendOrDrop(IPC::Message* message) {
77 if (!Send(message)) { 83 if (!Send(message)) {
78 DVLOG(1) << "Sending of message type " << message->type() 84 DVLOG(1) << "Sending of message type " << message->type()
79 << " failed. Dropping channel."; 85 << " failed. Dropping channel.";
80 DeleteWebSocketHost(message->routing_id()); 86 DeleteWebSocketHost(message->routing_id());
87 return WEBSOCKET_HOST_DELETED;
81 } 88 }
89 return WEBSOCKET_HOST_ALIVE;
82 } 90 }
83 91
84 void WebSocketDispatcherHost::SendAddChannelResponse( 92 WebSocketHostState WebSocketDispatcherHost::SendAddChannelResponse(
85 int routing_id, 93 int routing_id,
86 bool fail, 94 bool fail,
87 const std::string& selected_protocol, 95 const std::string& selected_protocol,
88 const std::string& extensions) { 96 const std::string& extensions) {
89 SendOrDrop(new WebSocketMsg_AddChannelResponse( 97 if (SendOrDrop(new WebSocketMsg_AddChannelResponse(
90 routing_id, fail, selected_protocol, extensions)); 98 routing_id, fail, selected_protocol, extensions)) ==
91 if (fail) 99 WEBSOCKET_HOST_DELETED)
100 return WEBSOCKET_HOST_DELETED;
101 if (fail) {
92 DeleteWebSocketHost(routing_id); 102 DeleteWebSocketHost(routing_id);
103 return WEBSOCKET_HOST_DELETED;
104 }
105 return WEBSOCKET_HOST_ALIVE;
93 } 106 }
94 107
95 void WebSocketDispatcherHost::SendFrame(int routing_id, 108 WebSocketHostState WebSocketDispatcherHost::SendFrame(
96 bool fin, 109 int routing_id,
97 WebSocketMessageType type, 110 bool fin,
98 const std::vector<char>& data) { 111 WebSocketMessageType type,
99 SendOrDrop(new WebSocketMsg_SendFrame(routing_id, fin, type, data)); 112 const std::vector<char>& data) {
113 return SendOrDrop(new WebSocketMsg_SendFrame(routing_id, fin, type, data));
100 } 114 }
101 115
102 void WebSocketDispatcherHost::SendFlowControl(int routing_id, int64 quota) { 116 WebSocketHostState WebSocketDispatcherHost::SendFlowControl(int routing_id,
103 SendOrDrop(new WebSocketMsg_FlowControl(routing_id, quota)); 117 int64 quota) {
118 return SendOrDrop(new WebSocketMsg_FlowControl(routing_id, quota));
104 } 119 }
105 120
106 void WebSocketDispatcherHost::SendClosing(int routing_id) { 121 WebSocketHostState WebSocketDispatcherHost::SendClosing(int routing_id) {
107 // TODO(ricea): Implement the SendClosing IPC. 122 // TODO(ricea): Implement the SendClosing IPC.
123 return WEBSOCKET_HOST_ALIVE;
108 } 124 }
109 125
110 void WebSocketDispatcherHost::DoDropChannel(int routing_id, 126 WebSocketHostState WebSocketDispatcherHost::DoDropChannel(
111 uint16 code, 127 int routing_id,
112 const std::string& reason) { 128 uint16 code,
113 SendOrDrop(new WebSocketMsg_DropChannel(routing_id, code, reason)); 129 const std::string& reason) {
130 if (SendOrDrop(new WebSocketMsg_DropChannel(routing_id, code, reason)) ==
131 WEBSOCKET_HOST_DELETED)
132 return WEBSOCKET_HOST_DELETED;
114 DeleteWebSocketHost(routing_id); 133 DeleteWebSocketHost(routing_id);
134 return WEBSOCKET_HOST_DELETED;
115 } 135 }
116 136
117 WebSocketDispatcherHost::~WebSocketDispatcherHost() { 137 WebSocketDispatcherHost::~WebSocketDispatcherHost() {
118 STLDeleteContainerPairSecondPointers(hosts_.begin(), hosts_.end()); 138 STLDeleteContainerPairSecondPointers(hosts_.begin(), hosts_.end());
119 } 139 }
120 140
121 void WebSocketDispatcherHost::DeleteWebSocketHost(int routing_id) { 141 void WebSocketDispatcherHost::DeleteWebSocketHost(int routing_id) {
122 WebSocketHostTable::iterator it = hosts_.find(routing_id); 142 WebSocketHostTable::iterator it = hosts_.find(routing_id);
123 if (it != hosts_.end()) { 143 DCHECK(it != hosts_.end());
124 delete it->second; 144 delete it->second;
125 hosts_.erase(it); 145 hosts_.erase(it);
126 }
127 } 146 }
128 147
129 } // namespace content 148 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698