OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/common/socket_stream_dispatcher.h" | 5 #include "chrome/common/socket_stream_dispatcher.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/id_map.h" | 9 #include "base/id_map.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 // webkit_glue::WebSocketStreamHandleBridge methods. | 38 // webkit_glue::WebSocketStreamHandleBridge methods. |
39 virtual void Connect(const GURL& url); | 39 virtual void Connect(const GURL& url); |
40 virtual bool Send(const std::vector<char>& data); | 40 virtual bool Send(const std::vector<char>& data); |
41 virtual void Close(); | 41 virtual void Close(); |
42 | 42 |
43 // Called by SocketStreamDispatcher. | 43 // Called by SocketStreamDispatcher. |
44 void OnConnected(int max_amount_send_allowed); | 44 void OnConnected(int max_amount_send_allowed); |
45 void OnSentData(int amount_sent); | 45 void OnSentData(int amount_sent); |
46 void OnReceivedData(const std::vector<char>& data); | 46 void OnReceivedData(const std::vector<char>& data); |
47 void OnClosed(); | 47 void OnClosed(); |
| 48 void OnError(int error); |
48 | 49 |
49 private: | 50 private: |
50 virtual ~IPCWebSocketStreamHandleBridge(); | 51 virtual ~IPCWebSocketStreamHandleBridge(); |
51 | 52 |
52 void DoConnect(const GURL& url); | 53 void DoConnect(const GURL& url); |
53 int socket_id_; | 54 int socket_id_; |
54 | 55 |
55 ChildThread* child_thread_; | 56 ChildThread* child_thread_; |
56 WebKit::WebSocketStreamHandle* handle_; | 57 WebKit::WebSocketStreamHandle* handle_; |
57 webkit_glue::WebSocketStreamHandleDelegate* delegate_; | 58 webkit_glue::WebSocketStreamHandleDelegate* delegate_; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 if (socket_id_ != chrome_common_net::kNoSocketId) { | 127 if (socket_id_ != chrome_common_net::kNoSocketId) { |
127 all_bridges.Remove(socket_id_); | 128 all_bridges.Remove(socket_id_); |
128 socket_id_ = chrome_common_net::kNoSocketId; | 129 socket_id_ = chrome_common_net::kNoSocketId; |
129 } | 130 } |
130 if (delegate_) | 131 if (delegate_) |
131 delegate_->DidClose(handle_); | 132 delegate_->DidClose(handle_); |
132 delegate_ = NULL; | 133 delegate_ = NULL; |
133 Release(); | 134 Release(); |
134 } | 135 } |
135 | 136 |
| 137 void IPCWebSocketStreamHandleBridge::OnError(int error) { |
| 138 if (delegate_) |
| 139 delegate_->DidFail(handle_, error); |
| 140 } |
| 141 |
136 void IPCWebSocketStreamHandleBridge::DoConnect(const GURL& url) { | 142 void IPCWebSocketStreamHandleBridge::DoConnect(const GURL& url) { |
137 DCHECK(child_thread_); | 143 DCHECK(child_thread_); |
138 DCHECK_EQ(socket_id_, chrome_common_net::kNoSocketId); | 144 DCHECK_EQ(socket_id_, chrome_common_net::kNoSocketId); |
139 if (delegate_) | 145 if (delegate_) |
140 delegate_->WillOpenStream(handle_, url); | 146 delegate_->WillOpenStream(handle_, url); |
141 | 147 |
142 socket_id_ = all_bridges.Add(this); | 148 socket_id_ = all_bridges.Add(this); |
143 DCHECK_NE(socket_id_, chrome_common_net::kNoSocketId); | 149 DCHECK_NE(socket_id_, chrome_common_net::kNoSocketId); |
144 AddRef(); // Released in OnClosed(). | 150 AddRef(); // Released in OnClosed(). |
145 if (child_thread_->Send( | 151 if (child_thread_->Send( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 214 } |
209 | 215 |
210 void SocketStreamDispatcher::OnClosed(int socket_id) { | 216 void SocketStreamDispatcher::OnClosed(int socket_id) { |
211 IPCWebSocketStreamHandleBridge* bridge = | 217 IPCWebSocketStreamHandleBridge* bridge = |
212 IPCWebSocketStreamHandleBridge::FromSocketId(socket_id); | 218 IPCWebSocketStreamHandleBridge::FromSocketId(socket_id); |
213 if (bridge) | 219 if (bridge) |
214 bridge->OnClosed(); | 220 bridge->OnClosed(); |
215 else | 221 else |
216 DLOG(ERROR) << "No SocketStreamHandleBridge for socket_id=" << socket_id; | 222 DLOG(ERROR) << "No SocketStreamHandleBridge for socket_id=" << socket_id; |
217 } | 223 } |
OLD | NEW |