OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/lazy_background_task_queue.h" | 5 #include "extensions/browser/lazy_background_task_queue.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( | 42 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( |
43 content::BrowserContext* browser_context, | 43 content::BrowserContext* browser_context, |
44 const Extension* extension) { | 44 const Extension* extension) { |
45 // Note: browser_context may not be the same as browser_context_ for incognito | 45 // Note: browser_context may not be the same as browser_context_ for incognito |
46 // extension tasks. | 46 // extension tasks. |
47 DCHECK(extension); | 47 DCHECK(extension); |
48 if (BackgroundInfo::HasBackgroundPage(extension)) { | 48 if (BackgroundInfo::HasBackgroundPage(extension)) { |
49 ProcessManager* pm = ProcessManager::Get(browser_context); | 49 ProcessManager* pm = ProcessManager::Get(browser_context); |
50 ExtensionHost* background_host = | 50 ExtensionHost* background_host = |
51 pm->GetBackgroundHostForExtension(extension->id()); | 51 pm->GetBackgroundHostForExtension(extension->id()); |
52 if (!background_host || !background_host->has_loaded_once()) | 52 if (!background_host || !background_host->did_stop_loading()) |
53 return true; | 53 return true; |
54 if (pm->IsBackgroundHostClosing(extension->id())) | 54 if (pm->IsBackgroundHostClosing(extension->id())) |
55 pm->CancelSuspend(extension); | 55 pm->CancelSuspend(extension); |
56 } | 56 } |
57 | 57 |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 void LazyBackgroundTaskQueue::AddPendingTask( | 61 void LazyBackgroundTaskQueue::AddPendingTask( |
62 content::BrowserContext* browser_context, | 62 content::BrowserContext* browser_context, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 int type, | 135 int type, |
136 const content::NotificationSource& source, | 136 const content::NotificationSource& source, |
137 const content::NotificationDetails& details) { | 137 const content::NotificationDetails& details) { |
138 switch (type) { | 138 switch (type) { |
139 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | 139 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { |
140 // If an on-demand background page finished loading, dispatch queued up | 140 // If an on-demand background page finished loading, dispatch queued up |
141 // events for it. | 141 // events for it. |
142 ExtensionHost* host = | 142 ExtensionHost* host = |
143 content::Details<ExtensionHost>(details).ptr(); | 143 content::Details<ExtensionHost>(details).ptr(); |
144 if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 144 if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
145 CHECK(host->has_loaded_once()); | 145 CHECK(host->did_stop_loading()); |
146 ProcessPendingTasks(host, host->browser_context(), host->extension()); | 146 ProcessPendingTasks(host, host->browser_context(), host->extension()); |
147 } | 147 } |
148 break; | 148 break; |
149 } | 149 } |
150 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 150 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
151 // Notify consumers about the load failure when the background host dies. | 151 // Notify consumers about the load failure when the background host dies. |
152 // This can happen if the extension crashes. This is not strictly | 152 // This can happen if the extension crashes. This is not strictly |
153 // necessary, since we also unload the extension in that case (which | 153 // necessary, since we also unload the extension in that case (which |
154 // dispatches the tasks below), but is a good extra precaution. | 154 // dispatches the tasks below), but is a good extra precaution. |
155 content::BrowserContext* browser_context = | 155 content::BrowserContext* browser_context = |
(...skipping 21 matching lines...) Expand all Loading... |
177 // task queue as well. | 177 // task queue as well. |
178 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); | 178 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); |
179 if (browser_client->HasOffTheRecordContext(browser_context)) { | 179 if (browser_client->HasOffTheRecordContext(browser_context)) { |
180 ProcessPendingTasks(NULL, | 180 ProcessPendingTasks(NULL, |
181 browser_client->GetOffTheRecordContext(browser_context), | 181 browser_client->GetOffTheRecordContext(browser_context), |
182 extension); | 182 extension); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 } // namespace extensions | 186 } // namespace extensions |
OLD | NEW |