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 "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( | 43 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( |
44 Profile* profile, const Extension* extension) { | 44 Profile* profile, const Extension* extension) { |
45 DCHECK(extension); | 45 DCHECK(extension); |
46 if (extension->has_lazy_background_page()) { | 46 if (extension->has_lazy_background_page()) { |
47 ExtensionProcessManager* pm = | 47 ExtensionProcessManager* pm = |
48 ExtensionSystem::Get(profile)->process_manager(); | 48 ExtensionSystem::Get(profile)->process_manager(); |
49 ExtensionHost* background_host = | 49 ExtensionHost* background_host = |
50 pm->GetBackgroundHostForExtension(extension->id()); | 50 pm->GetBackgroundHostForExtension(extension->id()); |
51 if (!background_host || !background_host->did_stop_loading()) | 51 if (!background_host || !background_host->did_stop_loading()) |
52 return true; | 52 return true; |
| 53 if (pm->IsBackgroundHostClosing(extension->id())) |
| 54 pm->CancelSuspend(extension); |
53 } | 55 } |
54 | 56 |
55 return false; | 57 return false; |
56 } | 58 } |
57 | 59 |
58 void LazyBackgroundTaskQueue::AddPendingTask( | 60 void LazyBackgroundTaskQueue::AddPendingTask( |
59 Profile* profile, | 61 Profile* profile, |
60 const std::string& extension_id, | 62 const std::string& extension_id, |
61 const PendingTask& task) { | 63 const PendingTask& task) { |
62 PendingTasksList* tasks_list = NULL; | 64 PendingTasksList* tasks_list = NULL; |
(...skipping 22 matching lines...) Expand all Loading... |
85 // When the background host finishes closing, we will reload it. | 87 // When the background host finishes closing, we will reload it. |
86 pending_page_loads_.insert(PendingTasksKey(profile, extension_id)); | 88 pending_page_loads_.insert(PendingTasksKey(profile, extension_id)); |
87 return; | 89 return; |
88 } | 90 } |
89 | 91 |
90 const Extension* extension = | 92 const Extension* extension = |
91 ExtensionSystem::Get(profile)->extension_service()-> | 93 ExtensionSystem::Get(profile)->extension_service()-> |
92 extensions()->GetByID(extension_id); | 94 extensions()->GetByID(extension_id); |
93 if (extension) { | 95 if (extension) { |
94 DCHECK(extension->has_lazy_background_page()); | 96 DCHECK(extension->has_lazy_background_page()); |
95 pm->IncrementLazyKeepaliveCount( | 97 pm->IncrementLazyKeepaliveCount(extension); |
96 extension, ExtensionProcessManager::DONT_CANCEL_SUSPEND); | |
97 pm->CreateBackgroundHost(extension, extension->GetBackgroundURL()); | 98 pm->CreateBackgroundHost(extension, extension->GetBackgroundURL()); |
98 } | 99 } |
99 | 100 |
100 pending_page_loads_.erase(PendingTasksKey(profile, extension_id)); | 101 pending_page_loads_.erase(PendingTasksKey(profile, extension_id)); |
101 } | 102 } |
102 | 103 |
103 void LazyBackgroundTaskQueue::ProcessPendingTasks( | 104 void LazyBackgroundTaskQueue::ProcessPendingTasks( |
104 ExtensionHost* host, | 105 ExtensionHost* host, |
105 Profile* profile, | 106 Profile* profile, |
106 const Extension* extension) { | 107 const Extension* extension) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 183 } |
183 break; | 184 break; |
184 } | 185 } |
185 default: | 186 default: |
186 NOTREACHED(); | 187 NOTREACHED(); |
187 break; | 188 break; |
188 } | 189 } |
189 } | 190 } |
190 | 191 |
191 } // namespace extensions | 192 } // namespace extensions |
OLD | NEW |