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

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

Issue 671763002: Extract ProcessManager from ExtensionSystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 6 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
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 "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"
11 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/site_instance.h" 12 #include "content/public/browser/site_instance.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "extensions/browser/extension_host.h" 14 #include "extensions/browser/extension_host.h"
15 #include "extensions/browser/extension_registry.h" 15 #include "extensions/browser/extension_registry.h"
16 #include "extensions/browser/extension_system.h"
17 #include "extensions/browser/extensions_browser_client.h" 16 #include "extensions/browser/extensions_browser_client.h"
18 #include "extensions/browser/notification_types.h" 17 #include "extensions/browser/notification_types.h"
19 #include "extensions/browser/process_manager.h" 18 #include "extensions/browser/process_manager.h"
20 #include "extensions/browser/process_map.h" 19 #include "extensions/browser/process_map.h"
21 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
22 #include "extensions/common/manifest_handlers/background_info.h" 21 #include "extensions/common/manifest_handlers/background_info.h"
23 #include "extensions/common/view_type.h" 22 #include "extensions/common/view_type.h"
24 23
25 namespace extensions { 24 namespace extensions {
26 25
(...skipping 13 matching lines...) Expand all
40 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() { 39 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() {
41 } 40 }
42 41
43 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( 42 bool LazyBackgroundTaskQueue::ShouldEnqueueTask(
44 content::BrowserContext* browser_context, 43 content::BrowserContext* browser_context,
45 const Extension* extension) { 44 const Extension* extension) {
46 // 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
47 // extension tasks. 46 // extension tasks.
48 DCHECK(extension); 47 DCHECK(extension);
49 if (BackgroundInfo::HasBackgroundPage(extension)) { 48 if (BackgroundInfo::HasBackgroundPage(extension)) {
50 ProcessManager* pm = ExtensionSystem::Get( 49 ProcessManager* pm = ProcessManager::Get(browser_context);
51 browser_context)->process_manager();
52 DCHECK(pm);
53 ExtensionHost* background_host = 50 ExtensionHost* background_host =
54 pm->GetBackgroundHostForExtension(extension->id()); 51 pm->GetBackgroundHostForExtension(extension->id());
55 if (!background_host || !background_host->did_stop_loading()) 52 if (!background_host || !background_host->did_stop_loading())
56 return true; 53 return true;
57 if (pm->IsBackgroundHostClosing(extension->id())) 54 if (pm->IsBackgroundHostClosing(extension->id()))
58 pm->CancelSuspend(extension); 55 pm->CancelSuspend(extension);
59 } 56 }
60 57
61 return false; 58 return false;
62 } 59 }
(...skipping 12 matching lines...) Expand all
75 if (it == pending_tasks_.end()) { 72 if (it == pending_tasks_.end()) {
76 tasks_list = new PendingTasksList(); 73 tasks_list = new PendingTasksList();
77 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list); 74 pending_tasks_[key] = linked_ptr<PendingTasksList>(tasks_list);
78 75
79 const Extension* extension = 76 const Extension* extension =
80 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID( 77 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID(
81 extension_id); 78 extension_id);
82 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension)) { 79 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension)) {
83 // If this is the first enqueued task, and we're not waiting for the 80 // 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. 81 // background page to unload, ensure the background page is loaded.
85 ProcessManager* pm = ExtensionSystem::Get( 82 ProcessManager* pm = ProcessManager::Get(browser_context);
86 browser_context)->process_manager();
87 pm->IncrementLazyKeepaliveCount(extension); 83 pm->IncrementLazyKeepaliveCount(extension);
88 // Creating the background host may fail, e.g. if |profile| is incognito 84 // Creating the background host may fail, e.g. if |profile| is incognito
89 // but the extension isn't enabled in incognito mode. 85 // but the extension isn't enabled in incognito mode.
90 if (!pm->CreateBackgroundHost( 86 if (!pm->CreateBackgroundHost(
91 extension, BackgroundInfo::GetBackgroundURL(extension))) { 87 extension, BackgroundInfo::GetBackgroundURL(extension))) {
92 task.Run(NULL); 88 task.Run(NULL);
93 return; 89 return;
94 } 90 }
95 } 91 }
96 } else { 92 } else {
(...skipping 26 matching lines...) Expand all
123 for (PendingTasksList::const_iterator it = tasks.begin(); 119 for (PendingTasksList::const_iterator it = tasks.begin();
124 it != tasks.end(); ++it) { 120 it != tasks.end(); ++it) {
125 it->Run(host); 121 it->Run(host);
126 } 122 }
127 123
128 pending_tasks_.erase(key); 124 pending_tasks_.erase(key);
129 125
130 // Balance the keepalive in AddPendingTask. Note we don't do this on a 126 // Balance the keepalive in AddPendingTask. Note we don't do this on a
131 // failure to load, because the keepalive count is reset in that case. 127 // failure to load, because the keepalive count is reset in that case.
132 if (host && BackgroundInfo::HasLazyBackgroundPage(extension)) { 128 if (host && BackgroundInfo::HasLazyBackgroundPage(extension)) {
133 ExtensionSystem::Get(browser_context)->process_manager()-> 129 ProcessManager::Get(browser_context)
134 DecrementLazyKeepaliveCount(extension); 130 ->DecrementLazyKeepaliveCount(extension);
135 } 131 }
136 } 132 }
137 133
138 void LazyBackgroundTaskQueue::Observe( 134 void LazyBackgroundTaskQueue::Observe(
139 int type, 135 int type,
140 const content::NotificationSource& source, 136 const content::NotificationSource& source,
141 const content::NotificationDetails& details) { 137 const content::NotificationDetails& details) {
142 switch (type) { 138 switch (type) {
143 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { 139 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
144 // If an on-demand background page finished loading, dispatch queued up 140 // If an on-demand background page finished loading, dispatch queued up
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // task queue as well. 177 // task queue as well.
182 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); 178 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get();
183 if (browser_client->HasOffTheRecordContext(browser_context)) { 179 if (browser_client->HasOffTheRecordContext(browser_context)) {
184 ProcessPendingTasks(NULL, 180 ProcessPendingTasks(NULL,
185 browser_client->GetOffTheRecordContext(browser_context), 181 browser_client->GetOffTheRecordContext(browser_context),
186 extension); 182 extension);
187 } 183 }
188 } 184 }
189 185
190 } // namespace extensions 186 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698