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

Side by Side Diff: chrome/browser/extensions/extension_process_manager.cc

Issue 7672009: Lazy creating of background pages --enable-lazy-background-pages) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix memory leak Created 9 years, 3 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/command_line.h"
5 #include "chrome/browser/extensions/extension_process_manager.h" 6 #include "chrome/browser/extensions/extension_process_manager.h"
6 7
7 #include "chrome/browser/ui/browser_window.h" 8 #include "chrome/browser/ui/browser_window.h"
8 #include "content/browser/browsing_instance.h" 9 #include "content/browser/browsing_instance.h"
9 #if defined(OS_MACOSX) 10 #if defined(OS_MACOSX)
10 #include "chrome/browser/extensions/extension_host_mac.h" 11 #include "chrome/browser/extensions/extension_host_mac.h"
11 #endif 12 #endif
12 #include "chrome/browser/extensions/extension_host.h" 13 #include "chrome/browser/extensions/extension_host.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
19 #include "content/browser/site_instance.h" 21 #include "content/browser/site_instance.h"
20 #include "content/browser/tab_contents/tab_contents.h" 22 #include "content/browser/tab_contents/tab_contents.h"
21 #include "content/common/notification_service.h" 23 #include "content/common/notification_service.h"
22 24
23 namespace { 25 namespace {
24 26
25 // Incognito profiles use this process manager. It is mostly a shim that decides 27 // Incognito profiles use this process manager. It is mostly a shim that decides
26 // whether to fall back on the original profile's ExtensionProcessManager based 28 // whether to fall back on the original profile's ExtensionProcessManager based
(...skipping 21 matching lines...) Expand all
48 // Returns the extension for an URL, which can either be a chrome-extension 50 // Returns the extension for an URL, which can either be a chrome-extension
49 // URL or a web app URL. 51 // URL or a web app URL.
50 const Extension* GetExtensionOrAppByURL(const GURL& url); 52 const Extension* GetExtensionOrAppByURL(const GURL& url);
51 53
52 // Returns true if the extension is allowed to run in incognito mode. 54 // Returns true if the extension is allowed to run in incognito mode.
53 bool IsIncognitoEnabled(const Extension* extension); 55 bool IsIncognitoEnabled(const Extension* extension);
54 56
55 ExtensionProcessManager* original_manager_; 57 ExtensionProcessManager* original_manager_;
56 }; 58 };
57 59
58 static void CreateBackgroundHost( 60 static void CreateBackgroundHostForExtensionLoad(
59 ExtensionProcessManager* manager, const Extension* extension) { 61 ExtensionProcessManager* manager, const Extension* extension) {
60 // Start the process for the master page, if it exists. 62 // Start the process for the master page, if it exists and we're not lazy.
61 if (extension->background_url().is_valid()) 63 if (!CommandLine::ForCurrentProcess()->HasSwitch(
64 switches::kEnableLazyBackgroundPages) &&
65 extension->background_url().is_valid())
62 manager->CreateBackgroundHost(extension, extension->background_url()); 66 manager->CreateBackgroundHost(extension, extension->background_url());
63 } 67 }
64 68
65 static void CreateBackgroundHosts( 69 static void CreateBackgroundHostsForProfileStartup(
66 ExtensionProcessManager* manager, const ExtensionList* extensions) { 70 ExtensionProcessManager* manager, const ExtensionList* extensions) {
67 for (ExtensionList::const_iterator extension = extensions->begin(); 71 for (ExtensionList::const_iterator extension = extensions->begin();
68 extension != extensions->end(); ++extension) { 72 extension != extensions->end(); ++extension) {
69 CreateBackgroundHost(manager, *extension); 73 CreateBackgroundHostForExtensionLoad(manager, *extension);
70 } 74 }
71 } 75 }
72 76
73 } // namespace 77 } // namespace
74 78
75 extern bool g_log_bug53991; 79 extern bool g_log_bug53991;
76 80
77 // 81 //
78 // ExtensionProcessManager 82 // ExtensionProcessManager
79 // 83 //
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 285
282 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { 286 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const {
283 return all_hosts_.find(host) != all_hosts_.end(); 287 return all_hosts_.find(host) != all_hosts_.end();
284 } 288 }
285 289
286 void ExtensionProcessManager::Observe(int type, 290 void ExtensionProcessManager::Observe(int type,
287 const NotificationSource& source, 291 const NotificationSource& source,
288 const NotificationDetails& details) { 292 const NotificationDetails& details) {
289 switch (type) { 293 switch (type) {
290 case chrome::NOTIFICATION_EXTENSIONS_READY: { 294 case chrome::NOTIFICATION_EXTENSIONS_READY: {
291 CreateBackgroundHosts(this, 295 CreateBackgroundHostsForProfileStartup(this,
292 Source<Profile>(source).ptr()->GetExtensionService()->extensions()); 296 Source<Profile>(source).ptr()->GetExtensionService()->extensions());
293 break; 297 break;
294 } 298 }
295 299
296 case chrome::NOTIFICATION_EXTENSION_LOADED: { 300 case chrome::NOTIFICATION_EXTENSION_LOADED: {
297 ExtensionService* service = 301 ExtensionService* service =
298 Source<Profile>(source).ptr()->GetExtensionService(); 302 Source<Profile>(source).ptr()->GetExtensionService();
299 if (service->is_ready()) { 303 if (service->is_ready()) {
300 const Extension* extension = Details<const Extension>(details).ptr(); 304 const Extension* extension = Details<const Extension>(details).ptr();
301 ::CreateBackgroundHost(this, extension); 305 ::CreateBackgroundHostForExtensionLoad(this, extension);
302 } 306 }
303 break; 307 break;
304 } 308 }
305 309
306 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { 310 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
307 const Extension* extension = 311 const Extension* extension =
308 Details<UnloadedExtensionInfo>(details)->extension; 312 Details<UnloadedExtensionInfo>(details)->extension;
309 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); 313 for (ExtensionHostSet::iterator iter = background_hosts_.begin();
310 iter != background_hosts_.end(); ++iter) { 314 iter != background_hosts_.end(); ++iter) {
311 ExtensionHost* host = *iter; 315 ExtensionHost* host = *iter;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 ExtensionService* service = profile->GetExtensionService(); 467 ExtensionService* service = profile->GetExtensionService();
464 return service && service->IsIncognitoEnabled(extension->id()); 468 return service && service->IsIncognitoEnabled(extension->id());
465 } 469 }
466 470
467 void IncognitoExtensionProcessManager::Observe( 471 void IncognitoExtensionProcessManager::Observe(
468 int type, 472 int type,
469 const NotificationSource& source, 473 const NotificationSource& source,
470 const NotificationDetails& details) { 474 const NotificationDetails& details) {
471 switch (type) { 475 switch (type) {
472 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { 476 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: {
477 if (CommandLine::ForCurrentProcess()->HasSwitch(
478 switches::kEnableLazyBackgroundPages))
479 break;
473 // We want to spawn our background hosts as soon as the user opens an 480 // We want to spawn our background hosts as soon as the user opens an
474 // incognito window. Watch for new browsers and create the hosts if 481 // incognito window. Watch for new browsers and create the hosts if
475 // it matches our profile. 482 // it matches our profile.
476 Browser* browser = Source<Browser>(source).ptr(); 483 Browser* browser = Source<Browser>(source).ptr();
477 if (browser->profile() == browsing_instance_->browser_context()) { 484 if (browser->profile() == browsing_instance_->browser_context()) {
478 // On Chrome OS, a login screen is implemented as a browser. 485 // On Chrome OS, a login screen is implemented as a browser.
479 // This browser has no extension service. In this case, 486 // This browser has no extension service. In this case,
480 // service will be NULL. 487 // service will be NULL.
481 Profile* profile = 488 Profile* profile =
482 Profile::FromBrowserContext(browsing_instance_->browser_context()); 489 Profile::FromBrowserContext(browsing_instance_->browser_context());
483 ExtensionService* service = profile->GetExtensionService(); 490 ExtensionService* service = profile->GetExtensionService();
484 if (service && service->is_ready()) 491 if (service && service->is_ready())
485 CreateBackgroundHosts(this, service->extensions()); 492 CreateBackgroundHostsForProfileStartup(this, service->extensions());
486 } 493 }
487 break; 494 break;
488 } 495 }
489 default: 496 default:
490 ExtensionProcessManager::Observe(type, source, details); 497 ExtensionProcessManager::Observe(type, source, details);
491 break; 498 break;
492 } 499 }
493 } 500 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_menu_manager_unittest.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698