Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: extensions/browser/lazy_background_task_queue.cc

Issue 62713003: Move ExtensionProcessManager to src/extensions, part 4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « extensions/browser/DEPS ('k') | extensions/browser/lazy_background_task_queue_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.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"
11 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/extensions/process_map.h" 12 #include "chrome/browser/extensions/process_map.h"
14 #include "chrome/common/extensions/background_info.h" 13 #include "chrome/common/extensions/background_info.h"
15 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_messages.h" 15 #include "chrome/common/extensions/extension_messages.h"
17 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
20 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/site_instance.h" 20 #include "content/public/browser/site_instance.h"
22 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
23 #include "extensions/browser/extensions_browser_client.h" 22 #include "extensions/browser/extensions_browser_client.h"
23 #include "extensions/browser/process_manager.h"
24 #include "extensions/common/view_type.h" 24 #include "extensions/common/view_type.h"
25 25
26 namespace extensions { 26 namespace extensions {
27 27
28 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue( 28 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue(
29 content::BrowserContext* browser_context) 29 content::BrowserContext* browser_context)
30 : browser_context_(browser_context) { 30 : browser_context_(browser_context) {
31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
32 content::NotificationService::AllBrowserContextsAndSources()); 32 content::NotificationService::AllBrowserContextsAndSources());
33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
34 content::NotificationService::AllBrowserContextsAndSources()); 34 content::NotificationService::AllBrowserContextsAndSources());
35 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 35 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
36 content::Source<content::BrowserContext>(browser_context)); 36 content::Source<content::BrowserContext>(browser_context));
37 } 37 }
38 38
39 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() { 39 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() {
40 } 40 }
41 41
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 DCHECK(extension); 45 DCHECK(extension);
46 if (BackgroundInfo::HasBackgroundPage(extension)) { 46 if (BackgroundInfo::HasBackgroundPage(extension)) {
47 ExtensionProcessManager* pm = ExtensionSystem::GetForBrowserContext( 47 ProcessManager* pm = ExtensionSystem::GetForBrowserContext(
48 browser_context)->process_manager(); 48 browser_context)->process_manager();
49 DCHECK(pm); 49 DCHECK(pm);
50 ExtensionHost* background_host = 50 ExtensionHost* background_host =
51 pm->GetBackgroundHostForExtension(extension->id()); 51 pm->GetBackgroundHostForExtension(extension->id());
52 if (!background_host || !background_host->did_stop_loading()) 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
(...skipping 16 matching lines...) Expand all
74 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list); 74 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list);
75 75
76 ExtensionService* extension_service = ExtensionSystem::GetForBrowserContext( 76 ExtensionService* extension_service = ExtensionSystem::GetForBrowserContext(
77 browser_context)->extension_service(); 77 browser_context)->extension_service();
78 DCHECK(extension_service); 78 DCHECK(extension_service);
79 const Extension* extension = 79 const Extension* extension =
80 extension_service->extensions()->GetByID(extension_id); 80 extension_service->extensions()->GetByID(extension_id);
81 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension)) { 81 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension)) {
82 // If this is the first enqueued task, and we're not waiting for the 82 // If this is the first enqueued task, and we're not waiting for the
83 // background page to unload, ensure the background page is loaded. 83 // background page to unload, ensure the background page is loaded.
84 ExtensionProcessManager* pm = ExtensionSystem::GetForBrowserContext( 84 ProcessManager* pm = ExtensionSystem::GetForBrowserContext(
85 browser_context)->process_manager(); 85 browser_context)->process_manager();
86 pm->IncrementLazyKeepaliveCount(extension); 86 pm->IncrementLazyKeepaliveCount(extension);
87 // Creating the background host may fail, e.g. if |profile| is incognito 87 // Creating the background host may fail, e.g. if |profile| is incognito
88 // but the extension isn't enabled in incognito mode. 88 // but the extension isn't enabled in incognito mode.
89 if (!pm->CreateBackgroundHost( 89 if (!pm->CreateBackgroundHost(
90 extension, BackgroundInfo::GetBackgroundURL(extension))) { 90 extension, BackgroundInfo::GetBackgroundURL(extension))) {
91 task.Run(NULL); 91 task.Run(NULL);
92 return; 92 return;
93 } 93 }
94 } 94 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 182 }
183 break; 183 break;
184 } 184 }
185 default: 185 default:
186 NOTREACHED(); 186 NOTREACHED();
187 break; 187 break;
188 } 188 }
189 } 189 }
190 190
191 } // namespace extensions 191 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/DEPS ('k') | extensions/browser/lazy_background_task_queue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698