diff options
author | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-07 06:13:39 +0000 |
---|---|---|
committer | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-07 06:13:39 +0000 |
commit | 7661f67398aa39e42346892bf33258db69ac9da7 (patch) | |
tree | af87943a3c633eb09c73f76735fdb783a97ddbe5 /chrome/renderer | |
parent | 703e4d66f618720ca07ce00ff3fbe68810a661c3 (diff) | |
download | chromium_src-7661f67398aa39e42346892bf33258db69ac9da7.zip chromium_src-7661f67398aa39e42346892bf33258db69ac9da7.tar.gz chromium_src-7661f67398aa39e42346892bf33258db69ac9da7.tar.bz2 |
WebSocket in Worker: render_thread->child_thread change.
SocketStream should be handled in ChildThread instead of RenderThread to be used in Worker process.
Move SocketStream in chrome/common to satisfy check_deps.
BUG=27618
TEST=none
Review URL: http://codereview.chromium.org/443015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/render_thread.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/render_thread.h | 6 | ||||
-rw-r--r-- | chrome/renderer/renderer_glue.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/socket_stream_dispatcher.cc | 214 | ||||
-rw-r--r-- | chrome/renderer/socket_stream_dispatcher.h | 38 |
5 files changed, 2 insertions, 264 deletions
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index d22f52a0..2a62005 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -53,7 +53,6 @@ #include "chrome/renderer/render_view_visitor.h" #include "chrome/renderer/renderer_webkitclient_impl.h" #include "chrome/renderer/renderer_web_database_observer.h" -#include "chrome/renderer/socket_stream_dispatcher.h" #include "chrome/renderer/spellchecker/spellcheck.h" #include "chrome/renderer/user_script_slave.h" #include "ipc/ipc_message.h" @@ -174,7 +173,6 @@ void RenderThread::Init() { dns_master_.reset(new RenderDnsMaster()); histogram_snapshots_.reset(new RendererHistogramSnapshots()); appcache_dispatcher_.reset(new AppCacheDispatcher(this)); - socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); devtools_agent_filter_ = new DevToolsAgentFilter(); AddFilter(devtools_agent_filter_.get()); db_message_filter_ = new DBMessageFilter(); @@ -319,8 +317,6 @@ void RenderThread::OnControlMessageReceived(const IPC::Message& msg) { // App cache messages are handled by a delegate. if (appcache_dispatcher_->OnMessageReceived(msg)) return; - if (socket_stream_dispatcher_->OnMessageReceived(msg)) - return; IPC_BEGIN_MESSAGE_MAP(RenderThread, msg) IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks) diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index ef880eb..f5e0d80 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -32,7 +32,6 @@ class RendererWebDatabaseObserver; class RendererWebKitClientImpl; class SpellCheck; class SkBitmap; -class SocketStreamDispatcher; class UserScriptSlave; class URLPattern; @@ -120,10 +119,6 @@ class RenderThread : public RenderThreadBase, return appcache_dispatcher_.get(); } - SocketStreamDispatcher* socket_stream_dispatcher() const { - return socket_stream_dispatcher_.get(); - } - SpellCheck* spellchecker() const { return spellchecker_.get(); } @@ -221,7 +216,6 @@ class RenderThread : public RenderThreadBase, scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_; scoped_ptr<RendererWebKitClientImpl> webkit_client_; scoped_ptr<WebKit::WebStorageEventDispatcher> dom_storage_event_dispatcher_; - scoped_ptr<SocketStreamDispatcher> socket_stream_dispatcher_; scoped_ptr<RendererWebDatabaseObserver> renderer_web_database_observer_; scoped_ptr<SpellCheck> spellchecker_; diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc index 558589c..012a249 100644 --- a/chrome/renderer/renderer_glue.cc +++ b/chrome/renderer/renderer_glue.cc @@ -19,12 +19,12 @@ #include "base/string_util.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" +#include "chrome/common/socket_stream_dispatcher.h" #include "chrome/common/url_constants.h" #include "chrome/plugin/npobject_util.h" #include "chrome/renderer/net/render_dns_master.h" #include "chrome/renderer/render_process.h" #include "chrome/renderer/render_thread.h" -#include "chrome/renderer/socket_stream_dispatcher.h" #include "googleurl/src/url_util.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" @@ -242,7 +242,7 @@ WebSocketStreamHandleBridge* WebSocketStreamHandleBridge::Create( WebKit::WebSocketStreamHandle* handle, WebSocketStreamHandleDelegate* delegate) { SocketStreamDispatcher* dispatcher = - RenderThread::current()->socket_stream_dispatcher(); + ChildThread::current()->socket_stream_dispatcher(); return dispatcher->CreateBridge(handle, delegate); } diff --git a/chrome/renderer/socket_stream_dispatcher.cc b/chrome/renderer/socket_stream_dispatcher.cc deleted file mode 100644 index aa9caec..0000000 --- a/chrome/renderer/socket_stream_dispatcher.cc +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/renderer/socket_stream_dispatcher.h" - -#include <vector> - -#include "base/id_map.h" -#include "base/ref_counted.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/net/socket_stream.h" -#include "chrome/renderer/render_thread.h" -#include "googleurl/src/gurl.h" -#include "webkit/glue/websocketstreamhandle_bridge.h" -#include "webkit/glue/websocketstreamhandle_delegate.h" - -// IPCWebSocketStreamHandleBridge is owned by each SocketStreamHandle. -// It communicates with the main browser process via SocketStreamDispatcher. -class IPCWebSocketStreamHandleBridge - : public webkit_glue::WebSocketStreamHandleBridge { - public: - IPCWebSocketStreamHandleBridge( - IPC::Message::Sender* sender, - WebKit::WebSocketStreamHandle* handle, - webkit_glue::WebSocketStreamHandleDelegate* delegate) - : socket_id_(chrome_common_net::kNoSocketId), - sender_(sender), - handle_(handle), - delegate_(delegate) {} - - // Returns the handle having given id or NULL if there is no such handle. - static IPCWebSocketStreamHandleBridge* FromSocketId(int id); - - // webkit_glue::WebSocketStreamHandleBridge methods. - virtual void Connect(const GURL& url); - virtual bool Send(const std::vector<char>& data); - virtual void Close(); - - // Called by SocketStreamDispatcher. - void OnConnected(int max_amount_send_allowed); - void OnSentData(int amount_sent); - void OnReceivedData(const std::vector<char>& data); - void OnClosed(); - - private: - virtual ~IPCWebSocketStreamHandleBridge(); - - void DoConnect(const GURL& url); - int socket_id_; - - IPC::Message::Sender* sender_; - WebKit::WebSocketStreamHandle* handle_; - webkit_glue::WebSocketStreamHandleDelegate* delegate_; - - static IDMap<IPCWebSocketStreamHandleBridge> all_bridges; -}; - -IDMap<IPCWebSocketStreamHandleBridge> -IPCWebSocketStreamHandleBridge::all_bridges; - -/* static */ -IPCWebSocketStreamHandleBridge* IPCWebSocketStreamHandleBridge::FromSocketId( - int id) { - return all_bridges.Lookup(id); -} - -IPCWebSocketStreamHandleBridge::~IPCWebSocketStreamHandleBridge() { - DLOG(INFO) << "IPCWebSocketStreamHandleBridge destructor socket_id=" - << socket_id_; - if (socket_id_ != chrome_common_net::kNoSocketId) { - sender_->Send(new ViewHostMsg_Close(socket_id_)); - socket_id_ = chrome_common_net::kNoSocketId; - } -} - -void IPCWebSocketStreamHandleBridge::Connect(const GURL& url) { - DCHECK(sender_); - DLOG(INFO) << "Connect url=" << url; - MessageLoop::current()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &IPCWebSocketStreamHandleBridge::DoConnect, - url)); -} - -bool IPCWebSocketStreamHandleBridge::Send( - const std::vector<char>& data) { - DLOG(INFO) << "Send data.size=" << data.size(); - if (sender_->Send(new ViewHostMsg_SocketStream_SendData(socket_id_, data))) { - if (delegate_) - delegate_->WillSendData(handle_, &data[0], data.size()); - return true; - } - return false; -} - -void IPCWebSocketStreamHandleBridge::Close() { - DLOG(INFO) << "Close socket_id" << socket_id_; - sender_->Send(new ViewHostMsg_SocketStream_Close(socket_id_)); -} - -void IPCWebSocketStreamHandleBridge::OnConnected(int max_pending_send_allowed) { - DLOG(INFO) << "IPCWebSocketStreamHandleBridge::OnConnected socket_id=" - << socket_id_; - if (delegate_) - delegate_->DidOpenStream(handle_, max_pending_send_allowed); -} - -void IPCWebSocketStreamHandleBridge::OnSentData(int amount_sent) { - if (delegate_) - delegate_->DidSendData(handle_, amount_sent); -} - -void IPCWebSocketStreamHandleBridge::OnReceivedData( - const std::vector<char>& data) { - if (delegate_) - delegate_->DidReceiveData(handle_, &data[0], data.size()); -} - -void IPCWebSocketStreamHandleBridge::OnClosed() { - DLOG(INFO) << "IPCWebSocketStreamHandleBridge::OnClosed"; - if (socket_id_ != chrome_common_net::kNoSocketId) { - all_bridges.Remove(socket_id_); - socket_id_ = chrome_common_net::kNoSocketId; - } - if (delegate_) { - delegate_->DidClose(handle_); - } - delegate_ = NULL; - Release(); -} - -void IPCWebSocketStreamHandleBridge::DoConnect(const GURL& url) { - DCHECK(sender_); - DCHECK_EQ(socket_id_, chrome_common_net::kNoSocketId); - if (delegate_) - delegate_->WillOpenStream(handle_, url); - - socket_id_ = all_bridges.Add(this); - DCHECK_NE(socket_id_, chrome_common_net::kNoSocketId); - if (sender_->Send(new ViewHostMsg_SocketStream_Connect(url, socket_id_))) { - DLOG(INFO) << "Connect socket_id=" << socket_id_; - AddRef(); // Released in OnClosed(). - // TODO(ukai): timeout to OnConnected. - } else { - LOG(ERROR) << "IPC SocketStream_Connect failed."; - OnClosed(); - } -} - -SocketStreamDispatcher::SocketStreamDispatcher() { -} - -/* static */ -webkit_glue::WebSocketStreamHandleBridge* -SocketStreamDispatcher::CreateBridge( - WebKit::WebSocketStreamHandle* handle, - webkit_glue::WebSocketStreamHandleDelegate* delegate) { - return new IPCWebSocketStreamHandleBridge( - ChildThread::current(), handle, delegate); -} - -bool SocketStreamDispatcher::OnMessageReceived(const IPC::Message& msg) { - DLOG(INFO) << "SocketStreamDispatcher::OnMessageReceived"; - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(SocketStreamDispatcher, msg) - IPC_MESSAGE_HANDLER(ViewMsg_SocketStream_Connected, OnConnected) - IPC_MESSAGE_HANDLER(ViewMsg_SocketStream_SentData, OnSentData) - IPC_MESSAGE_HANDLER(ViewMsg_SocketStream_ReceivedData, OnReceivedData) - IPC_MESSAGE_HANDLER(ViewMsg_SocketStream_Closed, OnClosed) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void SocketStreamDispatcher::OnConnected(int socket_id, - int max_pending_send_allowed) { - DLOG(INFO) << "SocketStreamDispatcher::OnConnected socket_id=" << socket_id - << " max_pending_send_allowed=" << max_pending_send_allowed; - IPCWebSocketStreamHandleBridge* bridge = - IPCWebSocketStreamHandleBridge::FromSocketId(socket_id); - if (bridge) - bridge->OnConnected(max_pending_send_allowed); - else - DLOG(ERROR) << "No SocketStreamHandleBridge for socket_id=" << socket_id; -} - -void SocketStreamDispatcher::OnSentData(int socket_id, int amount_sent) { - IPCWebSocketStreamHandleBridge* bridge = - IPCWebSocketStreamHandleBridge::FromSocketId(socket_id); - if (bridge) - bridge->OnSentData(amount_sent); - else - DLOG(ERROR) << "No SocketStreamHandleBridge for socket_id=" << socket_id; -} - -void SocketStreamDispatcher::OnReceivedData( - int socket_id, const std::vector<char>& data) { - IPCWebSocketStreamHandleBridge* bridge = - IPCWebSocketStreamHandleBridge::FromSocketId(socket_id); - if (bridge) - bridge->OnReceivedData(data); - else - DLOG(ERROR) << "No SocketStreamHandleBridge for socket_id=" << socket_id; -} - -void SocketStreamDispatcher::OnClosed(int socket_id) { - IPCWebSocketStreamHandleBridge* bridge = - IPCWebSocketStreamHandleBridge::FromSocketId(socket_id); - if (bridge) - bridge->OnClosed(); - else - DLOG(ERROR) << "No SocketStreamHandleBridge for socket_id=" << socket_id; -} diff --git a/chrome/renderer/socket_stream_dispatcher.h b/chrome/renderer/socket_stream_dispatcher.h deleted file mode 100644 index 5399030..0000000 --- a/chrome/renderer/socket_stream_dispatcher.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_RENDERER_SOCKET_STREAM_DISPATCHER_H_ -#define CHROME_RENDERER_SOCKET_STREAM_DISPATCHER_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "ipc/ipc_channel.h" -#include "ipc/ipc_message.h" -#include "webkit/glue/websocketstreamhandle_bridge.h" - -// Dispatches socket stream related messages sent to a child process from the -// main browser process. There is one instance per child process. Messages -// are dispatched on the main child thread. The RenderThread class -// creates an instance of SocketStreamDispatcher and delegates calls to it. -class SocketStreamDispatcher { - public: - SocketStreamDispatcher(); - ~SocketStreamDispatcher() {} - - static webkit_glue::WebSocketStreamHandleBridge* CreateBridge( - WebKit::WebSocketStreamHandle* handle, - webkit_glue::WebSocketStreamHandleDelegate* delegate); - bool OnMessageReceived(const IPC::Message& msg); - - private: - void OnConnected(int socket_id, int max_amount_send_allowed); - void OnSentData(int socket_id, int amount_sent); - void OnReceivedData(int socket_id, const std::vector<char>& data); - void OnClosed(int socket_id); - - DISALLOW_COPY_AND_ASSIGN(SocketStreamDispatcher); -}; - -#endif // CHROME_RENDERER_SOCKET_STREAM_DISPATCHER_H_ |