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/lazy_background_task_queue.h" | 5 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/browser/extensions/process_map.h" | 12 #include "chrome/browser/extensions/process_map.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/extensions/background_info.h" | 15 #include "chrome/common/extensions/background_info.h" |
16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/extensions/extension_messages.h" | 17 #include "chrome/common/extensions/extension_messages.h" |
18 #include "chrome/common/view_type.h" | |
19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/site_instance.h" | 21 #include "content/public/browser/site_instance.h" |
23 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "extensions/common/view_type.h" | |
24 | 24 |
25 namespace extensions { | 25 namespace extensions { |
26 | 26 |
27 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue(Profile* profile) | 27 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue(Profile* profile) |
28 : profile_(profile) { | 28 : profile_(profile) { |
29 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 29 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
30 content::NotificationService::AllBrowserContextsAndSources()); | 30 content::NotificationService::AllBrowserContextsAndSources()); |
31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
32 content::NotificationService::AllBrowserContextsAndSources()); | 32 content::NotificationService::AllBrowserContextsAndSources()); |
33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 int type, | 122 int type, |
123 const content::NotificationSource& source, | 123 const content::NotificationSource& source, |
124 const content::NotificationDetails& details) { | 124 const content::NotificationDetails& details) { |
125 switch (type) { | 125 switch (type) { |
126 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | 126 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { |
127 // If an on-demand background page finished loading, dispatch queued up | 127 // If an on-demand background page finished loading, dispatch queued up |
128 // events for it. | 128 // events for it. |
129 ExtensionHost* host = | 129 ExtensionHost* host = |
130 content::Details<ExtensionHost>(details).ptr(); | 130 content::Details<ExtensionHost>(details).ptr(); |
131 if (host->extension_host_type() == | 131 if (host->extension_host_type() == |
132 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 132 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
Yoyo Zhou
2013/04/01 17:36:51
''
| |
133 CHECK(host->did_stop_loading()); | 133 CHECK(host->did_stop_loading()); |
134 ProcessPendingTasks(host, host->profile(), host->extension()); | 134 ProcessPendingTasks(host, host->profile(), host->extension()); |
135 } | 135 } |
136 break; | 136 break; |
137 } | 137 } |
138 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 138 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
139 // Notify consumers about the load failure when the background host dies. | 139 // Notify consumers about the load failure when the background host dies. |
140 // This can happen if the extension crashes. This is not strictly | 140 // This can happen if the extension crashes. This is not strictly |
141 // necessary, since we also unload the extension in that case (which | 141 // necessary, since we also unload the extension in that case (which |
142 // dispatches the tasks below), but is a good extra precaution. | 142 // dispatches the tasks below), but is a good extra precaution. |
143 Profile* profile = content::Source<Profile>(source).ptr(); | 143 Profile* profile = content::Source<Profile>(source).ptr(); |
144 ExtensionHost* host = | 144 ExtensionHost* host = |
145 content::Details<ExtensionHost>(details).ptr(); | 145 content::Details<ExtensionHost>(details).ptr(); |
146 if (host->extension_host_type() == | 146 if (host->extension_host_type() == |
147 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 147 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
148 ProcessPendingTasks(NULL, profile, host->extension()); | 148 ProcessPendingTasks(NULL, profile, host->extension()); |
149 } | 149 } |
150 break; | 150 break; |
151 } | 151 } |
152 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 152 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
153 // Notify consumers that the page failed to load. | 153 // Notify consumers that the page failed to load. |
154 Profile* profile = content::Source<Profile>(source).ptr(); | 154 Profile* profile = content::Source<Profile>(source).ptr(); |
155 UnloadedExtensionInfo* unloaded = | 155 UnloadedExtensionInfo* unloaded = |
156 content::Details<UnloadedExtensionInfo>(details).ptr(); | 156 content::Details<UnloadedExtensionInfo>(details).ptr(); |
157 ProcessPendingTasks(NULL, profile, unloaded->extension); | 157 ProcessPendingTasks(NULL, profile, unloaded->extension); |
158 if (profile->HasOffTheRecordProfile()) { | 158 if (profile->HasOffTheRecordProfile()) { |
159 ProcessPendingTasks(NULL, profile->GetOffTheRecordProfile(), | 159 ProcessPendingTasks(NULL, profile->GetOffTheRecordProfile(), |
160 unloaded->extension); | 160 unloaded->extension); |
161 } | 161 } |
162 break; | 162 break; |
163 } | 163 } |
164 default: | 164 default: |
165 NOTREACHED(); | 165 NOTREACHED(); |
166 break; | 166 break; |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 } // namespace extensions | 170 } // namespace extensions |
OLD | NEW |