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

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: 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
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..2cd897f357f206e062428b9a7d9f6d5763d9f7b1 100644
--- a/chrome/browser/extensions/api/runtime/runtime_api.cc
+++ b/chrome/browser/extensions/api/runtime/runtime_api.cc
@@ -4,28 +4,70 @@
#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 should_enqueue,
+ ExtensionHost* unused) {
+ if (!g_browser_process->profile_manager()->IsValidProfile(profile))
+ return;
+ ExtensionSystem* system = ExtensionSystem::Get(profile);
+ if (!system)
+ return;
+
+ // Only check if we should enqueue the first time. If the background page
+ // fails to load, we don't want to re-enqueue the task.
+ const Extension* extension =
+ system->extension_service()->extensions()->GetByID(extension_id);
+ if (extension && should_enqueue &&
+ 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(
Profile* profile, const std::string& extension_id) {
+ if (!g_browser_process->profile_manager()->IsValidProfile(profile))
Yoyo Zhou 2012/08/09 00:49:17 What is this for?
Matt Perry 2012/08/15 20:35:45 This method is called via a PostTask, so the profi
+ return;
ExtensionSystem* system = ExtensionSystem::Get(profile);
if (!system)
return;

Powered by Google App Engine
This is Rietveld 408576698