OLD | NEW |
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/event_router.h" | 5 #include "chrome/browser/extensions/event_router.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 const std::string& extension_id, | 58 const std::string& extension_id, |
59 const Version& old_version, | 59 const Version& old_version, |
60 bool chrome_updated) { | 60 bool chrome_updated) { |
61 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | 61 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
62 return; | 62 return; |
63 | 63 |
64 RuntimeEventRouter::DispatchOnInstalledEvent(profile, extension_id, | 64 RuntimeEventRouter::DispatchOnInstalledEvent(profile, extension_id, |
65 old_version, chrome_updated); | 65 old_version, chrome_updated); |
66 } | 66 } |
67 | 67 |
| 68 void DoNothing(extensions::ExtensionHost* host) {} |
| 69 |
68 } // namespace | 70 } // namespace |
69 | 71 |
70 struct EventRouter::ListenerProcess { | 72 struct EventRouter::ListenerProcess { |
71 content::RenderProcessHost* process; | 73 content::RenderProcessHost* process; |
72 std::string extension_id; | 74 std::string extension_id; |
73 | 75 |
74 ListenerProcess(content::RenderProcessHost* process, | 76 ListenerProcess(content::RenderProcessHost* process, |
75 const std::string& extension_id) | 77 const std::string& extension_id) |
76 : process(process), extension_id(extension_id) {} | 78 : process(process), extension_id(extension_id) {} |
77 | 79 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 EventRouter::EventRouter(Profile* profile, ExtensionPrefs* extension_prefs) | 123 EventRouter::EventRouter(Profile* profile, ExtensionPrefs* extension_prefs) |
122 : profile_(profile), | 124 : profile_(profile), |
123 listeners_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 125 listeners_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
124 dispatch_chrome_updated_event_(false) { | 126 dispatch_chrome_updated_event_(false) { |
125 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 127 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
126 content::NotificationService::AllSources()); | 128 content::NotificationService::AllSources()); |
127 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 129 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
128 content::NotificationService::AllSources()); | 130 content::NotificationService::AllSources()); |
129 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 131 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
130 content::Source<Profile>(profile_)); | 132 content::Source<Profile>(profile_)); |
| 133 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED, |
| 134 content::Source<Profile>(profile_)); |
131 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 135 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
132 content::Source<Profile>(profile_)); | 136 content::Source<Profile>(profile_)); |
133 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 137 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
134 content::Source<Profile>(profile_)); | 138 content::Source<Profile>(profile_)); |
135 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 139 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
136 content::Source<Profile>(profile_)); | 140 content::Source<Profile>(profile_)); |
137 | 141 |
138 // NULL in unit_tests. | 142 // NULL in unit_tests. |
139 if (extension_prefs) { | 143 if (extension_prefs) { |
140 // Check if registered events are up-to-date. We need to do this before | 144 // Check if registered events are up-to-date. We need to do this before |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 content::Source<content::RenderProcessHost>(source).ptr(); | 603 content::Source<content::RenderProcessHost>(source).ptr(); |
600 // Remove all event listeners associated with this renderer. | 604 // Remove all event listeners associated with this renderer. |
601 listeners_.RemoveListenersForProcess(renderer); | 605 listeners_.RemoveListenersForProcess(renderer); |
602 break; | 606 break; |
603 } | 607 } |
604 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 608 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
605 // We're done restarting Chrome after an update. | 609 // We're done restarting Chrome after an update. |
606 dispatch_chrome_updated_event_ = false; | 610 dispatch_chrome_updated_event_ = false; |
607 break; | 611 break; |
608 } | 612 } |
| 613 case chrome::NOTIFICATION_EXTENSION_ENABLED: { |
| 614 // If the extension has a lazy background page, make sure it gets loaded |
| 615 // to register the events the extension is interested in. |
| 616 const Extension* extension = |
| 617 content::Details<const Extension>(details).ptr(); |
| 618 if (extension->has_lazy_background_page()) { |
| 619 LazyBackgroundTaskQueue* queue = |
| 620 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); |
| 621 queue->AddPendingTask(profile_, extension->id(), |
| 622 base::Bind(&DoNothing)); |
| 623 } |
| 624 } |
609 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 625 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
610 // Add all registered lazy listeners to our cache. | 626 // Add all registered lazy listeners to our cache. |
611 const Extension* extension = | 627 const Extension* extension = |
612 content::Details<const Extension>(details).ptr(); | 628 content::Details<const Extension>(details).ptr(); |
613 ExtensionPrefs* prefs = | 629 ExtensionPrefs* prefs = |
614 profile_->GetExtensionService()->extension_prefs(); | 630 profile_->GetExtensionService()->extension_prefs(); |
615 std::set<std::string> registered_events = | 631 std::set<std::string> registered_events = |
616 prefs->GetRegisteredEvents(extension->id()); | 632 prefs->GetRegisteredEvents(extension->id()); |
617 listeners_.LoadUnfilteredLazyListeners(extension->id(), | 633 listeners_.LoadUnfilteredLazyListeners(extension->id(), |
618 registered_events); | 634 registered_events); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 info(info) {} | 705 info(info) {} |
690 | 706 |
691 Event::~Event() {} | 707 Event::~Event() {} |
692 | 708 |
693 EventListenerInfo::EventListenerInfo(const std::string& event_name, | 709 EventListenerInfo::EventListenerInfo(const std::string& event_name, |
694 const std::string& extension_id) | 710 const std::string& extension_id) |
695 : event_name(event_name), | 711 : event_name(event_name), |
696 extension_id(extension_id) {} | 712 extension_id(extension_id) {} |
697 | 713 |
698 } // namespace extensions | 714 } // namespace extensions |
OLD | NEW |