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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/runtime/runtime_api.h" 5 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
6 6
7 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/extensions/event_router.h" 8 #include "chrome/browser/extensions/event_router.h"
8 #include "chrome/browser/extensions/extension_host.h" 9 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extension_process_manager.h" 10 #include "chrome/browser/extensions/extension_process_manager.h"
11 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_system.h" 12 #include "chrome/browser/extensions/extension_system.h"
11 #include "chrome/browser/extensions/lazy_background_task_queue.h" 13 #include "chrome/browser/extensions/lazy_background_task_queue.h"
12 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
14 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
15 18
19 namespace extensions {
20
16 namespace { 21 namespace {
17 22
23 const char kOnStartupEvent[] = "runtime.onStartup";
18 const char kOnInstalledEvent[] = "runtime.onInstalled"; 24 const char kOnInstalledEvent[] = "runtime.onInstalled";
19 const char kNoBackgroundPageError[] = "You do not have a background page."; 25 const char kNoBackgroundPageError[] = "You do not have a background page.";
20 const char kPageLoadError[] = "Background page failed to load."; 26 const char kPageLoadError[] = "Background page failed to load.";
21 27
28 static void DispatchOnStartupEventImpl(
29 Profile* profile,
30 const std::string& extension_id,
31 bool first_call,
32 ExtensionHost* unused) {
33 if (g_browser_process->IsShuttingDown() ||
34 !g_browser_process->profile_manager()->IsValidProfile(profile))
35 return;
36 ExtensionSystem* system = ExtensionSystem::Get(profile);
37 if (!system)
38 return;
39
40 // If this is a persistent background page, we want to wait for it to load
41 // (it might not be ready, since this is startup). But only enqueue once.
42 // If it fails to load the first time, don't bother trying again.
43 const Extension* extension =
44 system->extension_service()->extensions()->GetByID(extension_id);
45 if (extension && extension->has_persistent_background_page() && first_call &&
46 system->lazy_background_task_queue()->
47 ShouldEnqueueTask(profile, extension)) {
48 system->lazy_background_task_queue()->AddPendingTask(
49 profile, extension_id,
50 base::Bind(&DispatchOnStartupEventImpl,
51 profile, extension_id, false));
52 return;
53 }
54
55 scoped_ptr<ListValue> event_args(new ListValue());
56 system->event_router()->DispatchEventToExtension(
57 extension_id, kOnStartupEvent, event_args.Pass(), NULL, GURL());
22 } 58 }
23 59
24 namespace extensions { 60 } // namespace
61
62 // static
63 void RuntimeEventRouter::DispatchOnStartupEvent(
64 Profile* profile, const std::string& extension_id) {
65 DispatchOnStartupEventImpl(profile, extension_id, true, NULL);
66 }
25 67
26 // static 68 // static
27 void RuntimeEventRouter::DispatchOnInstalledEvent( 69 void RuntimeEventRouter::DispatchOnInstalledEvent(
28 Profile* profile, const std::string& extension_id) { 70 Profile* profile, const std::string& extension_id) {
29 ExtensionSystem* system = ExtensionSystem::Get(profile); 71 ExtensionSystem* system = ExtensionSystem::Get(profile);
30 if (!system) 72 if (!system)
31 return; 73 return;
32 74
33 // Special case: normally, extensions add their own lazy event listeners. 75 // Special case: normally, extensions add their own lazy event listeners.
34 // However, since the extension has just been installed, it hasn't had a 76 // However, since the extension has just been installed, it hasn't had a
(...skipping 29 matching lines...) Expand all
64 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) { 106 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) {
65 if (host) { 107 if (host) {
66 SendResponse(true); 108 SendResponse(true);
67 } else { 109 } else {
68 error_ = kPageLoadError; 110 error_ = kPageLoadError;
69 SendResponse(false); 111 SendResponse(false);
70 } 112 }
71 } 113 }
72 114
73 } // namespace extensions 115 } // namespace extensions
OLDNEW
« 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