Chromium Code Reviews| 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; |