| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/id_map.h" | 10 #include "base/id_map.h" |
| 10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 13 #include "base/task.h" | |
| 14 #include "content/common/child_thread.h" | 14 #include "content/common/child_thread.h" |
| 15 #include "content/common/socket_stream.h" | 15 #include "content/common/socket_stream.h" |
| 16 #include "content/common/socket_stream_messages.h" | 16 #include "content/common/socket_stream_messages.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "webkit/glue/websocketstreamhandle_bridge.h" | 18 #include "webkit/glue/websocketstreamhandle_bridge.h" |
| 19 #include "webkit/glue/websocketstreamhandle_delegate.h" | 19 #include "webkit/glue/websocketstreamhandle_delegate.h" |
| 20 | 20 |
| 21 // IPCWebSocketStreamHandleBridge is owned by each SocketStreamHandle. | 21 // IPCWebSocketStreamHandleBridge is owned by each SocketStreamHandle. |
| 22 // It communicates with the main browser process via SocketStreamDispatcher. | 22 // It communicates with the main browser process via SocketStreamDispatcher. |
| 23 class IPCWebSocketStreamHandleBridge | 23 class IPCWebSocketStreamHandleBridge |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 child_thread_->Send(new SocketStreamHostMsg_Close(socket_id_)); | 82 child_thread_->Send(new SocketStreamHostMsg_Close(socket_id_)); |
| 83 socket_id_ = content_common::kNoSocketId; | 83 socket_id_ = content_common::kNoSocketId; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 void IPCWebSocketStreamHandleBridge::Connect(const GURL& url) { | 87 void IPCWebSocketStreamHandleBridge::Connect(const GURL& url) { |
| 88 DCHECK(child_thread_); | 88 DCHECK(child_thread_); |
| 89 DVLOG(1) << "Connect url=" << url; | 89 DVLOG(1) << "Connect url=" << url; |
| 90 child_thread_->message_loop()->PostTask( | 90 child_thread_->message_loop()->PostTask( |
| 91 FROM_HERE, | 91 FROM_HERE, |
| 92 NewRunnableMethod(this, &IPCWebSocketStreamHandleBridge::DoConnect, | 92 base::Bind(&IPCWebSocketStreamHandleBridge::DoConnect, this, url)); |
| 93 url)); | |
| 94 } | 93 } |
| 95 | 94 |
| 96 bool IPCWebSocketStreamHandleBridge::Send( | 95 bool IPCWebSocketStreamHandleBridge::Send( |
| 97 const std::vector<char>& data) { | 96 const std::vector<char>& data) { |
| 98 DVLOG(1) << "Send data.size=" << data.size(); | 97 DVLOG(1) << "Send data.size=" << data.size(); |
| 99 if (child_thread_->Send( | 98 if (child_thread_->Send( |
| 100 new SocketStreamHostMsg_SendData(socket_id_, data))) { | 99 new SocketStreamHostMsg_SendData(socket_id_, data))) { |
| 101 if (delegate_) | 100 if (delegate_) |
| 102 delegate_->WillSendData(handle_, &data[0], data.size()); | 101 delegate_->WillSendData(handle_, &data[0], data.size()); |
| 103 return true; | 102 return true; |
| 104 } | 103 } |
| 105 return false; | 104 return false; |
| 106 } | 105 } |
| 107 | 106 |
| 108 void IPCWebSocketStreamHandleBridge::Close() { | 107 void IPCWebSocketStreamHandleBridge::Close() { |
| 109 DVLOG(1) << "Close socket_id" << socket_id_; | 108 DVLOG(1) << "Close socket_id" << socket_id_; |
| 110 AddRef(); // Released in DoClose(). | 109 AddRef(); // Released in DoClose(). |
| 111 child_thread_->message_loop()->PostTask( | 110 child_thread_->message_loop()->PostTask( |
| 112 FROM_HERE, | 111 FROM_HERE, |
| 113 NewRunnableMethod(this, &IPCWebSocketStreamHandleBridge::DoClose)); | 112 base::Bind(&IPCWebSocketStreamHandleBridge::DoClose, this)); |
| 114 } | 113 } |
| 115 | 114 |
| 116 void IPCWebSocketStreamHandleBridge::OnConnected(int max_pending_send_allowed) { | 115 void IPCWebSocketStreamHandleBridge::OnConnected(int max_pending_send_allowed) { |
| 117 DVLOG(1) << "IPCWebSocketStreamHandleBridge::OnConnected socket_id=" | 116 DVLOG(1) << "IPCWebSocketStreamHandleBridge::OnConnected socket_id=" |
| 118 << socket_id_; | 117 << socket_id_; |
| 119 if (delegate_) | 118 if (delegate_) |
| 120 delegate_->DidOpenStream(handle_, max_pending_send_allowed); | 119 delegate_->DidOpenStream(handle_, max_pending_send_allowed); |
| 121 } | 120 } |
| 122 | 121 |
| 123 void IPCWebSocketStreamHandleBridge::OnSentData(int amount_sent) { | 122 void IPCWebSocketStreamHandleBridge::OnSentData(int amount_sent) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 221 } |
| 223 | 222 |
| 224 void SocketStreamDispatcher::OnClosed(int socket_id) { | 223 void SocketStreamDispatcher::OnClosed(int socket_id) { |
| 225 IPCWebSocketStreamHandleBridge* bridge = | 224 IPCWebSocketStreamHandleBridge* bridge = |
| 226 IPCWebSocketStreamHandleBridge::FromSocketId(socket_id); | 225 IPCWebSocketStreamHandleBridge::FromSocketId(socket_id); |
| 227 if (bridge) | 226 if (bridge) |
| 228 bridge->OnClosed(); | 227 bridge->OnClosed(); |
| 229 else | 228 else |
| 230 DLOG(ERROR) << "No SocketStreamHandleBridge for socket_id=" << socket_id; | 229 DLOG(ERROR) << "No SocketStreamHandleBridge for socket_id=" << socket_id; |
| 231 } | 230 } |
| OLD | NEW |