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

Side by Side Diff: content/common/socket_stream_dispatcher.cc

Issue 10668018: Websocket should fire 'error' event if no server available (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: For reland (tyoshino) Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « content/common/socket_stream_dispatcher.h ('k') | content/common/socket_stream_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/socket_stream_dispatcher.h" 5 #include "content/common/socket_stream_dispatcher.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/id_map.h" 10 #include "base/id_map.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string16.h"
15 #include "base/utf_string_conversions.h"
14 #include "content/common/child_thread.h" 16 #include "content/common/child_thread.h"
15 #include "content/common/socket_stream.h" 17 #include "content/common/socket_stream.h"
16 #include "content/common/socket_stream_handle_data.h" 18 #include "content/common/socket_stream_handle_data.h"
17 #include "content/common/socket_stream_messages.h" 19 #include "content/common/socket_stream_messages.h"
18 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
21 #include "net/base/net_errors.h"
19 #include "webkit/glue/websocketstreamhandle_bridge.h" 22 #include "webkit/glue/websocketstreamhandle_bridge.h"
20 #include "webkit/glue/websocketstreamhandle_delegate.h" 23 #include "webkit/glue/websocketstreamhandle_delegate.h"
21 24
22 namespace content { 25 namespace content {
23 26
24 // IPCWebSocketStreamHandleBridge is owned by each SocketStreamHandle. 27 // IPCWebSocketStreamHandleBridge is owned by each SocketStreamHandle.
25 // It communicates with the main browser process via SocketStreamDispatcher. 28 // It communicates with the main browser process via SocketStreamDispatcher.
26 class IPCWebSocketStreamHandleBridge 29 class IPCWebSocketStreamHandleBridge
27 : public webkit_glue::WebSocketStreamHandleBridge { 30 : public webkit_glue::WebSocketStreamHandleBridge {
28 public: 31 public:
(...skipping 12 matching lines...) Expand all
41 // webkit_glue::WebSocketStreamHandleBridge methods. 44 // webkit_glue::WebSocketStreamHandleBridge methods.
42 virtual void Connect(const GURL& url) OVERRIDE; 45 virtual void Connect(const GURL& url) OVERRIDE;
43 virtual bool Send(const std::vector<char>& data) OVERRIDE; 46 virtual bool Send(const std::vector<char>& data) OVERRIDE;
44 virtual void Close() OVERRIDE; 47 virtual void Close() OVERRIDE;
45 48
46 // Called by SocketStreamDispatcher. 49 // Called by SocketStreamDispatcher.
47 void OnConnected(int max_amount_send_allowed); 50 void OnConnected(int max_amount_send_allowed);
48 void OnSentData(int amount_sent); 51 void OnSentData(int amount_sent);
49 void OnReceivedData(const std::vector<char>& data); 52 void OnReceivedData(const std::vector<char>& data);
50 void OnClosed(); 53 void OnClosed();
54 void OnFailed(int error_code, const char* error_msg);
51 55
52 private: 56 private:
53 virtual ~IPCWebSocketStreamHandleBridge(); 57 virtual ~IPCWebSocketStreamHandleBridge();
54 58
55 void DoConnect(const GURL& url); 59 void DoConnect(const GURL& url);
56 void DoClose(); 60 void DoClose();
57 61
58 // The ID for this bridge and corresponding SocketStream instance in the 62 // The ID for this bridge and corresponding SocketStream instance in the
59 // browser process. 63 // browser process.
60 int socket_id_; 64 int socket_id_;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (socket_id_ != kNoSocketId) { 156 if (socket_id_ != kNoSocketId) {
153 all_bridges.Get().Remove(socket_id_); 157 all_bridges.Get().Remove(socket_id_);
154 socket_id_ = kNoSocketId; 158 socket_id_ = kNoSocketId;
155 } 159 }
156 if (delegate_) 160 if (delegate_)
157 delegate_->DidClose(handle_); 161 delegate_->DidClose(handle_);
158 delegate_ = NULL; 162 delegate_ = NULL;
159 Release(); 163 Release();
160 } 164 }
161 165
166 void IPCWebSocketStreamHandleBridge::OnFailed(int error_code,
167 const char* error_msg) {
168 DVLOG(1) << "Bridge #" << socket_id_ << " OnFailed (error_code=" << error_code
169 << ")";
170 if (delegate_)
171 delegate_->DidFail(handle_, error_code, ASCIIToUTF16(error_msg));
172 }
173
162 void IPCWebSocketStreamHandleBridge::DoConnect(const GURL& url) { 174 void IPCWebSocketStreamHandleBridge::DoConnect(const GURL& url) {
163 DCHECK(child_thread_); 175 DCHECK(child_thread_);
164 DCHECK_EQ(socket_id_, kNoSocketId); 176 DCHECK_EQ(socket_id_, kNoSocketId);
165 if (delegate_) 177 if (delegate_)
166 delegate_->WillOpenStream(handle_, url); 178 delegate_->WillOpenStream(handle_, url);
167 179
168 socket_id_ = all_bridges.Get().Add(this); 180 socket_id_ = all_bridges.Get().Add(this);
169 DCHECK_NE(socket_id_, kNoSocketId); 181 DCHECK_NE(socket_id_, kNoSocketId);
170 int render_view_id = MSG_ROUTING_NONE; 182 int render_view_id = MSG_ROUTING_NONE;
171 const SocketStreamHandleData* data = 183 const SocketStreamHandleData* data =
(...skipping 28 matching lines...) Expand all
200 ChildThread::current(), handle, delegate); 212 ChildThread::current(), handle, delegate);
201 } 213 }
202 214
203 bool SocketStreamDispatcher::OnMessageReceived(const IPC::Message& msg) { 215 bool SocketStreamDispatcher::OnMessageReceived(const IPC::Message& msg) {
204 bool handled = true; 216 bool handled = true;
205 IPC_BEGIN_MESSAGE_MAP(SocketStreamDispatcher, msg) 217 IPC_BEGIN_MESSAGE_MAP(SocketStreamDispatcher, msg)
206 IPC_MESSAGE_HANDLER(SocketStreamMsg_Connected, OnConnected) 218 IPC_MESSAGE_HANDLER(SocketStreamMsg_Connected, OnConnected)
207 IPC_MESSAGE_HANDLER(SocketStreamMsg_SentData, OnSentData) 219 IPC_MESSAGE_HANDLER(SocketStreamMsg_SentData, OnSentData)
208 IPC_MESSAGE_HANDLER(SocketStreamMsg_ReceivedData, OnReceivedData) 220 IPC_MESSAGE_HANDLER(SocketStreamMsg_ReceivedData, OnReceivedData)
209 IPC_MESSAGE_HANDLER(SocketStreamMsg_Closed, OnClosed) 221 IPC_MESSAGE_HANDLER(SocketStreamMsg_Closed, OnClosed)
222 IPC_MESSAGE_HANDLER(SocketStreamMsg_Failed, OnFailed)
210 IPC_MESSAGE_UNHANDLED(handled = false) 223 IPC_MESSAGE_UNHANDLED(handled = false)
211 IPC_END_MESSAGE_MAP() 224 IPC_END_MESSAGE_MAP()
212 return handled; 225 return handled;
213 } 226 }
214 227
215 void SocketStreamDispatcher::OnConnected(int socket_id, 228 void SocketStreamDispatcher::OnConnected(int socket_id,
216 int max_pending_send_allowed) { 229 int max_pending_send_allowed) {
217 DVLOG(1) << "SocketStreamDispatcher::OnConnected (max_pending_send_allowed=" 230 DVLOG(1) << "SocketStreamDispatcher::OnConnected (max_pending_send_allowed="
218 << max_pending_send_allowed << ") to socket_id=" << socket_id; 231 << max_pending_send_allowed << ") to socket_id=" << socket_id;
219 232
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 DVLOG(1) << "SocketStreamDispatcher::OnClosed to socket_id=" << socket_id; 267 DVLOG(1) << "SocketStreamDispatcher::OnClosed to socket_id=" << socket_id;
255 268
256 IPCWebSocketStreamHandleBridge* bridge = 269 IPCWebSocketStreamHandleBridge* bridge =
257 IPCWebSocketStreamHandleBridge::FromSocketId(socket_id); 270 IPCWebSocketStreamHandleBridge::FromSocketId(socket_id);
258 if (bridge) 271 if (bridge)
259 bridge->OnClosed(); 272 bridge->OnClosed();
260 else 273 else
261 DLOG(ERROR) << "No bridge for socket_id=" << socket_id; 274 DLOG(ERROR) << "No bridge for socket_id=" << socket_id;
262 } 275 }
263 276
277 void SocketStreamDispatcher::OnFailed(int socket_id, int error_code) {
278 IPCWebSocketStreamHandleBridge* bridge =
279 IPCWebSocketStreamHandleBridge::FromSocketId(socket_id);
280 if (bridge)
281 bridge->OnFailed(error_code, net::ErrorToString(error_code));
282 else
283 DLOG(ERROR) << "No bridge for socket_id=" << socket_id;
284 }
285
264 } // namespace content 286 } // namespace content
OLDNEW
« no previous file with comments | « content/common/socket_stream_dispatcher.h ('k') | content/common/socket_stream_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698