diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-18 03:47:48 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-18 03:47:48 +0000 |
commit | 6dffde32e9bf00108ebe936b06f02fc80ed09fb4 (patch) | |
tree | d2da2ecf38102a7b7997bbf5a3542a588fbeb330 /chrome/browser | |
parent | 8c6add3b6648649eeadb60abdecbf6a1bec01860 (diff) | |
download | chromium_src-6dffde32e9bf00108ebe936b06f02fc80ed09fb4.zip chromium_src-6dffde32e9bf00108ebe936b06f02fc80ed09fb4.tar.gz chromium_src-6dffde32e9bf00108ebe936b06f02fc80ed09fb4.tar.bz2 |
Take out common functionality from PluginProcessHost and move it to ChildProcessHost.
Review URL: http://codereview.chromium.org/21443
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9935 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.cc | 8 | ||||
-rw-r--r-- | chrome/browser/memory_details.cc | 9 | ||||
-rw-r--r-- | chrome/browser/plugin_process_host.cc | 142 | ||||
-rw-r--r-- | chrome/browser/plugin_process_host.h | 31 | ||||
-rw-r--r-- | chrome/browser/plugin_service.cc | 6 | ||||
-rw-r--r-- | chrome/browser/renderer_host/browser_render_process_host.cc | 17 | ||||
-rw-r--r-- | chrome/browser/renderer_host/browser_render_process_host.h | 4 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.cc | 7 |
8 files changed, 36 insertions, 188 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 06b6281..9ac4ed5 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -24,7 +24,6 @@ #include "chrome/browser/tab_contents/site_instance.h" #include "chrome/browser/tab_contents/tab_contents_type.h" #include "chrome/browser/tab_contents/web_contents.h" -#include "chrome/common/child_process_info.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/l10n_util.h" @@ -70,6 +69,7 @@ #include "chrome/browser/views/download_tab_view.h" #include "chrome/browser/views/location_bar_view.h" #include "chrome/browser/window_sizer.h" +#include "chrome/common/child_process_host.h" #include "chrome/common/win_util.h" #include "chromium_strings.h" @@ -97,10 +97,8 @@ class ReduceChildProcessesWorkingSetTask : public Task { public: virtual void Run() { #if defined(OS_WIN) - for (ChildProcessInfo::Iterator iter; !iter.Done(); ++iter) { - DCHECK(iter->process().handle()); - iter->process().ReduceWorkingSet(); - } + for (ChildProcessHost::Iterator iter; !iter.Done(); ++iter) + iter->ReduceWorkingSet(); #endif } }; diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc index 2eb0135..7c81d6f 100644 --- a/chrome/browser/memory_details.cc +++ b/chrome/browser/memory_details.cc @@ -18,7 +18,7 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/web_contents.h" -#include "chrome/common/child_process_info.h" +#include "chrome/common/child_process_host.h" class RenderViewHostDelegate; @@ -73,12 +73,9 @@ void MemoryDetails::CollectChildInfoOnIOThread() { std::vector<ProcessMemoryInformation> child_info; // Collect the list of child processes. - for (ChildProcessInfo::Iterator iter; !iter.Done(); ++iter) { - if (!iter->process().handle()) - continue; - + for (ChildProcessHost::Iterator iter; !iter.Done(); ++iter) { ProcessMemoryInformation info; - info.pid = iter->process().pid(); + info.pid = iter->pid(); if (!info.pid) continue; diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc index f14524d..03a59ba 100644 --- a/chrome/browser/plugin_process_host.cc +++ b/chrome/browser/plugin_process_host.cc @@ -30,12 +30,8 @@ #include "chrome/common/chrome_plugin_lib.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/debug_flags.h" -#include "chrome/common/ipc_logging.h" #include "chrome/common/logging_chrome.h" -#include "chrome/common/notification_service.h" -#include "chrome/common/notification_type.h" #include "chrome/common/plugin_messages.h" -#include "chrome/common/process_watcher.h" #include "chrome/common/render_messages.h" #include "chrome/common/win_util.h" #include "net/base/cookie_monster.h" @@ -47,26 +43,6 @@ static const char kDefaultPluginFinderURL[] = "http://dl.google.com/chrome/plugins/plugins2.xml"; -// The NotificationTask is used to notify about plugin process connection/ -// disconnection. It is needed because the notifications in the -// NotificationService must happen in the main thread. -class PluginNotificationTask : public Task { - public: - PluginNotificationTask(NotificationType notification_type, - ChildProcessInfo* info) - : notification_type_(notification_type), info_(*info) { } - - virtual void Run() { - NotificationService::current()-> - Notify(notification_type_, NotificationService::AllSources(), - Details<ChildProcessInfo>(&info_)); - } - - private: - NotificationType notification_type_; - ChildProcessInfo info_; -}; - // The PluginDownloadUrlHelper is used to handle one download URL request // from the plugin. Each download request is handled by a new instance @@ -357,32 +333,26 @@ class DestroyWindowTask : public Task { }; -PluginProcessHost::PluginProcessHost() - : ChildProcessInfo(PLUGIN_PROCESS), - opening_channel_(false), +PluginProcessHost::PluginProcessHost(MessageLoop* main_message_loop) + : ChildProcessHost(PLUGIN_PROCESS, main_message_loop), ALLOW_THIS_IN_INITIALIZER_LIST(resolve_proxy_msg_helper_(this, NULL)) { } PluginProcessHost::~PluginProcessHost() { - if (process().handle()) { - watcher_.StopWatching(); - ProcessWatcher::EnsureProcessTerminated(process().handle()); - } + // Cancel all requests for plugin processes. + // TODO(mpcomplete): use a real process ID when http://b/issue?id=1210062 is + // fixed. + PluginService::GetInstance()->resource_dispatcher_host()-> + CancelRequestsForProcess(-1); } bool PluginProcessHost::Init(const WebPluginInfo& info, const std::string& activex_clsid, const std::wstring& locale) { - DCHECK(channel_.get() == NULL); - info_ = info; set_name(info_.name); - channel_id_ = GenerateRandomChannelID(this); - channel_.reset(new IPC::Channel(channel_id_, - IPC::Channel::MODE_SERVER, - this)); - if (!channel_->Connect()) + if (!CreateChannel()) return false; // build command line for plugin, we have to quote the plugin's path to deal @@ -450,8 +420,7 @@ bool PluginProcessHost::Init(const WebPluginInfo& info, cmd_line.AppendSwitchWithValue(switches::kProcessType, switches::kPluginProcess); - cmd_line.AppendSwitchWithValue(switches::kProcessChannelID, - channel_id_); + cmd_line.AppendSwitchWithValue(switches::kProcessChannelID, channel_id()); cmd_line.AppendSwitchWithValue(switches::kPluginPath, info.path.ToWStringHack()); @@ -494,7 +463,7 @@ bool PluginProcessHost::Init(const WebPluginInfo& info, ResumeThread(target.hThread); CloseHandle(target.hThread); - process().set_handle(target.hProcess); + SetHandle(target.hProcess); // Help the process a little. It can't start the debugger by itself if // the process is in a sandbox. @@ -505,11 +474,9 @@ bool PluginProcessHost::Init(const WebPluginInfo& info, HANDLE handle; if (!base::LaunchApp(cmd_line, false, false, &handle)) return false; - process().set_handle(handle); + SetHandle(handle); } - watcher_.StartWatching(process().handle(), this); - FilePath gears_path; if (PathService::Get(chrome::FILE_GEARS_PLUGIN, &gears_path)) { FilePath::StringType gears_path_lc = StringToLowerASCII(gears_path.value()); @@ -518,65 +485,14 @@ bool PluginProcessHost::Init(const WebPluginInfo& info, if (plugin_path_lc == gears_path_lc) { // Give Gears plugins "background" priority. See // http://b/issue?id=1280317. - process().SetProcessBackgrounded(true); + SetProcessBackgrounded(); } } - opening_channel_ = true; - return true; } -bool PluginProcessHost::Send(IPC::Message* msg) { - if (!channel_.get()) { - delete msg; - return false; - } - return channel_->Send(msg); -} - -// indicates the plugin process has exited -void PluginProcessHost::OnObjectSignaled(HANDLE object) { - DCHECK(process().handle()); - DCHECK_EQ(object, process().handle()); - - bool did_crash = base::DidProcessCrash(object); - - if (did_crash) { - // Report that this plugin crashed. - PluginService::GetInstance()->main_message_loop()->PostTask( - FROM_HERE, new PluginNotificationTask( - NotificationType::CHILD_PROCESS_CRASHED, this)); - } - // Notify in the main loop of the disconnection. - PluginService::GetInstance()->main_message_loop()->PostTask( - FROM_HERE, new PluginNotificationTask( - NotificationType::CHILD_PROCESS_HOST_DISCONNECTED, this)); - - // Cancel all requests for plugin processes. - // TODO(mpcomplete): use a real process ID when http://b/issue?id=1210062 is - // fixed. - PluginService::GetInstance()->resource_dispatcher_host()-> - CancelRequestsForProcess(-1); - - delete this; -} - - void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { -#ifdef IPC_MESSAGE_LOG_ENABLED - IPC::Logging* logger = IPC::Logging::current(); - if (msg.type() == IPC_LOGGING_ID) { - logger->OnReceivedLoggingMessage(msg); - return; - } -#endif - -#ifdef IPC_MESSAGE_LOG_ENABLED - if (logger->Enabled()) - logger->OnPreDispatchMessage(msg); -#endif - IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) IPC_MESSAGE_HANDLER(PluginProcessHostMsg_DownloadUrl, OnDownloadUrl) @@ -598,16 +514,9 @@ void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PluginProcessHostMsg_DestroyWindow, OnDestroyWindow) IPC_MESSAGE_UNHANDLED_ERROR() IPC_END_MESSAGE_MAP() - -#ifdef IPC_MESSAGE_LOG_ENABLED - if (logger->Enabled()) - logger->OnPostDispatchMessage(msg, channel_id_); -#endif } void PluginProcessHost::OnChannelConnected(int32 peer_pid) { - opening_channel_ = false; - for (size_t i = 0; i < pending_requests_.size(); ++i) { RequestPluginChannel(pending_requests_[i].renderer_message_filter_.get(), pending_requests_[i].mime_type, @@ -615,15 +524,9 @@ void PluginProcessHost::OnChannelConnected(int32 peer_pid) { } pending_requests_.clear(); - - // Notify in the main loop of the connection. - PluginService::GetInstance()->main_message_loop()->PostTask( - FROM_HERE, new PluginNotificationTask( - NotificationType::CHILD_PROCESS_HOST_CONNECTED, this)); } void PluginProcessHost::OnChannelError() { - opening_channel_ = false; for (size_t i = 0; i < pending_requests_.size(); ++i) { ReplyToRenderer(pending_requests_[i].renderer_message_filter_.get(), std::wstring(), @@ -638,24 +541,13 @@ void PluginProcessHost::OpenChannelToPlugin( ResourceMessageFilter* renderer_message_filter, const std::string& mime_type, IPC::Message* reply_msg) { - // Notify in the main loop of the instantiation. - PluginService::GetInstance()->main_message_loop()->PostTask( - FROM_HERE, new PluginNotificationTask( - NotificationType::CHILD_INSTANCE_CREATED, this)); - - if (opening_channel_) { + InstanceCreated(); + if (opening_channel()) { pending_requests_.push_back( ChannelRequest(renderer_message_filter, mime_type, reply_msg)); return; } - if (!channel_.get()) { - // There was an error opening the channel, tell the renderer. - ReplyToRenderer(renderer_message_filter, std::wstring(), FilePath(), - reply_msg); - return; - } - // We already have an open channel, send a request right away to plugin. RequestPluginChannel(renderer_message_filter, mime_type, reply_msg); } @@ -675,7 +567,7 @@ void PluginProcessHost::OnRequestResource( context = Profile::GetDefaultRequestContext(); PluginService::GetInstance()->resource_dispatcher_host()-> - BeginRequest(this, process().handle(), render_process_host_id, + BeginRequest(this, handle(), render_process_host_id, MSG_ROUTING_CONTROL, request_id, request, context, NULL); } @@ -709,7 +601,7 @@ void PluginProcessHost::OnSyncLoad( context = Profile::GetDefaultRequestContext(); PluginService::GetInstance()->resource_dispatcher_host()-> - BeginRequest(this, process().handle(), render_process_host_id, + BeginRequest(this, handle(), render_process_host_id, MSG_ROUTING_CONTROL, request_id, request, context, sync_result); } @@ -764,7 +656,7 @@ void PluginProcessHost::RequestPluginChannel( HANDLE renderer_handle = NULL; BOOL result = DuplicateHandle(GetCurrentProcess(), renderer_message_filter->renderer_handle(), - process().handle(), &renderer_handle, 0, FALSE, + handle(), &renderer_handle, 0, FALSE, DUPLICATE_SAME_ACCESS); DCHECK(result); diff --git a/chrome/browser/plugin_process_host.h b/chrome/browser/plugin_process_host.h index f9b79f4..78b4f9d 100644 --- a/chrome/browser/plugin_process_host.h +++ b/chrome/browser/plugin_process_host.h @@ -8,13 +8,11 @@ #include <vector> #include "base/basictypes.h" -#include "base/object_watcher.h" #include "base/scoped_ptr.h" #include "base/task.h" #include "chrome/browser/net/resolve_proxy_msg_helper.h" #include "chrome/browser/renderer_host/resource_message_filter.h" -#include "chrome/common/child_process_info.h" -#include "chrome/common/ipc_channel.h" +#include "chrome/common/child_process_host.h" #include "webkit/glue/webplugin.h" class ResourceDispatcherHost; @@ -30,13 +28,10 @@ class GURL; // starting the plugin process when a plugin is created that doesn't already // have a process. After that, most of the communication is directly between // the renderer and plugin processes. -class PluginProcessHost : public ChildProcessInfo, - public IPC::Channel::Listener, - public IPC::Message::Sender, - public base::ObjectWatcher::Delegate, +class PluginProcessHost : public ChildProcessHost, public ResolveProxyMsgHelper::Delegate { public: - PluginProcessHost(); + PluginProcessHost(MessageLoop* main_message_loop); ~PluginProcessHost(); // Initialize the new plugin process, returning true on success. This must @@ -47,13 +42,6 @@ class PluginProcessHost : public ChildProcessInfo, const std::string& activex_clsid, const std::wstring& locale); - // IPC::Message::Sender implementation: - virtual bool Send(IPC::Message* msg); - - // ObjectWatcher::Delegate implementation: - virtual void OnObjectSignaled(HANDLE object); - - // IPC::Channel::Listener implementation: virtual void OnMessageReceived(const IPC::Message& msg); virtual void OnChannelConnected(int32 peer_pid); virtual void OnChannelError(); @@ -136,19 +124,6 @@ class PluginProcessHost : public ChildProcessInfo, // the plugin process, but haven't heard back about yet. std::vector<ChannelRequest> sent_requests_; - // Used to watch the plugin process handle. - base::ObjectWatcher watcher_; - - // true while we're waiting the channel to be opened. In the meantime, - // plugin instance requests will be buffered. - bool opening_channel_; - - // The IPC::Channel. - scoped_ptr<IPC::Channel> channel_; - - // IPC Channel's id. - std::wstring channel_id_; - // Information about the plugin. WebPluginInfo info_; diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc index 87d2aeb..a0f7044 100644 --- a/chrome/browser/plugin_service.cc +++ b/chrome/browser/plugin_service.cc @@ -75,7 +75,7 @@ PluginProcessHost* PluginService::FindPluginProcess( return NULL; } - for (ChildProcessInfo::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); + for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); !iter.Done(); ++iter) { PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); if (plugin->info().path == plugin_path) @@ -102,7 +102,7 @@ PluginProcessHost* PluginService::FindOrStartPluginProcess( } // This plugin isn't loaded by any plugin process, so create a new process. - plugin_host = new PluginProcessHost(); + plugin_host = new PluginProcessHost(main_message_loop_); if (!plugin_host->Init(info, clsid, ui_locale_)) { DCHECK(false); // Init is not expected to fail delete plugin_host; @@ -170,7 +170,7 @@ void PluginService::Shutdown() { } void PluginService::OnShutdown() { - for (ChildProcessInfo::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); + for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); !iter.Done(); ++iter) { static_cast<PluginProcessHost*>(*iter)->Shutdown(); } diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 20bd867..eda2f1a 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -33,6 +33,7 @@ #include "chrome/browser/renderer_host/resource_message_filter.h" #include "chrome/browser/visitedlink_master.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/child_process_info.h" #include "chrome/common/debug_flags.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/notification_service.h" @@ -218,7 +219,8 @@ bool BrowserRenderProcessHost::Init() { const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); // setup IPC channel - const std::wstring channel_id = GenerateRandomChannelID(this); + const std::wstring channel_id = + ChildProcessInfo::GenerateRandomChannelID(this); channel_.reset( new IPC::SyncChannel(channel_id, IPC::Channel::MODE_SERVER, this, resource_message_filter, @@ -813,16 +815,3 @@ void BrowserRenderProcessHost::Observe(NotificationType type, } } } - -std::wstring GenerateRandomChannelID(void* instance) { - // Note: the string must start with the current process id, this is how - // child processes determine the pid of the parent. - // Build the channel ID. This is composed of a unique identifier for the - // parent browser process, an identifier for the renderer/plugin instance, - // and a random component. We use a random component so that a hacked child - // process can't cause denial of service by causing future named pipe creation - // to fail. - return StringPrintf(L"%d.%x.%d", - base::GetCurrentProcId(), instance, - base::RandInt(0, std::numeric_limits<int>::max())); -} diff --git a/chrome/browser/renderer_host/browser_render_process_host.h b/chrome/browser/renderer_host/browser_render_process_host.h index d089516..be7e225 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.h +++ b/chrome/browser/renderer_host/browser_render_process_host.h @@ -143,8 +143,4 @@ class BrowserRenderProcessHost : public RenderProcessHost, DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); }; -// Generates a unique channel name for a child renderer/plugin process. -// The "instance" pointer value is baked into the channel id. -std::wstring GenerateRandomChannelID(void* instance); - #endif // CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc index ec95cbe..59b83ec 100644 --- a/chrome/browser/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager_resource_providers.cc @@ -16,6 +16,7 @@ #include "chrome/browser/renderer_host/resource_message_filter.h" #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/tab_contents/web_contents.h" +#include "chrome/common/child_process_host.h" #include "chrome/common/notification_service.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/stl_util-inl.h" @@ -264,7 +265,7 @@ TaskManagerChildProcessResource::TaskManagerChildProcessResource( network_usage_support_(false) { // We cache the process id because it's not cheap to calculate, and it won't // be available when we get the plugin disconnected notification. - pid_ = child_proc.process().pid(); + pid_ = child_proc.pid(); if (!default_icon_) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); @@ -288,7 +289,7 @@ SkBitmap TaskManagerChildProcessResource::GetIcon() const { } HANDLE TaskManagerChildProcessResource::GetProcess() const { - return (const_cast<ChildProcessInfo&>(child_process_)).process().handle(); + return child_process_.handle(); } //////////////////////////////////////////////////////////////////////////////// @@ -427,7 +428,7 @@ void TaskManagerChildProcessResourceProvider::AddToTaskManager( // The ChildProcessInfo::Iterator has to be used from the IO thread. void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { - for (ChildProcessInfo::Iterator iter; !iter.Done(); ++iter) { + for (ChildProcessHost::Iterator iter; !iter.Done(); ++iter) { existing_child_process_info_.push_back(**iter); } // Now notify the UI thread that we have retrieved information about child |