diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 18:02:22 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 18:02:22 +0000 |
commit | 8d5c43c4a9958b592565da16912fd44960aab906 (patch) | |
tree | 3cefd920d10a6355df674c3f05d542bba4777485 | |
parent | 1226abb3175f2386c071946f51f2a8b79061d695 (diff) | |
download | chromium_src-8d5c43c4a9958b592565da16912fd44960aab906.zip chromium_src-8d5c43c4a9958b592565da16912fd44960aab906.tar.gz chromium_src-8d5c43c4a9958b592565da16912fd44960aab906.tar.bz2 |
Keep the internal plugin always loaded in a more efficient way (i.e. don't initialize it until it's needed).
Review URL: http://codereview.chromium.org/2747007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49418 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/render_process_impl.cc | 17 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib.cc | 44 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib.h | 4 |
3 files changed, 35 insertions, 30 deletions
diff --git a/chrome/renderer/render_process_impl.cc b/chrome/renderer/render_process_impl.cc index 659d1b7..30d7493 100644 --- a/chrome/renderer/render_process_impl.cc +++ b/chrome/renderer/render_process_impl.cc @@ -187,23 +187,16 @@ RenderProcessImpl::RenderProcessImpl() if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf)) { static scoped_refptr<NPAPI::PluginLib> pdf_lib = NPAPI::PluginLib::CreatePluginLib(pdf); - // Actually load the plugin. - pdf_lib->NP_Initialize(); - // Keep an instance around to prevent the plugin unloading after a pdf is - // closed. - // Don't use scoped_ptr here because then get asserts on process shut down - // when running in --single-process. - static NPAPI::PluginInstance* instance = pdf_lib->CreateInstance(""); - instance->plugin_lib(); // Quiet unused variable warnings in gcc. + // Load the plugin now before the sandbox engages and keep it always loaded. + pdf_lib->EnsureAlwaysLoaded(); #if defined(OS_WIN) g_iat_patch_createdca.Patch( pdf_lib->plugin_info().path.value().c_str(), "gdi32.dll", "CreateDCA", CreateDCAPatch); - g_iat_patch_get_font_data.Patch( - pdf_lib->plugin_info().path.value().c_str(), - "gdi32.dll", "GetFontData", GetFontDataPatch); - + g_iat_patch_get_font_data.Patch( + pdf_lib->plugin_info().path.value().c_str(), + "gdi32.dll", "GetFontData", GetFontDataPatch); #endif } } diff --git a/webkit/glue/plugins/plugin_lib.cc b/webkit/glue/plugins/plugin_lib.cc index 921ef5d..c335b51 100644 --- a/webkit/glue/plugins/plugin_lib.cc +++ b/webkit/glue/plugins/plugin_lib.cc @@ -61,11 +61,12 @@ void PluginLib::ShutdownAllPlugins() { PluginLib::PluginLib(const WebPluginInfo& info, const PluginEntryPoints* entry_points) : web_plugin_info_(info), - library_(0), + library_(NULL), initialized_(false), saved_data_(0), instance_count_(0), - skip_unload_(false) { + skip_unload_(false), + always_loaded_(false) { StatsCounter(kPluginLibrariesLoadedCounter).Increment(); memset((void*)&plugin_funcs_, 0, sizeof(plugin_funcs_)); g_loaded_libs->push_back(this); @@ -132,6 +133,11 @@ void PluginLib::PreventLibraryUnload() { skip_unload_ = true; } +void PluginLib::EnsureAlwaysLoaded() { + always_loaded_ = true; + Load(); +} + PluginInstance* PluginLib::CreateInstance(const std::string& mime_type) { PluginInstance* new_instance = new PluginInstance(this, mime_type); instance_count_++; @@ -145,30 +151,18 @@ void PluginLib::CloseInstance() { instance_count_--; // If a plugin is running in its own process it will get unloaded on process // shutdown. - if ((instance_count_ == 0) && - webkit_glue::IsPluginRunningInRendererProcess()) { + if ((instance_count_ == 0) && webkit_glue::IsPluginRunningInRendererProcess()) Unload(); - for (size_t i = 0; i < g_loaded_libs->size(); ++i) { - if ((*g_loaded_libs)[i].get() == this) { - g_loaded_libs->erase(g_loaded_libs->begin() + i); - break; - } - } - if (g_loaded_libs->empty()) { - delete g_loaded_libs; - g_loaded_libs = NULL; - } - } } bool PluginLib::Load() { + if (library_) + return true; + bool rv = false; base::NativeLibrary library = 0; if (!internal_) { - if (library_ != 0) - return rv; - library = base::LoadNativeLibrary(web_plugin_info_.path); if (library == 0) return rv; @@ -254,6 +248,9 @@ class FreePluginLibraryTask : public Task { }; void PluginLib::Unload() { + if (always_loaded_) + return; + if (!internal_ && library_) { // In case of single process mode, a plugin can delete itself // by executing a script. So delay the unloading of the library @@ -282,6 +279,17 @@ void PluginLib::Unload() { library_ = 0; } + + for (size_t i = 0; i < g_loaded_libs->size(); ++i) { + if ((*g_loaded_libs)[i].get() == this) { + g_loaded_libs->erase(g_loaded_libs->begin() + i); + break; + } + } + if (g_loaded_libs->empty()) { + delete g_loaded_libs; + g_loaded_libs = NULL; + } } void PluginLib::Shutdown() { diff --git a/webkit/glue/plugins/plugin_lib.h b/webkit/glue/plugins/plugin_lib.h index dc0b304..53568f1 100644 --- a/webkit/glue/plugins/plugin_lib.h +++ b/webkit/glue/plugins/plugin_lib.h @@ -78,6 +78,9 @@ class PluginLib : public base::RefCounted<PluginLib> { // some plugins crash if unloaded). void PreventLibraryUnload(); + // Loads the library now and ensures it's never unloaded. + void EnsureAlwaysLoaded(); + private: friend class base::RefCounted<PluginLib>; @@ -107,6 +110,7 @@ class PluginLib : public base::RefCounted<PluginLib> { NPSavedData *saved_data_; // Persisted plugin info for NPAPI. int instance_count_; // Count of plugins in use. bool skip_unload_; // True if library_ should not be unloaded. + bool always_loaded_; // True if should always keep this loaded. // Function pointers to entry points into the plugin. PluginEntryPoints entry_points_; |