summaryrefslogtreecommitdiffstats
path: root/chrome/browser/background_page_tracker.h
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-22 20:53:44 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-22 20:53:44 +0000
commitb569c11767085b8e4b440d51b3bb84740a91f204 (patch)
tree2249778ad3d12ccbfdcebc89ff8f52f3a699a5b6 /chrome/browser/background_page_tracker.h
parentca6c990f200c470f2f026ccafac39e29a23c26f2 (diff)
downloadchromium_src-b569c11767085b8e4b440d51b3bb84740a91f204.zip
chromium_src-b569c11767085b8e4b440d51b3bb84740a91f204.tar.gz
chromium_src-b569c11767085b8e4b440d51b3bb84740a91f204.tar.bz2
Display badge when new background page is installed.
Added BackgroundPageTracker which tracks which extensions/apps contain background pages. Added code to wrench menu/toolbar to display a badge when there is a new background page added to the system. BUG=59980 TEST=BackgroundPageTrackerTest Review URL: http://codereview.chromium.org/5207002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/background_page_tracker.h')
-rw-r--r--chrome/browser/background_page_tracker.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/chrome/browser/background_page_tracker.h b/chrome/browser/background_page_tracker.h
new file mode 100644
index 0000000..2b3b90c
--- /dev/null
+++ b/chrome/browser/background_page_tracker.h
@@ -0,0 +1,95 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_BACKGROUND_PAGE_TRACKER_H_
+#define CHROME_BROWSER_BACKGROUND_PAGE_TRACKER_H_
+#pragma once
+
+#include <map>
+#include <string>
+
+#include "base/gtest_prod_util.h"
+#include "base/singleton.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
+
+class PrefService;
+
+///////////////////////////////////////////////////////////////////////////////
+// BackgroundPageTracker
+//
+// This class is a singleton class that monitors when new background pages are
+// loaded, and sends out a notification.
+//
+class BackgroundPageTracker : public NotificationObserver {
+ public:
+ static void RegisterPrefs(PrefService* prefs);
+
+ // Convenience routine which gets the singleton object.
+ static BackgroundPageTracker* GetSingleton();
+
+ // Returns the number of background apps/extensions currently loaded.
+ int GetBackgroundPageCount();
+
+ // Returns the number of unacknowledged background pages (for use in badges,
+ // etc).
+ int GetUnacknowledgedBackgroundPageCount();
+
+ // Called when the user has acknowledged that new background apps have been
+ // loaded. Future calls to GetUnacknowledgedBackgroundPageCount() will return
+ // 0 until another background page is installed.
+ void AcknowledgeBackgroundPages();
+
+ protected:
+ // Constructor marked as protected so we can create mock subclasses.
+ BackgroundPageTracker();
+ ~BackgroundPageTracker();
+ friend struct DefaultSingletonTraits<BackgroundPageTracker>;
+ friend class BackgroundPageTrackerTest;
+ FRIEND_TEST_ALL_PREFIXES(BackgroundPageTrackerTest, OnBackgroundPageLoaded);
+ FRIEND_TEST_ALL_PREFIXES(BackgroundPageTrackerTest,
+ AcknowledgeBackgroundPages);
+ FRIEND_TEST_ALL_PREFIXES(BackgroundPageTrackerTest,
+ TestTrackerChangedNotifications);
+
+ // Mockable method to get the PrefService where we store information about
+ // background pages.
+ virtual PrefService* GetPrefService();
+
+ // Helper routine which checks to see if this object should be enabled or not.
+ // If false, the BackgroundPageTracker always acts as if there are no
+ // background pages. Virtual to allow enabling in mocks.
+ virtual bool IsEnabled();
+
+ private:
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ // Invoked once all extensions have been loaded, so we can update our list of
+ // tracked pages and send out the appropriate notifications. Returns true if
+ // the extension list was changed.
+ bool UpdateExtensionList();
+
+ // Called when a background page is loaded (either because a hosted app
+ // opened a BackgroundContents or a packaged extension was loaded with an
+ // extension background page). Updates our internal list of unacknowledged
+ // background pages.
+ void OnBackgroundPageLoaded(const std::string& parent_application_id);
+
+ // When an extension is unloaded, removes it from the list of background pages
+ // so we no longer nag the user about it (if it is still unacknowledged) and
+ // we inform the user if it is ever re-installed/enabled.
+ void OnExtensionUnloaded(const std::string& parent_application_id);
+
+ // Sends out a notification that the list of background pages has changed.
+ void SendChangeNotification();
+
+ NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(BackgroundPageTracker);
+};
+
+#endif // CHROME_BROWSER_BACKGROUND_PAGE_TRACKER_H_