diff options
Diffstat (limited to 'chrome/browser/rlz/rlz.cc')
-rw-r--r-- | chrome/browser/rlz/rlz.cc | 22 |
1 files changed, 21 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(); +} |