summaryrefslogtreecommitdiffstats
path: root/chrome/browser/plugin_process_host.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 03:47:48 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 03:47:48 +0000
commit6dffde32e9bf00108ebe936b06f02fc80ed09fb4 (patch)
treed2da2ecf38102a7b7997bbf5a3542a588fbeb330 /chrome/browser/plugin_process_host.cc
parent8c6add3b6648649eeadb60abdecbf6a1bec01860 (diff)
downloadchromium_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/plugin_process_host.cc')
-rw-r--r--chrome/browser/plugin_process_host.cc142
1 files changed, 17 insertions, 125 deletions
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);