summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 15:32:52 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 15:32:52 +0000
commitd4af8e56a65e79313231d322a17013be946647e5 (patch)
treecc1d205aefc77c8b9a2f786acf2f64222c464cd5
parentab73904ffa1b236905a4f1253dd03e02dd9e8695 (diff)
downloadchromium_src-d4af8e56a65e79313231d322a17013be946647e5.zip
chromium_src-d4af8e56a65e79313231d322a17013be946647e5.tar.gz
chromium_src-d4af8e56a65e79313231d322a17013be946647e5.tar.bz2
Leak the resource tracker and any resources still around at shutdown. The
reasoning is described in the comment above the global_tracker_ member. TEST=manual BUG=none Review URL: http://codereview.chromium.org/6804031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80782 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/plugins/ppapi/resource_tracker.cc9
-rw-r--r--webkit/plugins/ppapi/resource_tracker.h25
2 files changed, 24 insertions, 10 deletions
diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc
index 79a0125..4642b63 100644
--- a/webkit/plugins/ppapi/resource_tracker.cc
+++ b/webkit/plugins/ppapi/resource_tracker.cc
@@ -7,7 +7,6 @@
#include <limits>
#include <set>
-#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/rand_util.h"
#include "ppapi/c/pp_resource.h"
@@ -44,9 +43,6 @@ template <typename T> static inline bool CheckIdType(T id, PPIdType type) {
namespace webkit {
namespace ppapi {
-static base::LazyInstance<ResourceTracker> g_resource_tracker(
- base::LINKER_INITIALIZED);
-
struct ResourceTracker::InstanceData {
InstanceData() : instance(0) {}
@@ -70,6 +66,7 @@ scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const {
}
// static
+ResourceTracker* ResourceTracker::global_tracker_ = NULL;
ResourceTracker* ResourceTracker::singleton_override_ = NULL;
ResourceTracker::ResourceTracker()
@@ -84,7 +81,9 @@ ResourceTracker::~ResourceTracker() {
ResourceTracker* ResourceTracker::Get() {
if (singleton_override_)
return singleton_override_;
- return g_resource_tracker.Pointer();
+ if (!global_tracker_)
+ global_tracker_ = new ResourceTracker;
+ return global_tracker_;
}
PP_Resource ResourceTracker::AddResource(Resource* resource) {
diff --git a/webkit/plugins/ppapi/resource_tracker.h b/webkit/plugins/ppapi/resource_tracker.h
index f0610db..a5cd70d 100644
--- a/webkit/plugins/ppapi/resource_tracker.h
+++ b/webkit/plugins/ppapi/resource_tracker.h
@@ -17,10 +17,6 @@
#include "ppapi/c/pp_module.h"
#include "ppapi/c/pp_resource.h"
-namespace base {
-template <typename T> struct DefaultLazyInstanceTraits;
-}
-
namespace webkit {
namespace ppapi {
@@ -95,7 +91,6 @@ class ResourceTracker {
PluginInstance* GetInstance(PP_Instance instance);
private:
- friend struct base::DefaultLazyInstanceTraits<ResourceTracker>;
friend class Resource;
friend class ResourceTrackerTest;
friend class Var;
@@ -131,6 +126,26 @@ class ResourceTracker {
static void SetSingletonOverride(ResourceTracker* tracker);
static void ClearSingletonOverride();
+ // The lazy-initialized global instance of this object. This is created in
+ // ::Get() if there is no singleton_override_ specified.
+ //
+ // It would be nice to use LazyInstance for this since it manages the
+ // creation properly, and also cleans up on shutdown. However, the shutdown
+ // cleanup causes problems in some cases.
+ //
+ // For example, say the browser crashes or is killed. The renderer then
+ // decides to exit. Normally resources are bound to an instance and are
+ // cleaned up when WebKit deletes the instance (when you go to a different
+ // page or close that view). In this case, WebKit doesn't clean up. If the
+ // ResourceTracker was cleaned up by the AtExitManager (which would be the
+ // case with LazyInstance/Singleton) then we'd try to call up to the renderer
+ // layer via the delegate, which may be in a random state of shutdown.
+ //
+ // So effectively our rule is: any resources still around at shutdown are
+ // associated with leaked plugins in WebKit, so it's also OK to leak those
+ // resources from here (avoiding the shutdown race).
+ static ResourceTracker* global_tracker_;
+
// See SetSingletonOverride above.
static ResourceTracker* singleton_override_;