diff options
author | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-23 17:33:22 +0000 |
---|---|---|
committer | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-23 17:33:22 +0000 |
commit | 9291ed107d2031cea55f324431ffee8d7bae1416 (patch) | |
tree | 5c1d8e6d992aa324f099062b0f85e3945fdfe761 /chrome/plugin | |
parent | fefa8b29191ffd7730f7d3428697408bf979e6ee (diff) | |
download | chromium_src-9291ed107d2031cea55f324431ffee8d7bae1416.zip chromium_src-9291ed107d2031cea55f324431ffee8d7bae1416.tar.gz chromium_src-9291ed107d2031cea55f324431ffee8d7bae1416.tar.bz2 |
Revert 21355 because it might be causing all the new
crashes on reliability. It also seems to be causing
valgrind error.
Original change:
Switch the first thread in a child process to be the main thread, and make theIO thread be the second thread. The change is needed for plugins on mac.
Review URL: http://codereview.chromium.org/159274
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21398 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/plugin')
-rw-r--r-- | chrome/plugin/plugin_main.cc | 7 | ||||
-rw-r--r-- | chrome/plugin/plugin_thread.cc | 56 | ||||
-rw-r--r-- | chrome/plugin/plugin_thread.h | 8 |
3 files changed, 52 insertions, 19 deletions
diff --git a/chrome/plugin/plugin_main.cc b/chrome/plugin/plugin_main.cc index 63d295d..7361d64 100644 --- a/chrome/plugin/plugin_main.cc +++ b/chrome/plugin/plugin_main.cc @@ -29,8 +29,8 @@ // main() routine for running as the plugin process. int PluginMain(const MainFunctionParams& parameters) { - // The main thread of the plugin services UI. - MessageLoop main_message_loop(MessageLoop::TYPE_UI); + // The main thread of the plugin services IO. + MessageLoopForIO main_message_loop; std::wstring app_name = chrome::kBrowserAppName; PlatformThread::SetName(WideToASCII(app_name + L"_PluginMain").c_str()); @@ -80,8 +80,7 @@ int PluginMain(const MainFunctionParams& parameters) { } { - ChildProcess plugin_process; - plugin_process.set_main_thread(new PluginThread()); + ChildProcess plugin_process(new PluginThread()); #if defined(OS_WIN) if (!no_sandbox && target_services) target_services->LowerToken(); diff --git a/chrome/plugin/plugin_thread.cc b/chrome/plugin/plugin_thread.cc index ae90e1a..da5c68c 100644 --- a/chrome/plugin/plugin_thread.cc +++ b/chrome/plugin/plugin_thread.cc @@ -6,6 +6,11 @@ #include "build/build_config.h" +#if defined(OS_WIN) +#include <windows.h> +#include <objbase.h> +#endif + #include "base/command_line.h" #include "base/lazy_instance.h" #include "base/process_util.h" @@ -13,6 +18,7 @@ #include "chrome/common/child_process.h" #include "chrome/common/chrome_plugin_lib.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/notification_service.h" #include "chrome/common/plugin_messages.h" #include "chrome/common/render_messages.h" #include "chrome/plugin/chrome_plugin_host.h" @@ -26,10 +32,27 @@ static base::LazyInstance<base::ThreadLocalPointer<PluginThread> > lazy_tls( base::LINKER_INITIALIZED); PluginThread::PluginThread() - : preloaded_plugin_module_(NULL) { + : ChildThread(base::Thread::Options(MessageLoop::TYPE_UI, 0)), + preloaded_plugin_module_(NULL) { plugin_path_ = FilePath::FromWStringHack( CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kPluginPath)); +} + +PluginThread::~PluginThread() { +} + +PluginThread* PluginThread::current() { + return lazy_tls.Pointer()->Get(); +} + +void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { + IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) + IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) + IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage) + IPC_END_MESSAGE_MAP() +} +void PluginThread::Init() { lazy_tls.Pointer()->Set(this); #if defined(OS_LINUX) { @@ -52,8 +75,14 @@ PluginThread::PluginThread() } } #endif + ChildThread::Init(); PatchNPNFunctions(); +#if defined(OS_WIN) + CoInitialize(NULL); +#endif + + notification_service_.reset(new NotificationService); // Preload the library to avoid loading, unloading then reloading preloaded_plugin_module_ = base::LoadNativeLibrary(plugin_path_); @@ -71,7 +100,7 @@ PluginThread::PluginThread() message_loop()->set_exception_restoration(true); } -PluginThread::~PluginThread() { +void PluginThread::CleanUp() { if (preloaded_plugin_module_) { base::UnloadNativeLibrary(preloaded_plugin_module_); preloaded_plugin_module_ = NULL; @@ -79,29 +108,26 @@ PluginThread::~PluginThread() { PluginChannelBase::CleanupChannels(); NPAPI::PluginLib::UnloadAllPlugins(); ChromePluginLib::UnloadAllPlugins(); + notification_service_.reset(); +#if defined(OS_WIN) + CoUninitialize(); +#endif if (webkit_glue::ShouldForcefullyTerminatePluginProcess()) base::KillProcess(base::GetCurrentProcessHandle(), 0, /* wait= */ false); + // Call this last because it deletes the ResourceDispatcher, which is used + // in some of the above cleanup. + // See http://code.google.com/p/chromium/issues/detail?id=8980 + ChildThread::CleanUp(); lazy_tls.Pointer()->Set(NULL); } -PluginThread* PluginThread::current() { - return lazy_tls.Pointer()->Get(); -} - -void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { - IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) - IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) - IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage) - IPC_END_MESSAGE_MAP() -} - void PluginThread::OnCreateChannel( int process_id, bool off_the_record) { - scoped_refptr<PluginChannel> channel = PluginChannel::GetPluginChannel( - process_id, ChildProcess::current()->io_message_loop()); + scoped_refptr<PluginChannel> channel = + PluginChannel::GetPluginChannel(process_id, owner_loop()); IPC::ChannelHandle channel_handle; if (channel.get()) { channel_handle.name = channel->channel_name(); diff --git a/chrome/plugin/plugin_thread.h b/chrome/plugin/plugin_thread.h index 2e9803c..e9074aa 100644 --- a/chrome/plugin/plugin_thread.h +++ b/chrome/plugin/plugin_thread.h @@ -16,6 +16,8 @@ #include "base/file_descriptor_posix.h" #endif +class NotificationService; + // The PluginThread class represents a background thread where plugin instances // live. Communication occurs between WebPluginDelegateProxy in the renderer // process and WebPluginDelegateStub in this thread through IPC messages. @@ -30,12 +32,18 @@ class PluginThread : public ChildThread { private: virtual void OnControlMessageReceived(const IPC::Message& msg); + // Thread implementation: + virtual void Init(); + virtual void CleanUp(); + // Callback for when a channel has been created. void OnCreateChannel( int process_id, bool off_the_record); void OnPluginMessage(const std::vector<uint8> &data); + scoped_ptr<NotificationService> notification_service_; + // The plugin module which is preloaded in Init base::NativeLibrary preloaded_plugin_module_; |