Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(680)

Unified Diff: chrome/browser/extensions/api/runtime/runtime_api.cc

Issue 10828218: Add chrome.runtime.onStartup, which is fired on browser start. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm debug logs Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/runtime/runtime_api.h ('k') | chrome/browser/extensions/event_router.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/runtime/runtime_api.cc
diff --git a/chrome/browser/extensions/api/runtime/runtime_api.cc b/chrome/browser/extensions/api/runtime/runtime_api.cc
index 47b8f571b5716a4b63e9fa22d4a19dcfd32af1ba..39d30a9b02163c44d5f4678163e64defd80afc54 100644
--- a/chrome/browser/extensions/api/runtime/runtime_api.cc
+++ b/chrome/browser/extensions/api/runtime/runtime_api.cc
@@ -4,24 +4,66 @@
#include "chrome/browser/extensions/api/runtime/runtime_api.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/event_router.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_process_manager.h"
+#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/lazy_background_task_queue.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/extensions/extension.h"
#include "googleurl/src/gurl.h"
+namespace extensions {
+
namespace {
+const char kOnStartupEvent[] = "runtime.onStartup";
const char kOnInstalledEvent[] = "runtime.onInstalled";
const char kNoBackgroundPageError[] = "You do not have a background page.";
const char kPageLoadError[] = "Background page failed to load.";
+static void DispatchOnStartupEventImpl(
+ Profile* profile,
+ const std::string& extension_id,
+ bool first_call,
+ ExtensionHost* unused) {
+ if (g_browser_process->IsShuttingDown() ||
+ !g_browser_process->profile_manager()->IsValidProfile(profile))
+ return;
+ ExtensionSystem* system = ExtensionSystem::Get(profile);
+ if (!system)
+ return;
+
+ // If this is a persistent background page, we want to wait for it to load
+ // (it might not be ready, since this is startup). But only enqueue once.
+ // If it fails to load the first time, don't bother trying again.
+ const Extension* extension =
+ system->extension_service()->extensions()->GetByID(extension_id);
+ if (extension && extension->has_persistent_background_page() && first_call &&
+ system->lazy_background_task_queue()->
+ ShouldEnqueueTask(profile, extension)) {
+ system->lazy_background_task_queue()->AddPendingTask(
+ profile, extension_id,
+ base::Bind(&DispatchOnStartupEventImpl,
+ profile, extension_id, false));
+ return;
+ }
+
+ scoped_ptr<ListValue> event_args(new ListValue());
+ system->event_router()->DispatchEventToExtension(
+ extension_id, kOnStartupEvent, event_args.Pass(), NULL, GURL());
}
-namespace extensions {
+} // namespace
+
+// static
+void RuntimeEventRouter::DispatchOnStartupEvent(
+ Profile* profile, const std::string& extension_id) {
+ DispatchOnStartupEventImpl(profile, extension_id, true, NULL);
+}
// static
void RuntimeEventRouter::DispatchOnInstalledEvent(
« no previous file with comments | « chrome/browser/extensions/api/runtime/runtime_api.h ('k') | chrome/browser/extensions/event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698