summaryrefslogtreecommitdiffstats
path: root/chrome/browser/background_contents_service.h
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-21 01:46:08 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-21 01:46:08 +0000
commit398206ce0943c935a8da55d382e60e7be16099cf (patch)
treef45ab7ef6f6c101b142a7d5c1393c6455caf2e70 /chrome/browser/background_contents_service.h
parent0965c6d6d392916a4017bce6ddf5fef8d5bcd22a (diff)
downloadchromium_src-398206ce0943c935a8da55d382e60e7be16099cf.zip
chromium_src-398206ce0943c935a8da55d382e60e7be16099cf.tar.gz
chromium_src-398206ce0943c935a8da55d382e60e7be16099cf.tar.bz2
Added BackgroundContentsService to manage lifecycle of BackgroundContents.
If --restore-background-contents flag is passed, stores the URLs of running BackgroundContents in preferences so they can be re-launched when the browser restarts. Moved logic to shutdown background contents into BackgroundContentsService so we can use this to coordinate when to keep the browser process running. BUG=43382 TEST=new tests Review URL: http://codereview.chromium.org/2104018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50329 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/background_contents_service.h')
-rw-r--r--chrome/browser/background_contents_service.h113
1 files changed, 113 insertions, 0 deletions
diff --git a/chrome/browser/background_contents_service.h b/chrome/browser/background_contents_service.h
new file mode 100644
index 0000000..d9e9e67
--- /dev/null
+++ b/chrome/browser/background_contents_service.h
@@ -0,0 +1,113 @@
+// 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_CONTENTS_SERVICE_H_
+#define CHROME_BROWSER_BACKGROUND_CONTENTS_SERVICE_H_
+
+#include <map>
+
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest_prod.h"
+
+class BackgroundContents;
+class CommandLine;
+class PrefService;
+class Profile;
+struct BackgroundContentsOpenedDetails;
+
+// BackgroundContentsService is owned by the profile, and is responsible for
+// managing the lifetime of BackgroundContents (tracking the set of background
+// urls, loading them at startup, and keeping the browser process alive as long
+// as there are BackgroundContents loaded).
+//
+// It is also responsible for tracking the association between
+// BackgroundContents and their parent app, and shutting them down when the
+// parent app is unloaded.
+class BackgroundContentsService : private NotificationObserver {
+ public:
+ BackgroundContentsService(Profile* profile, const CommandLine* command_line);
+ virtual ~BackgroundContentsService();
+
+ // Returns the BackgroundContents associated with the passed application id,
+ // or NULL if none.
+ BackgroundContents* GetAppBackgroundContents(const string16& appid);
+
+ static void RegisterUserPrefs(PrefService* prefs);
+
+ private:
+ friend class BackgroundContentsServiceTest;
+ FRIEND_TEST(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy);
+ FRIEND_TEST(BackgroundContentsServiceTest, TestApplicationIDLinkage);
+
+ // Registers for various notifications.
+ void StartObserving(Profile* profile);
+
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ // Loads all registered BackgroundContents at startup.
+ void LoadBackgroundContentsFromPrefs();
+
+ // Creates a single BackgroundContents associated with the specified |appid|.
+ // The BackgroundContents frame will be given the name specified by
+ // |frame_name| and navigated to the passed URL.
+ void CreateBackgroundContents(const GURL& url,
+ const string16& frame_name,
+ const string16& appid);
+
+ // Invoked when a new BackgroundContents is opened.
+ void BackgroundContentsOpened(BackgroundContentsOpenedDetails* details);
+
+ // Invoked when a BackgroundContents object is destroyed.
+ void BackgroundContentsShutdown(BackgroundContents* contents);
+
+ // Registers the |contents->GetURL()| to be run at startup. Only happens for
+ // the first navigation after window.open() (future calls to
+ // RegisterBackgroundContents() for the same BackgroundContents will do
+ // nothing).
+ void RegisterBackgroundContents(BackgroundContents* contents);
+
+ // Stops loading the passed BackgroundContents on startup.
+ void UnregisterBackgroundContents(BackgroundContents* contents);
+
+ // Unregisters and deletes the BackgroundContents associated with the
+ // passed extension.
+ void ShutdownAssociatedBackgroundContents(const string16& appid);
+
+ // Returns true if this BackgroundContents is in the contents_list_.
+ bool IsTracked(BackgroundContents* contents) const;
+
+ // Gets the parent application id for the passed BackgroundContents. Returns
+ // an empty string if no parent application found (e.g. passed
+ // BackgroundContents has already shut down).
+ const string16& GetParentApplicationId(BackgroundContents* contents) const;
+
+ // PrefService used to store list of background pages (or NULL if this is
+ // running under an off-the-record profile).
+ PrefService* prefs_;
+ NotificationRegistrar registrar_;
+
+ // Information we track about each BackgroundContents.
+ struct BackgroundContentsInfo {
+ // The BackgroundContents whose information we are tracking.
+ BackgroundContents* contents;
+ // The name of the top level frame for this BackgroundContents.
+ string16 frame_name;
+ };
+
+ // Map associating currently loaded BackgroundContents with their parent
+ // applications.
+ // Key: application id
+ // Value: BackgroundContentsInfo for the BC associated with that application
+ typedef std::map<string16, BackgroundContentsInfo> BackgroundContentsMap;
+ BackgroundContentsMap contents_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(BackgroundContentsService);
+};
+
+#endif // CHROME_BROWSER_BACKGROUND_CONTENTS_SERVICE_H_