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

Side by Side Diff: chrome/browser/extensions/api/runtime/runtime_api.cc

Issue 10836317: Revert 152017 - 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 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"
8 #include "chrome/browser/extensions/event_router.h" 7 #include "chrome/browser/extensions/event_router.h"
9 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_process_manager.h" 9 #include "chrome/browser/extensions/extension_process_manager.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/extensions/lazy_background_task_queue.h" 11 #include "chrome/browser/extensions/lazy_background_task_queue.h"
14 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
17 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
18 15
19 namespace extensions {
20
21 namespace { 16 namespace {
22 17
23 const char kOnStartupEvent[] = "runtime.onStartup";
24 const char kOnInstalledEvent[] = "runtime.onInstalled"; 18 const char kOnInstalledEvent[] = "runtime.onInstalled";
25 const char kNoBackgroundPageError[] = "You do not have a background page."; 19 const char kNoBackgroundPageError[] = "You do not have a background page.";
26 const char kPageLoadError[] = "Background page failed to load."; 20 const char kPageLoadError[] = "Background page failed to load.";
27 21
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());
58 } 22 }
59 23
60 } // namespace 24 namespace extensions {
61
62 // static
63 void RuntimeEventRouter::DispatchOnStartupEvent(
64 Profile* profile, const std::string& extension_id) {
65 DispatchOnStartupEventImpl(profile, extension_id, true, NULL);
66 }
67 25
68 // static 26 // static
69 void RuntimeEventRouter::DispatchOnInstalledEvent( 27 void RuntimeEventRouter::DispatchOnInstalledEvent(
70 Profile* profile, const std::string& extension_id) { 28 Profile* profile, const std::string& extension_id) {
71 ExtensionSystem* system = ExtensionSystem::Get(profile); 29 ExtensionSystem* system = ExtensionSystem::Get(profile);
72 if (!system) 30 if (!system)
73 return; 31 return;
74 32
75 // Special case: normally, extensions add their own lazy event listeners. 33 // Special case: normally, extensions add their own lazy event listeners.
76 // However, since the extension has just been installed, it hasn't had a 34 // However, since the extension has just been installed, it hasn't had a
(...skipping 29 matching lines...) Expand all
106 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) { 64 void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) {
107 if (host) { 65 if (host) {
108 SendResponse(true); 66 SendResponse(true);
109 } else { 67 } else {
110 error_ = kPageLoadError; 68 error_ = kPageLoadError;
111 SendResponse(false); 69 SendResponse(false);
112 } 70 }
113 } 71 }
114 72
115 } // namespace extensions 73 } // 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