summaryrefslogtreecommitdiffstats
path: root/chrome/browser/rlz
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-28 21:53:16 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-28 21:53:16 +0000
commit4663213354a9c41ab0e5a785d52bf5c9a9692514 (patch)
treee171f81dc4e0bd37b993b077a69ea5199a42d7b6 /chrome/browser/rlz
parentbc90a55d0dd209e0d3a1c719f54226becb045dd8 (diff)
downloadchromium_src-4663213354a9c41ab0e5a785d52bf5c9a9692514.zip
chromium_src-4663213354a9c41ab0e5a785d52bf5c9a9692514.tar.gz
chromium_src-4663213354a9c41ab0e5a785d52bf5c9a9692514.tar.bz2
Adds cleanup code to RLZ so that we don't leak an OmniBoxUsageObserver
on shutdown. This came up in running in process ui tests through purify. BUG=none TEST=none Review URL: http://codereview.chromium.org/19428 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8830 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/rlz')
-rw-r--r--chrome/browser/rlz/rlz.cc22
-rw-r--r--chrome/browser/rlz/rlz.h3
2 files changed, 24 insertions, 1 deletions
diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc
index 6434fb1..33e9b59 100644
--- a/chrome/browser/rlz/rlz.cc
+++ b/chrome/browser/rlz/rlz.cc
@@ -127,6 +127,8 @@ class OmniBoxUsageObserver : public NotificationObserver {
NOTIFY_OMNIBOX_OPENED_URL,
NotificationService::AllSources());
omnibox_used_ = false;
+ DCHECK(!instance_);
+ instance_ = this;
}
virtual void Observe(NotificationType type,
@@ -145,18 +147,31 @@ class OmniBoxUsageObserver : public NotificationObserver {
return omnibox_used_;
}
+ // Deletes the single instance of OmniBoxUsageObserver.
+ static void DeleteInstance() {
+ delete instance_;
+ }
+
private:
// Dtor is private so the object cannot be created on the stack.
~OmniBoxUsageObserver() {
NotificationService::current()->RemoveObserver(this,
NOTIFY_OMNIBOX_OPENED_URL,
NotificationService::AllSources());
+ instance_ = NULL;
}
static bool omnibox_used_;
+
+ // There should only be one instance created at a time, and instance_ points
+ // to that instance.
+ // NOTE: this is only non-null for the amount of time it is needed. Once the
+ // instance_ is no longer needed (or Chrome is exitting), this is null.
+ static OmniBoxUsageObserver* instance_;
};
bool OmniBoxUsageObserver::omnibox_used_ = false;
+OmniBoxUsageObserver* OmniBoxUsageObserver::instance_ = NULL;
// This task is run in the file thread, so to not block it for a long time
// we use a throwaway thread to do the blocking url request.
@@ -273,7 +288,8 @@ bool RLZTracker::InitRlz(int directory_key) {
}
bool RLZTracker::InitRlzDelayed(int directory_key, bool first_run) {
- new OmniBoxUsageObserver();
+ if (!OmniBoxUsageObserver::used())
+ new OmniBoxUsageObserver();
// Schedule the delayed init items.
const int kTwentySeconds = 20 * 1000;
MessageLoop::current()->PostDelayedTask(FROM_HERE,
@@ -314,3 +330,7 @@ bool RLZTracker::GetAccessPointRlz(AccessPoint point, std::wstring* rlz) {
return true;
}
+// static
+void RLZTracker::CleanupRlz() {
+ OmniBoxUsageObserver::DeleteInstance();
+}
diff --git a/chrome/browser/rlz/rlz.h b/chrome/browser/rlz/rlz.h
index 23aa88b..69199ae 100644
--- a/chrome/browser/rlz/rlz.h
+++ b/chrome/browser/rlz/rlz.h
@@ -89,6 +89,9 @@ class RLZTracker {
// when it is un-installed.
static bool ClearAllProductEvents(Product product);
+ // Invoked during shutdown to clean up any state created by RLZTracker.
+ static void CleanupRlz();
+
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(RLZTracker);
};