diff options
Diffstat (limited to 'chrome')
31 files changed, 116 insertions, 335 deletions
diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc index 40e470f..23aa42d 100644 --- a/chrome/browser/browser_shutdown.cc +++ b/chrome/browser/browser_shutdown.cc @@ -16,7 +16,6 @@ #include "chrome/browser/first_run.h" #include "chrome/browser/jankometer.h" #include "chrome/browser/metrics/metrics_service.h" -#include "chrome/browser/plugin_service.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host.h" @@ -106,11 +105,6 @@ void Shutdown() { // Notifies we are going away. g_browser_process->shutdown_event()->Signal(); - PluginService* plugin_service = PluginService::GetInstance(); - if (plugin_service) { - plugin_service->Shutdown(); - } - PrefService* prefs = g_browser_process->local_state(); chrome_browser_net::SaveHostNamesForNextStartup(prefs); diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc index e7a7f30..5031a35 100644 --- a/chrome/browser/plugin_process_host.cc +++ b/chrome/browser/plugin_process_host.cc @@ -505,8 +505,6 @@ void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PluginProcessHostMsg_DownloadUrl, OnDownloadUrl) IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetPluginFinderUrl, OnGetPluginFinderUrl) - IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ShutdownRequest, - OnPluginShutdownRequest) IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginMessage, OnPluginMessage) IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetCookies, OnGetCookies) IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_ResolveProxy, @@ -657,21 +655,6 @@ void PluginProcessHost::OnGetPluginFinderUrl(std::string* plugin_finder_url) { *plugin_finder_url = kDefaultPluginFinderURL; } -void PluginProcessHost::OnPluginShutdownRequest() { -#if defined(OS_WIN) - DCHECK(MessageLoop::current() == - ChromeThread::GetMessageLoop(ChromeThread::IO)); - - // If we have pending channel open requests from the renderers, then - // refuse the shutdown request from the plugin process. - bool ok_to_shutdown = sent_requests_.empty(); - Send(new PluginProcessMsg_ShutdownResponse(ok_to_shutdown)); -#else - // TODO(port): Port plugin_messages_internal.h. - NOTIMPLEMENTED(); -#endif -} - void PluginProcessHost::OnPluginMessage( const std::vector<uint8>& data) { DCHECK(MessageLoop::current() == @@ -684,12 +667,3 @@ void PluginProcessHost::OnPluginMessage( chrome_plugin->functions().on_message(data_ptr, data_len); } } - -void PluginProcessHost::Shutdown() { -#if defined(OS_WIN) - Send(new PluginProcessMsg_BrowserShutdown); -#else - // TODO(port): Port plugin_messages_internal.h. - NOTIMPLEMENTED(); -#endif -} diff --git a/chrome/browser/plugin_process_host.h b/chrome/browser/plugin_process_host.h index bc15ca2..71b7c77 100644 --- a/chrome/browser/plugin_process_host.h +++ b/chrome/browser/plugin_process_host.h @@ -75,9 +75,6 @@ class PluginProcessHost : public ChildProcessHost, void OnModalDialogResponse(const std::string& json_retval, IPC::Message* sync_result); - // Shuts down the current plugin process instance. - void Shutdown(); - const WebPluginInfo& info() const { return info_; } #if defined(OS_WIN) @@ -106,7 +103,6 @@ class PluginProcessHost : public ChildProcessHost, void OnGetCookies(uint32 request_context, const GURL& url, std::string* cookies); void OnResolveProxy(const GURL& url, IPC::Message* reply_msg); - void OnPluginShutdownRequest(); void OnPluginMessage(const std::vector<uint8>& data); #if defined(OS_WIN) @@ -114,6 +110,8 @@ class PluginProcessHost : public ChildProcessHost, void OnDestroyWindow(HWND window); #endif + virtual bool CanShutdown() { return sent_requests_.empty(); } + struct ChannelRequest { ChannelRequest(ResourceMessageFilter* renderer_message_filter, const std::string& m, IPC::Message* r) : diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc index 26f791b..d46a1d5 100644 --- a/chrome/browser/plugin_service.cc +++ b/chrome/browser/plugin_service.cc @@ -27,8 +27,7 @@ PluginService* PluginService::GetInstance() { PluginService::PluginService() : main_message_loop_(MessageLoop::current()), resource_dispatcher_host_(NULL), - ui_locale_(g_browser_process->GetApplicationLocale()), - plugin_shutdown_handler_(new ShutdownHandler) { + ui_locale_(g_browser_process->GetApplicationLocale()) { // Have the NPAPI plugin list search for Chrome plugins as well. ChromePluginLib::RegisterPluginsWithNPAPI(); // Load the one specified on the command line as well. @@ -172,27 +171,3 @@ bool PluginService::HavePluginFor(const std::string& mime_type, allow_wildcard, &info, NULL); } - -void PluginService::Shutdown() { - plugin_shutdown_handler_->InitiateShutdown(); -} - -void PluginService::OnShutdown() { - for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); - !iter.Done(); ++iter) { - static_cast<PluginProcessHost*>(*iter)->Shutdown(); - } -} - -void PluginService::ShutdownHandler::InitiateShutdown() { - g_browser_process->io_thread()->message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &ShutdownHandler::OnShutdown)); -} - -void PluginService::ShutdownHandler::OnShutdown() { - PluginService* plugin_service = PluginService::GetInstance(); - if (plugin_service) { - plugin_service->OnShutdown(); - } -} diff --git a/chrome/browser/plugin_service.h b/chrome/browser/plugin_service.h index d4f9368..d193cda 100644 --- a/chrome/browser/plugin_service.h +++ b/chrome/browser/plugin_service.h @@ -101,10 +101,6 @@ class PluginService { return resource_dispatcher_host_; } - // Initiates shutdown on all running PluginProcessHost instances. - // Can be invoked on the main thread. - void Shutdown(); - private: friend struct DefaultSingletonTraits<PluginService>; @@ -113,9 +109,6 @@ class PluginService { PluginService(); ~PluginService(); - // Shutdown handler which executes in the context of the IO thread. - void OnShutdown(); - // mapping between plugin path and PluginProcessHost typedef base::hash_map<FilePath, PluginProcessHost*> PluginMap; PluginMap plugin_hosts_; @@ -136,26 +129,6 @@ class PluginService { // webkit_glue since this class is called on the main and IO thread. Lock lock_; - // Handles plugin process shutdown. - class ShutdownHandler : public base::RefCountedThreadSafe<ShutdownHandler> { - public: - ShutdownHandler() {} - ~ShutdownHandler() {} - - // Initiates plugin process shutdown. Ensures that the actual shutdown - // happens on the io thread. - void InitiateShutdown(); - - private: - // Shutdown handler which runs on the io thread. - void OnShutdown(); - - DISALLOW_COPY_AND_ASSIGN(ShutdownHandler); - }; - - friend class ShutdownHandler; - scoped_refptr<ShutdownHandler> plugin_shutdown_handler_; - DISALLOW_COPY_AND_ASSIGN(PluginService); }; diff --git a/chrome/browser/worker_host/worker_process_host.h b/chrome/browser/worker_host/worker_process_host.h index 0a885ea..cf8072c 100644 --- a/chrome/browser/worker_host/worker_process_host.h +++ b/chrome/browser/worker_host/worker_process_host.h @@ -44,6 +44,8 @@ class WorkerProcessHost : public ChildProcessHost { // Called when a message arrives from the worker process. void OnMessageReceived(const IPC::Message& message); + virtual bool CanShutdown() { return instances_.empty(); } + // Updates the title shown in the task manager. void UpdateTitle(); diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index f4c431e..3f1b847 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -2702,8 +2702,6 @@ 'plugin/plugin_channel_base.cc', 'plugin/plugin_channel_base.h', 'plugin/plugin_main.cc', - 'plugin/plugin_process.cc', - 'plugin/plugin_process.h', 'plugin/plugin_thread.cc', 'plugin/plugin_thread.h', 'plugin/webplugin_delegate_stub.cc', @@ -2740,8 +2738,6 @@ 'worker/webworkerclient_proxy.cc', 'worker/webworkerclient_proxy.h', 'worker/worker_main.cc', - 'worker/worker_process.cc', - 'worker/worker_process.h', 'worker/worker_thread.cc', 'worker/worker_thread.h', 'worker/worker_webkitclient_impl.cc', diff --git a/chrome/common/child_process.cc b/chrome/common/child_process.cc index 27b55b7..55f5bb0 100644 --- a/chrome/common/child_process.cc +++ b/chrome/common/child_process.cc @@ -35,32 +35,22 @@ ChildProcess::~ChildProcess() { child_process_ = NULL; } -// Called on any thread void ChildProcess::AddRefProcess() { - base::AtomicRefCountInc(&ref_count_); + DCHECK(MessageLoop::current() == child_thread_->message_loop()); + ref_count_++; } -// Called on any thread void ChildProcess::ReleaseProcess() { - DCHECK(!base::AtomicRefCountIsZero(&ref_count_)); + DCHECK(MessageLoop::current() == child_thread_->message_loop()); + DCHECK(ref_count_); DCHECK(child_process_); - if (!base::AtomicRefCountDec(&ref_count_)) - child_process_->OnFinalRelease(); + if (--ref_count_) + return; + + child_thread_->OnProcessFinalRelease(); } base::WaitableEvent* ChildProcess::GetShutDownEvent() { DCHECK(child_process_); return &child_process_->shutdown_event_; } - -// Called on any thread -bool ChildProcess::ProcessRefCountIsZero() { - return base::AtomicRefCountIsZero(&ref_count_); -} - -void ChildProcess::OnFinalRelease() { - if (child_thread_.get()) { - child_thread_->owner_loop()->PostTask( - FROM_HERE, new MessageLoop::QuitTask()); - } -} diff --git a/chrome/common/child_process.h b/chrome/common/child_process.h index 5844b5b..23bfad8 100644 --- a/chrome/common/child_process.h +++ b/chrome/common/child_process.h @@ -7,7 +7,6 @@ #include <string> #include <vector> -#include "base/atomic_ref_count.h" #include "base/basictypes.h" #include "base/message_loop.h" #include "base/scoped_ptr.h" @@ -40,34 +39,21 @@ class ChildProcess { base::WaitableEvent* GetShutDownEvent(); // These are used for ref-counting the child process. The process shuts - // itself down when the ref count reaches 0. These functions may be called - // on any thread. + // itself down when the ref count reaches 0. // For example, in the renderer process, generally each tab managed by this // process will hold a reference to the process, and release when closed. void AddRefProcess(); void ReleaseProcess(); - protected: - friend class ChildThread; - // Getter for the one ChildProcess object for this process. static ChildProcess* current() { return child_process_; } - protected: - bool ProcessRefCountIsZero(); - - // Derived classes can override this to alter the behavior when the ref count - // reaches 0. The default implementation calls Quit on the main message loop - // which causes the process to shutdown. Note, this can be called on any - // thread. (See ReleaseProcess) - virtual void OnFinalRelease(); - private: // NOTE: make sure that child_thread_ is listed before shutdown_event_, since // it depends on it (indirectly through IPC::SyncChannel). scoped_ptr<ChildThread> child_thread_; - base::AtomicRefCount ref_count_; + int ref_count_; // An event that will be signalled when we shutdown. base::WaitableEvent shutdown_event_; diff --git a/chrome/common/child_process_host.cc b/chrome/common/child_process_host.cc index 4269678..6618554 100644 --- a/chrome/common/child_process_host.cc +++ b/chrome/common/child_process_host.cc @@ -17,7 +17,12 @@ #include "chrome/common/process_watcher.h" #include "chrome/common/result_codes.h" -typedef std::list<ChildProcessInfo*> ChildProcessList; +#if defined(OS_WIN) +#include "chrome/common/plugin_messages.h" +#endif + +namespace { +typedef std::list<ChildProcessHost*> ChildProcessList; // The NotificationTask is used to notify about plugin process connection/ // disconnection. It is needed because the notifications in the @@ -39,6 +44,9 @@ class ChildNotificationTask : public Task { ChildProcessInfo info_; }; +} // namespace + + ChildProcessHost::ChildProcessHost( ProcessType type, ResourceDispatcherHost* resource_dispatcher_host) @@ -143,10 +151,22 @@ void ChildProcessHost::ListenerHook::OnMessageReceived( bool msg_is_ok = true; bool handled = host_->resource_dispatcher_host_->OnMessageReceived( msg, host_, &msg_is_ok); - if (!handled) - host_->OnMessageReceived(msg); - if (!msg_is_ok) + if (!handled) { +#if defined(OS_WIN) + if (msg.type() == PluginProcessHostMsg_ShutdownRequest::ID) { + // Must remove the process from the list now, in case it gets used for a + // new instance before our watcher tells us that the process terminated. + Singleton<ChildProcessList>::get()->remove(host_); + if (host_->CanShutdown()) + host_->Send(new PluginProcessMsg_Shutdown()); +#endif + } else { + host_->OnMessageReceived(msg); + } + } + + if (!msg_is_ok) base::KillProcess(host_->handle(), ResultCodes::KILLED_BAD_MESSAGE, false); #ifdef IPC_MESSAGE_LOG_ENABLED @@ -158,6 +178,7 @@ void ChildProcessHost::ListenerHook::OnMessageReceived( void ChildProcessHost::ListenerHook::OnChannelConnected(int32 peer_pid) { host_->opening_channel_ = false; host_->OnChannelConnected(peer_pid); + host_->Send(new PluginProcessMsg_AskBeforeShutdown()); // Notify in the main loop of the connection. host_->Notify(NotificationType::CHILD_PROCESS_HOST_CONNECTED); @@ -186,7 +207,7 @@ ChildProcessHost::Iterator::Iterator(ProcessType type) ++(*this); } -ChildProcessInfo* ChildProcessHost::Iterator::operator++() { +ChildProcessHost* ChildProcessHost::Iterator::operator++() { do { ++iterator_; if (Done()) diff --git a/chrome/common/child_process_host.h b/chrome/common/child_process_host.h index cef940c..d4d2dd9 100644 --- a/chrome/common/child_process_host.h +++ b/chrome/common/child_process_host.h @@ -38,21 +38,24 @@ class ChildProcessHost : public ResourceDispatcherHost::Receiver, public: Iterator(); Iterator(ProcessType type); - ChildProcessInfo* operator->() { return *iterator_; } - ChildProcessInfo* operator*() { return *iterator_; } - ChildProcessInfo* operator++(); + ChildProcessHost* operator->() { return *iterator_; } + ChildProcessHost* operator*() { return *iterator_; } + ChildProcessHost* operator++(); bool Done(); private: bool all_; ProcessType type_; - std::list<ChildProcessInfo*>::iterator iterator_; + std::list<ChildProcessHost*>::iterator iterator_; }; protected: ChildProcessHost(ProcessType type, ResourceDispatcherHost* resource_dispatcher_host); + // Derived classes return true if it's ok to shut down the child process. + virtual bool CanShutdown() = 0; + // Creates the IPC channel. Returns true iff it succeeded. bool CreateChannel(); diff --git a/chrome/common/child_thread.cc b/chrome/common/child_thread.cc index 237e53c..22c82c0 100644 --- a/chrome/common/child_thread.cc +++ b/chrome/common/child_thread.cc @@ -11,13 +11,18 @@ #include "chrome/common/ipc_logging.h" #include "webkit/glue/webkit_glue.h" +#if defined(OS_WIN) +#include "chrome/common/plugin_messages.h" +#endif + // V8 needs a 1MB stack size. const size_t ChildThread::kV8StackSize = 1024 * 1024; ChildThread::ChildThread(Thread::Options options) : Thread("Chrome_ChildThread"), owner_loop_(MessageLoop::current()), - options_(options) { + options_(options), + check_with_browser_before_shutdown_(false) { DCHECK(owner_loop_); channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValue( switches::kProcessChannelID); @@ -66,6 +71,18 @@ void ChildThread::OnMessageReceived(const IPC::Message& msg) { if (resource_dispatcher_->OnMessageReceived(msg)) return; +#if defined(OS_WIN) + if (msg.type() == PluginProcessMsg_AskBeforeShutdown::ID) { + check_with_browser_before_shutdown_ = true; + return; + } + + if (msg.type() == PluginProcessMsg_Shutdown::ID) { + owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); + return; + } +#endif + if (msg.routing_id() == MSG_ROUTING_CONTROL) { OnControlMessageReceived(msg); } else { @@ -97,3 +114,16 @@ void ChildThread::CleanUp() { channel_.reset(); resource_dispatcher_.reset(); } + +void ChildThread::OnProcessFinalRelease() { + if (!check_with_browser_before_shutdown_) { + owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); + return; + } + + // The child process shutdown sequence is a request response based mechanism, + // where we send out an initial feeler request to the child process host + // instance in the browser to verify if it's ok to shutdown the child process. + // The browser then sends back a response if it's ok to shutdown. + Send(new PluginProcessHostMsg_ShutdownRequest); +} diff --git a/chrome/common/child_thread.h b/chrome/common/child_thread.h index c499cb5..66fcc09 100644 --- a/chrome/common/child_thread.h +++ b/chrome/common/child_thread.h @@ -41,6 +41,9 @@ class ChildThread : public IPC::Channel::Listener, // Overrides the channel name. Used for --single-process mode. void SetChannelName(const std::wstring& name) { channel_name_ = name; } + // Called when the process refcount is 0. + void OnProcessFinalRelease(); + protected: // The required stack size if V8 runs on a thread. static const size_t kV8StackSize; @@ -77,6 +80,11 @@ class ChildThread : public IPC::Channel::Listener, // NOTE: this object lives on the owner thread. scoped_ptr<ResourceDispatcher> resource_dispatcher_; + // If true, checks with the browser process before shutdown. This avoids race + // conditions if the process refcount is 0 but there's an IPC message inflight + // that would addref it. + bool check_with_browser_before_shutdown_; + DISALLOW_EVIL_CONSTRUCTORS(ChildThread); }; diff --git a/chrome/common/plugin_messages_internal.h b/chrome/common/plugin_messages_internal.h index b9c7a58..61c53f0 100644 --- a/chrome/common/plugin_messages_internal.h +++ b/chrome/common/plugin_messages_internal.h @@ -16,15 +16,19 @@ IPC_BEGIN_MESSAGES(PluginProcess) IPC_MESSAGE_CONTROL1(PluginProcessMsg_CreateChannel, bool /* off_the_record */) - IPC_MESSAGE_CONTROL1(PluginProcessMsg_ShutdownResponse, - bool /* ok to shutdown */) - // Allows a chrome plugin loaded in the browser process to send arbitrary // data to an instance of the same plugin loaded in a plugin process. IPC_MESSAGE_CONTROL1(PluginProcessMsg_PluginMessage, std::vector<uint8> /* opaque data */) - IPC_MESSAGE_CONTROL0(PluginProcessMsg_BrowserShutdown) + // The following messages are used by all child processes, even though they + // are listed under PluginProcess. It seems overkill to define ChildProcess. + // Tells the child process it should stop. + IPC_MESSAGE_CONTROL0(PluginProcessMsg_AskBeforeShutdown) + + // Sent in response to PluginProcessHostMsg_ShutdownRequest to tell the child + // process that it's safe to shutdown. + IPC_MESSAGE_CONTROL0(PluginProcessMsg_Shutdown) IPC_END_MESSAGES(PluginProcess) diff --git a/chrome/plugin/chrome_plugin_host.cc b/chrome/plugin/chrome_plugin_host.cc index 8ac50f2..48f975a 100644 --- a/chrome/plugin/chrome_plugin_host.cc +++ b/chrome/plugin/chrome_plugin_host.cc @@ -7,12 +7,12 @@ #include "base/command_line.h" #include "base/file_util.h" #include "base/message_loop.h" +#include "chrome/common/child_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_plugin_lib.h" #include "chrome/common/chrome_plugin_util.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/plugin_messages.h" -#include "chrome/plugin/plugin_process.h" #include "chrome/plugin/plugin_thread.h" #include "chrome/plugin/webplugin_proxy.h" #include "net/base/data_url.h" @@ -255,9 +255,9 @@ void STDCALL CPB_SetKeepProcessAlive(CPID id, CPBool keep_alive) { if (desired_value != g_keep_process_alive) { g_keep_process_alive = desired_value; if (g_keep_process_alive) - PluginProcess::current()->AddRefProcess(); + ChildProcess::current()->AddRefProcess(); else - PluginProcess::current()->ReleaseProcess(); + ChildProcess::current()->ReleaseProcess(); } } diff --git a/chrome/plugin/plugin.scons b/chrome/plugin/plugin.scons index 3cf9e84..5621eeb 100644 --- a/chrome/plugin/plugin.scons +++ b/chrome/plugin/plugin.scons @@ -43,8 +43,6 @@ input_files = ChromeFileList([ 'plugin_channel_base.cc', 'plugin_channel_base.h', 'plugin_main.cc', - 'plugin_process.cc', - 'plugin_process.h', 'plugin_thread.cc', 'plugin_thread.h', '$CHROME_DIR/tools/build/win/precompiled$OBJSUFFIX', @@ -69,7 +67,6 @@ if env.Bit('posix'): 'plugin_channel.cc', 'plugin_channel_base.cc', 'plugin_main.cc', - 'plugin_process.cc', 'plugin_thread.cc', 'webplugin_delegate_stub.cc', 'webplugin_proxy.cc', diff --git a/chrome/plugin/plugin.vcproj b/chrome/plugin/plugin.vcproj index fadc40c..4fd5459 100644 --- a/chrome/plugin/plugin.vcproj +++ b/chrome/plugin/plugin.vcproj @@ -178,14 +178,6 @@ > </File> <File - RelativePath=".\plugin_process.cc" - > - </File> - <File - RelativePath=".\plugin_process.h" - > - </File> - <File RelativePath=".\plugin_thread.cc" > </File> diff --git a/chrome/plugin/plugin_channel.cc b/chrome/plugin/plugin_channel.cc index 125054a..066bda3 100644 --- a/chrome/plugin/plugin_channel.cc +++ b/chrome/plugin/plugin_channel.cc @@ -6,12 +6,12 @@ #include "chrome/plugin/plugin_channel.h" -#include "chrome/common/plugin_messages.h" #include "base/command_line.h" #include "base/process_util.h" #include "base/string_util.h" +#include "chrome/common/child_process.h" +#include "chrome/common/plugin_messages.h" #include "chrome/common/chrome_switches.h" -#include "chrome/plugin/plugin_process.h" #include "chrome/plugin/plugin_thread.h" PluginChannel* PluginChannel::GetPluginChannel(MessageLoop* ipc_message_loop) { @@ -29,13 +29,13 @@ PluginChannel* PluginChannel::GetPluginChannel(MessageLoop* ipc_message_loop) { PluginChannel::PluginChannel() : in_send_(0), off_the_record_(false) { SendUnblockingOnlyDuringDispatch(); - PluginProcess::current()->AddRefProcess(); + ChildProcess::current()->AddRefProcess(); const CommandLine* command_line = CommandLine::ForCurrentProcess(); log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); } PluginChannel::~PluginChannel() { - PluginProcess::current()->ReleaseProcess(); + ChildProcess::current()->ReleaseProcess(); } bool PluginChannel::Send(IPC::Message* msg) { diff --git a/chrome/plugin/plugin_channel_base.cc b/chrome/plugin/plugin_channel_base.cc index 61b56d5..0e26e86 100644 --- a/chrome/plugin/plugin_channel_base.cc +++ b/chrome/plugin/plugin_channel_base.cc @@ -7,8 +7,8 @@ #include "chrome/plugin/plugin_channel_base.h" #include "base/hash_tables.h" +#include "chrome/common/child_process.h" #include "chrome/common/ipc_sync_message.h" -#include "chrome/plugin/plugin_process.h" typedef base::hash_map<std::wstring, scoped_refptr<PluginChannelBase> > PluginChannelMap; @@ -78,7 +78,7 @@ bool PluginChannelBase::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) { channel_.reset(new IPC::SyncChannel( channel_name_, mode_, this, NULL, ipc_message_loop, create_pipe_now, - PluginProcess::current()->GetShutDownEvent())); + ChildProcess::current()->GetShutDownEvent())); channel_valid_ = true; return true; } diff --git a/chrome/plugin/plugin_main.cc b/chrome/plugin/plugin_main.cc index f6808c1..fe71ea0 100644 --- a/chrome/plugin/plugin_main.cc +++ b/chrome/plugin/plugin_main.cc @@ -6,12 +6,13 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "base/system_monitor.h" +#include "chrome/common/child_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/main_function_params.h" #include "chrome/common/win_util.h" -#include "chrome/plugin/plugin_process.h" +#include "chrome/plugin/plugin_thread.h" #include "chrome/test/injection_test_dll.h" #include "sandbox/src/sandbox.h" @@ -54,7 +55,7 @@ int PluginMain(const MainFunctionParams& parameters) { } { - PluginProcess plugin_process; + ChildProcess plugin_process(new PluginThread()); if (!no_sandbox && target_services) { target_services->LowerToken(); } diff --git a/chrome/plugin/plugin_process.cc b/chrome/plugin/plugin_process.cc deleted file mode 100644 index 9d0f567..0000000 --- a/chrome/plugin/plugin_process.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2006-2008 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 <windows.h> -#include "chrome/plugin/plugin_process.h" - -#include "base/basictypes.h" -#include "base/scoped_handle.h" -#include "chrome/common/ipc_channel.h" -#include "chrome/common/ipc_message_utils.h" -#include "chrome/common/plugin_messages.h" -#include "chrome/common/render_messages.h" -#include "webkit/glue/webkit_glue.h" - -// How long to wait after there are no more plugin instances before killing the -// process. -static const int kProcessShutdownDelayMs = 10 * 1000; - -// No AddRef required when using PluginProcess with RunnableMethod. This is -// okay since the lifetime of the PluginProcess is always greater than the -// lifetime of PluginThread because it's a member variable. -template <> struct RunnableMethodTraits<PluginProcess> { - static void RetainCallee(PluginProcess*) {} - static void ReleaseCallee(PluginProcess*) {} -}; - -PluginProcess::PluginProcess() - : ChildProcess(new PluginThread()) { -} - -PluginProcess::~PluginProcess() { -} - -// Note: may be called on any thread -void PluginProcess::OnFinalRelease() { - // We override this to have the process linger for a few seconds to - // better accomdate back/forth navigation. This avoids shutting down and - // immediately starting a new plugin process. If a new channel is - // opened in the interim, the current process will not be shutdown. - child_thread()->owner_loop()->PostDelayedTask(FROM_HERE, NewRunnableMethod( - this, &PluginProcess::OnProcessShutdownTimeout), - kProcessShutdownDelayMs); -} - -void PluginProcess::OnProcessShutdownTimeout() { - if (ProcessRefCountIsZero()) { - // The plugin process shutdown sequence is a request response based - // mechanism, where we send out an initial feeler request to the plugin - // process host instance in the browser to verify if it is ok to shutdown - // the plugin process. The browser then sends back a response indicating - // whether it is ok to shutdown. - child_thread()->Send(new PluginProcessHostMsg_ShutdownRequest); - } -} - -void PluginProcess::Shutdown() { - ChildProcess::OnFinalRelease(); -} diff --git a/chrome/plugin/plugin_process.h b/chrome/plugin/plugin_process.h deleted file mode 100644 index 467b46d..0000000 --- a/chrome/plugin/plugin_process.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2006-2008 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_PLUGIN_PLUGIN_PROCESS_H_ -#define CHROME_PLUGIN_PLUGIN_PROCESS_H_ - -#include "base/file_path.h" -#include "chrome/common/child_process.h" -#include "chrome/plugin/plugin_thread.h" - -// Represents the plugin end of the renderer<->plugin connection. The -// opposite end is the PluginProcessHost. This is a singleton object for -// each plugin. -class PluginProcess : public ChildProcess { - public: - PluginProcess(); - virtual ~PluginProcess(); - - // Invoked when the browser is shutdown. This ensures that the plugin - // process does not hang around waiting for future invocations - // from the browser. - void Shutdown(); - - // Returns a pointer to the PluginProcess singleton instance. - static PluginProcess* current() { - return static_cast<PluginProcess*>(ChildProcess::current()); - } - - private: - - virtual void OnFinalRelease(); - void OnProcessShutdownTimeout(); - - DISALLOW_EVIL_CONSTRUCTORS(PluginProcess); -}; - -#endif // CHROME_PLUGIN_PLUGIN_PROCESS_H_ diff --git a/chrome/plugin/plugin_thread.cc b/chrome/plugin/plugin_thread.cc index 10172e7..9993c37 100644 --- a/chrome/plugin/plugin_thread.cc +++ b/chrome/plugin/plugin_thread.cc @@ -8,6 +8,7 @@ #include "chrome/plugin/plugin_thread.h" #include "base/command_line.h" +#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" @@ -15,7 +16,6 @@ #include "chrome/common/render_messages.h" #include "chrome/plugin/chrome_plugin_host.h" #include "chrome/plugin/npobject_util.h" -#include "chrome/plugin/plugin_process.h" #include "chrome/renderer/render_thread.h" #include "net/base/net_errors.h" #include "webkit/glue/plugins/plugin_lib.h" @@ -40,9 +40,7 @@ PluginThread* PluginThread::current() { void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { IPC_BEGIN_MESSAGE_MAP(PluginThread, msg) IPC_MESSAGE_HANDLER(PluginProcessMsg_CreateChannel, OnCreateChannel) - IPC_MESSAGE_HANDLER(PluginProcessMsg_ShutdownResponse, OnShutdownResponse) IPC_MESSAGE_HANDLER(PluginProcessMsg_PluginMessage, OnPluginMessage) - IPC_MESSAGE_HANDLER(PluginProcessMsg_BrowserShutdown, OnBrowserShutdown) IPC_END_MESSAGE_MAP() } @@ -100,27 +98,18 @@ void PluginThread::OnCreateChannel(bool off_the_record) { Send(new PluginProcessHostMsg_ChannelCreated(channel_name)); } -void PluginThread::OnShutdownResponse(bool ok_to_shutdown) { - if (ok_to_shutdown) - PluginProcess::current()->Shutdown(); -} - -void PluginThread::OnBrowserShutdown() { - PluginProcess::current()->Shutdown(); -} - void PluginThread::OnPluginMessage(const std::vector<unsigned char> &data) { // We Add/Release ref here to ensure that something will trigger the // shutdown mechanism for processes started in the absence of renderer's // opening a plugin channel. - PluginProcess::current()->AddRefProcess(); + ChildProcess::current()->AddRefProcess(); ChromePluginLib *chrome_plugin = ChromePluginLib::Find(plugin_path_); if (chrome_plugin) { void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); uint32 data_len = static_cast<uint32>(data.size()); chrome_plugin->functions().on_message(data_ptr, data_len); } - PluginProcess::current()->ReleaseProcess(); + ChildProcess::current()->ReleaseProcess(); } namespace webkit_glue { diff --git a/chrome/plugin/plugin_thread.h b/chrome/plugin/plugin_thread.h index 1550d5a..9b999e2 100644 --- a/chrome/plugin/plugin_thread.h +++ b/chrome/plugin/plugin_thread.h @@ -30,9 +30,7 @@ class PluginThread : public ChildThread { virtual void CleanUp(); void OnCreateChannel(bool off_the_record); - void OnShutdownResponse(bool ok_to_shutdown); void OnPluginMessage(const std::vector<uint8> &data); - void OnBrowserShutdown(); scoped_ptr<NotificationService> notification_service_; diff --git a/chrome/worker/webworkerclient_proxy.cc b/chrome/worker/webworkerclient_proxy.cc index 6cc3d9b..33bcbc8 100644 --- a/chrome/worker/webworkerclient_proxy.cc +++ b/chrome/worker/webworkerclient_proxy.cc @@ -4,9 +4,9 @@ #include "chrome/worker/webworkerclient_proxy.h" +#include "chrome/common/child_process.h" #include "chrome/common/ipc_logging.h" #include "chrome/common/worker_messages.h" -#include "chrome/worker/worker_process.h" #include "chrome/worker/worker_thread.h" #include "webkit/glue/webworker.h" @@ -17,12 +17,12 @@ WebWorkerClientProxy::WebWorkerClientProxy(const GURL& url, int route_id) ALLOW_THIS_IN_INITIALIZER_LIST(impl_(WebWorker::Create(this))) { AddRef(); WorkerThread::current()->AddRoute(route_id_, this); - WorkerProcess::current()->AddRefProcess(); + ChildProcess::current()->AddRefProcess(); } WebWorkerClientProxy::~WebWorkerClientProxy() { WorkerThread::current()->RemoveRoute(route_id_); - WorkerProcess::current()->ReleaseProcess(); + ChildProcess::current()->ReleaseProcess(); } void WebWorkerClientProxy::PostMessageToWorkerObject(const string16& message) { diff --git a/chrome/worker/worker.scons b/chrome/worker/worker.scons index 6b194c4..fe4aaa2 100644 --- a/chrome/worker/worker.scons +++ b/chrome/worker/worker.scons @@ -28,8 +28,6 @@ input_files = ChromeFileList([ 'webworkerclient_proxy.cc', 'webworkerclient_proxy.h', 'worker_main.cc', - 'worker_process.cc', - 'worker_process.h', 'worker_thread.cc', 'worker_thread.h', 'worker_webkitclient_impl.cc', @@ -48,7 +46,6 @@ if env.Bit('posix'): input_files.Remove( 'webworker.cc', 'worker_main.cc', - 'worker_process.cc', 'worker_thread.cc', 'worker_webkitclient_impl.cc', ) diff --git a/chrome/worker/worker.vcproj b/chrome/worker/worker.vcproj index 8adcbab..96d5aa34 100644 --- a/chrome/worker/worker.vcproj +++ b/chrome/worker/worker.vcproj @@ -150,14 +150,6 @@ >
</File>
<File
- RelativePath=".\worker_process.cc"
- >
- </File>
- <File
- RelativePath=".\worker_process.h"
- >
- </File>
- <File
RelativePath=".\worker_thread.cc"
>
</File>
diff --git a/chrome/worker/worker_main.cc b/chrome/worker/worker_main.cc index 1b973c3..ad41a8b 100644 --- a/chrome/worker/worker_main.cc +++ b/chrome/worker/worker_main.cc @@ -6,12 +6,13 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "base/system_monitor.h" +#include "chrome/common/child_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/main_function_params.h" #include "chrome/common/win_util.h" -#include "chrome/worker/worker_process.h" +#include "chrome/worker/worker_thread.h" #if defined(OS_WIN) #include "chrome/common/sandbox_init_wrapper.h" @@ -30,7 +31,7 @@ int WorkerMain(const MainFunctionParams& parameters) { // Initialize the SystemMonitor base::SystemMonitor::Start(); - WorkerProcess worker_process; + ChildProcess worker_process(new WorkerThread()); #if defined(OS_WIN) sandbox::TargetServices* target_services = parameters.sandbox_info_.TargetServices(); diff --git a/chrome/worker/worker_process.cc b/chrome/worker/worker_process.cc deleted file mode 100644 index 4d319e3..0000000 --- a/chrome/worker/worker_process.cc +++ /dev/null @@ -1,14 +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/worker/worker_process.h" - -#include "chrome/worker/worker_thread.h" - -WorkerProcess::WorkerProcess() - : ChildProcess(new WorkerThread()) { -} - -WorkerProcess::~WorkerProcess() { -} diff --git a/chrome/worker/worker_process.h b/chrome/worker/worker_process.h deleted file mode 100644 index da76781..0000000 --- a/chrome/worker/worker_process.h +++ /dev/null @@ -1,28 +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_WORKER_WORKER_PROCESS_H_ -#define CHROME_WORKER_WORKER_PROCESS_H_ - -#include "chrome/common/child_process.h" - -// Represents the worker end of the renderer<->worker connection. The -// opposite end is the WorkerProcessHost. This is a singleton object for -// each worker process. -class WorkerProcess : public ChildProcess { - public: - WorkerProcess(); - virtual ~WorkerProcess(); - - // Returns a pointer to the PluginProcess singleton instance. - static WorkerProcess* current() { - return static_cast<WorkerProcess*>(ChildProcess::current()); - } - - private: - - DISALLOW_COPY_AND_ASSIGN(WorkerProcess); -}; - -#endif // CHROME_WORKER_WORKER_PROCESS_H_ diff --git a/chrome/worker/worker_thread.cc b/chrome/worker/worker_thread.cc index 8091dbf..f37904a 100644 --- a/chrome/worker/worker_thread.cc +++ b/chrome/worker/worker_thread.cc @@ -6,7 +6,6 @@ #include "chrome/common/worker_messages.h" #include "chrome/worker/webworkerclient_proxy.h" -#include "chrome/worker/worker_process.h" #include "chrome/worker/worker_webkitclient_impl.h" #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" |