summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/lazy_background_task_queue.h
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 18:55:23 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 18:55:23 +0000
commitb6536df0203bcb40613d40a6ae28a82c6e8a2e95 (patch)
treed12ed781ce6a46063613a5f6123e8707c9cb0690 /chrome/browser/extensions/lazy_background_task_queue.h
parent950ee84c28a20172764da99ed03a4f0d4c9cc371 (diff)
downloadchromium_src-b6536df0203bcb40613d40a6ae28a82c6e8a2e95.zip
chromium_src-b6536df0203bcb40613d40a6ae28a82c6e8a2e95.tar.gz
chromium_src-b6536df0203bcb40613d40a6ae28a82c6e8a2e95.tar.bz2
Lazy background pages now load in response to message passing.
I refactored the pending event stuff so that it handles generic tasks. The first enqueued task for an extension will start its lazy background page, and tasks are run once the page finishes loading. Events and messages now share this mechanism so that either one can activate the page. BUG=81752 TEST=no Review URL: https://chromiumcodereview.appspot.com/9704031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127216 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/lazy_background_task_queue.h')
-rw-r--r--chrome/browser/extensions/lazy_background_task_queue.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/chrome/browser/extensions/lazy_background_task_queue.h b/chrome/browser/extensions/lazy_background_task_queue.h
new file mode 100644
index 0000000..63936b6
--- /dev/null
+++ b/chrome/browser/extensions/lazy_background_task_queue.h
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 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_EXTENSIONS_LAZY_BACKGROUND_TASK_QUEUE_H_
+#define CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_TASK_QUEUE_H_
+#pragma once
+
+#include <map>
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "base/callback_forward.h"
+#include "base/memory/linked_ptr.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+class ExtensionHost;
+class Profile;
+
+// This class maintains a queue of tasks that should execute when an
+// extension's lazy background page is loaded. It is also in charge of loading
+// the page when the first task is queued.
+//
+// It is the consumer's responsibility to use this class when appropriate, i.e.
+// only with extensions that have not-yet-loaded lazy background pages.
+class LazyBackgroundTaskQueue : public content::NotificationObserver {
+ public:
+ typedef base::Callback<void(ExtensionHost*)> PendingTask;
+
+ explicit LazyBackgroundTaskQueue(Profile* profile);
+ virtual ~LazyBackgroundTaskQueue();
+
+ // Adds a task to the queue for a given extension. If this is the first
+ // task added for the extension, its lazy background page will be loaded.
+ void AddPendingTask(
+ Profile* profile,
+ const std::string& extension_id,
+ const PendingTask& task);
+
+ private:
+ // A map between an extension_id,Profile pair and the queue of tasks pending
+ // the load of its background page.
+ typedef std::string ExtensionID;
+ typedef std::pair<Profile*, ExtensionID> PendingTasksKey;
+ typedef std::vector<PendingTask> PendingTasksList;
+ typedef std::map<PendingTasksKey,
+ linked_ptr<PendingTasksList> > PendingTasksMap;
+
+ // content::NotificationObserver interface.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ // Called when a lazy background page has finished loading. All enqueued
+ // tasks are run in order.
+ void ProcessPendingTasks(ExtensionHost* host);
+
+ Profile* profile_;
+ content::NotificationRegistrar registrar_;
+ PendingTasksMap pending_tasks_;
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_TASK_QUEUE_H_