| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 59   } | 59   } | 
| 60 | 60 | 
| 61   return false; | 61   return false; | 
| 62 } | 62 } | 
| 63 | 63 | 
| 64 void LazyBackgroundTaskQueue::AddPendingTask( | 64 void LazyBackgroundTaskQueue::AddPendingTask( | 
| 65     content::BrowserContext* browser_context, | 65     content::BrowserContext* browser_context, | 
| 66     const std::string& extension_id, | 66     const std::string& extension_id, | 
| 67     const PendingTask& task) { | 67     const PendingTask& task) { | 
| 68   if (ExtensionsBrowserClient::Get()->IsShuttingDown()) { | 68   if (ExtensionsBrowserClient::Get()->IsShuttingDown()) { | 
| 69     task.Run(NULL); | 69     task.Run(nullptr); | 
| 70     return; | 70     return; | 
| 71   } | 71   } | 
| 72   PendingTasksList* tasks_list = NULL; | 72   PendingTasksList* tasks_list = nullptr; | 
| 73   PendingTasksKey key(browser_context, extension_id); | 73   PendingTasksKey key(browser_context, extension_id); | 
| 74   PendingTasksMap::iterator it = pending_tasks_.find(key); | 74   PendingTasksMap::iterator it = pending_tasks_.find(key); | 
| 75   if (it == pending_tasks_.end()) { | 75   if (it == pending_tasks_.end()) { | 
| 76     tasks_list = new PendingTasksList(); | 76     tasks_list = new PendingTasksList(); | 
| 77     pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list); | 77     pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list); | 
| 78 | 78 | 
| 79     const Extension* extension = | 79     const Extension* extension = | 
| 80         ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID( | 80         ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID( | 
| 81             extension_id); | 81             extension_id); | 
| 82     if (extension && BackgroundInfo::HasLazyBackgroundPage(extension)) { | 82     if (extension && BackgroundInfo::HasLazyBackgroundPage(extension)) { | 
| 83       // If this is the first enqueued task, and we're not waiting for the | 83       // If this is the first enqueued task, and we're not waiting for the | 
| 84       // background page to unload, ensure the background page is loaded. | 84       // background page to unload, ensure the background page is loaded. | 
| 85       ProcessManager* pm = ExtensionSystem::Get( | 85       ProcessManager* pm = ExtensionSystem::Get( | 
| 86           browser_context)->process_manager(); | 86           browser_context)->process_manager(); | 
| 87       pm->IncrementLazyKeepaliveCount(extension); | 87       pm->IncrementLazyKeepaliveCount(extension); | 
| 88       // Creating the background host may fail, e.g. if |profile| is incognito | 88       // Creating the background host may fail, e.g. if |profile| is incognito | 
| 89       // but the extension isn't enabled in incognito mode. | 89       // but the extension isn't enabled in incognito mode. | 
| 90       if (!pm->CreateBackgroundHost( | 90       if (!pm->CreateBackgroundHost( | 
| 91             extension, BackgroundInfo::GetBackgroundURL(extension))) { | 91             extension, BackgroundInfo::GetBackgroundURL(extension))) { | 
| 92         task.Run(NULL); | 92         task.Run(nullptr); | 
| 93         return; | 93         return; | 
| 94       } | 94       } | 
| 95     } | 95     } | 
| 96   } else { | 96   } else { | 
| 97     tasks_list = it->second.get(); | 97     tasks_list = it->second.get(); | 
| 98   } | 98   } | 
| 99 | 99 | 
| 100   tasks_list->push_back(task); | 100   tasks_list->push_back(task); | 
| 101 } | 101 } | 
| 102 | 102 | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 154     case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 154     case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 
| 155       // Notify consumers about the load failure when the background host dies. | 155       // Notify consumers about the load failure when the background host dies. | 
| 156       // This can happen if the extension crashes. This is not strictly | 156       // This can happen if the extension crashes. This is not strictly | 
| 157       // necessary, since we also unload the extension in that case (which | 157       // necessary, since we also unload the extension in that case (which | 
| 158       // dispatches the tasks below), but is a good extra precaution. | 158       // dispatches the tasks below), but is a good extra precaution. | 
| 159       content::BrowserContext* browser_context = | 159       content::BrowserContext* browser_context = | 
| 160           content::Source<content::BrowserContext>(source).ptr(); | 160           content::Source<content::BrowserContext>(source).ptr(); | 
| 161       ExtensionHost* host = | 161       ExtensionHost* host = | 
| 162            content::Details<ExtensionHost>(details).ptr(); | 162            content::Details<ExtensionHost>(details).ptr(); | 
| 163       if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 163       if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 
| 164         ProcessPendingTasks(NULL, browser_context, host->extension()); | 164         ProcessPendingTasks(nullptr, browser_context, host->extension()); | 
| 165       } | 165       } | 
| 166       break; | 166       break; | 
| 167     } | 167     } | 
| 168     default: | 168     default: | 
| 169       NOTREACHED(); | 169       NOTREACHED(); | 
| 170       break; | 170       break; | 
| 171   } | 171   } | 
| 172 } | 172 } | 
| 173 | 173 | 
| 174 void LazyBackgroundTaskQueue::OnExtensionUnloaded( | 174 void LazyBackgroundTaskQueue::OnExtensionUnloaded( | 
| 175     content::BrowserContext* browser_context, | 175     content::BrowserContext* browser_context, | 
| 176     const Extension* extension, | 176     const Extension* extension, | 
| 177     UnloadedExtensionInfo::Reason reason) { | 177     UnloadedExtensionInfo::Reason reason) { | 
| 178   // Notify consumers that the page failed to load. | 178   // Notify consumers that the page failed to load. | 
| 179   ProcessPendingTasks(NULL, browser_context, extension); | 179   ProcessPendingTasks(nullptr, browser_context, extension); | 
| 180   // If this extension is also running in an off-the-record context, notify that | 180   // If this extension is also running in an off-the-record context, notify that | 
| 181   // task queue as well. | 181   // task queue as well. | 
| 182   ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); | 182   ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); | 
| 183   if (browser_client->HasOffTheRecordContext(browser_context)) { | 183   if (browser_client->HasOffTheRecordContext(browser_context)) { | 
| 184     ProcessPendingTasks(NULL, | 184     ProcessPendingTasks(nullptr, | 
| 185                         browser_client->GetOffTheRecordContext(browser_context), | 185                         browser_client->GetOffTheRecordContext(browser_context), | 
| 186                         extension); | 186                         extension); | 
| 187   } | 187   } | 
| 188 } | 188 } | 
| 189 | 189 | 
| 190 }  // namespace extensions | 190 }  // namespace extensions | 
| OLD | NEW | 
|---|