summaryrefslogtreecommitdiffstats
path: root/webkit/glue/plugins
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-21 19:38:14 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-21 19:38:14 +0000
commit1953711651f746346155172d957f6b1817e7e9c3 (patch)
tree51b613f41932b1b51c11abb08b47da2438813d56 /webkit/glue/plugins
parent848ecead9eab06c735a7520a4c4bc1dc1632e403 (diff)
downloadchromium_src-1953711651f746346155172d957f6b1817e7e9c3.zip
chromium_src-1953711651f746346155172d957f6b1817e7e9c3.tar.gz
chromium_src-1953711651f746346155172d957f6b1817e7e9c3.tar.bz2
Some cleanup to the PluginList Singleton.
- Remove unneeded ref counting. - Remove a static constructor (scoped_refptr). - Remove a leak (extra_plugin_paths_). This slightly changes the code, since PlatformInit could be called before Singleton, via AddExtraPluginPaths. I don't think this should be a problem. Review URL: http://codereview.chromium.org/18454 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8382 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/plugins')
-rw-r--r--webkit/glue/plugins/plugin_list.cc39
-rw-r--r--webkit/glue/plugins/plugin_list.h27
2 files changed, 35 insertions, 31 deletions
diff --git a/webkit/glue/plugins/plugin_list.cc b/webkit/glue/plugins/plugin_list.cc
index a32fe62..4484fa3 100644
--- a/webkit/glue/plugins/plugin_list.cc
+++ b/webkit/glue/plugins/plugin_list.cc
@@ -6,6 +6,7 @@
#include "webkit/glue/plugins/plugin_list.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/time.h"
@@ -19,33 +20,30 @@
#include "webkit/glue/plugins/plugin_constants_win.h"
#endif
-namespace NPAPI
-{
+namespace NPAPI {
-scoped_refptr<PluginList> PluginList::singleton_;
-
-// Extra paths to search.
-static std::vector<FilePath>* extra_plugin_paths_ = NULL;
+base::LazyInstance<PluginList> g_singleton(base::LINKER_INITIALIZED);
+// static
PluginList* PluginList::Singleton() {
- if (singleton_.get() == NULL) {
- singleton_ = new PluginList();
- singleton_->LoadPlugins(false);
+ PluginList* singleton = g_singleton.Pointer();
+ if (!singleton->plugins_loaded_) {
+ singleton->LoadPlugins(false);
+ DCHECK(singleton->plugins_loaded_);
}
-
- return singleton_;
+ return singleton;
}
+// static
void PluginList::AddExtraPluginPath(const FilePath& plugin_path) {
- DCHECK(!singleton_.get() || !singleton_->plugins_loaded_);
+ // We access the singleton directly, and not through Singleton(), since
+ // we don't want LoadPlugins() to be called.
+ DCHECK(!g_singleton.Pointer()->plugins_loaded_);
- if (!extra_plugin_paths_)
- extra_plugin_paths_ = new std::vector<FilePath>;
- extra_plugin_paths_->push_back(plugin_path);
+ g_singleton.Pointer()->extra_plugin_paths_.push_back(plugin_path);
}
-PluginList::PluginList() :
- plugins_loaded_(false) {
+PluginList::PluginList() : plugins_loaded_(false) {
PlatformInit();
}
@@ -67,10 +65,9 @@ void PluginList::LoadPlugins(bool refresh) {
LoadPluginsFromDir(directories_to_scan[i]);
}
- if (extra_plugin_paths_) {
- for (size_t i = 0; i < extra_plugin_paths_->size(); ++i)
- LoadPlugin((*extra_plugin_paths_)[i]);
- }
+ for (size_t i = 0; i < extra_plugin_paths_.size(); ++i)
+ LoadPlugin(extra_plugin_paths_[i]);
+ extra_plugin_paths_.clear();
if (webkit_glue::IsDefaultPluginEnabled())
LoadPlugin(FilePath(kDefaultPluginLibraryName));
diff --git a/webkit/glue/plugins/plugin_list.h b/webkit/glue/plugins/plugin_list.h
index 3b1a76d..9c4efef 100644
--- a/webkit/glue/plugins/plugin_list.h
+++ b/webkit/glue/plugins/plugin_list.h
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// TODO: Need mechanism to cleanup the static instance
-
#ifndef WEBKIT_GLUE_PLUGIN_PLUGIN_LIST_H__
#define WEBKIT_GLUE_PLUGIN_PLUGIN_LIST_H__
@@ -18,6 +16,13 @@
class GURL;
+namespace base {
+
+template <typename T>
+struct DefaultLazyInstanceTraits;
+
+} // namespace base
+
namespace NPAPI
{
@@ -33,14 +38,12 @@ class PluginInstance;
// the machine-wide and user plugin directories and loads anything that has
// the correct types. On Linux, it walks the plugin directories as well
// (e.g. /usr/lib/browser-plugins/).
-class PluginList : public base::RefCounted<PluginList> {
+class PluginList {
public:
- // Gets the one instance of the PluginList.
- //
- // Accessing the singleton causes the PluginList to look on
- // disk for existing plugins. It does not actually load
- // libraries, that will only happen when you initialize
- // the plugin for the first time.
+ // Gets the one instance of the PluginList. Accessing the singleton causes
+ // the PluginList to look on disk for existing plugins. It does not actually
+ // load libraries, that will only happen when you initialize the plugin for
+ // the first time.
static PluginList* Singleton();
// Add an extra plugin to load when we actually do the loading. This is
@@ -145,12 +148,16 @@ class PluginList : public base::RefCounted<PluginList> {
// Internals
//
- static scoped_refptr<PluginList> singleton_;
bool plugins_loaded_;
// Contains information about the available plugins.
std::vector<WebPluginInfo> plugins_;
+ // Extra plugin paths that we want to search when loading.
+ std::vector<FilePath> extra_plugin_paths_;
+
+ friend struct base::DefaultLazyInstanceTraits<PluginList>;
+
DISALLOW_EVIL_CONSTRUCTORS(PluginList);
};