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

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

Issue 147051: Clean up a few startup and shutdown dependencies which should fix some of the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extension_process_manager.h" 5 #include "chrome/browser/extensions/extension_process_manager.h"
6 6
7 #include "chrome/browser/browsing_instance.h" 7 #include "chrome/browser/browsing_instance.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extensions_service.h" 9 #include "chrome/browser/extensions/extensions_service.h"
10 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
11 #include "chrome/browser/tab_contents/site_instance.h" 11 #include "chrome/browser/tab_contents/site_instance.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/notification_service.h" 13 #include "chrome/common/notification_service.h"
14 #include "chrome/common/notification_type.h" 14 #include "chrome/common/notification_type.h"
15 15
16 static void CreateBackgroundHosts( 16 static void CreateBackgroundHosts(
17 ExtensionProcessManager* manager, const ExtensionList* extensions) { 17 ExtensionProcessManager* manager, const ExtensionList* extensions) {
18 for (ExtensionList::const_iterator extension = extensions->begin(); 18 for (ExtensionList::const_iterator extension = extensions->begin();
19 extension != extensions->end(); ++extension) { 19 extension != extensions->end(); ++extension) {
20 // Start the process for the master page, if it exists. 20 // Start the process for the master page, if it exists.
21 if ((*extension)->background_url().is_valid()) 21 if ((*extension)->background_url().is_valid())
22 manager->CreateBackgroundHost(*extension, (*extension)->background_url()); 22 manager->CreateBackgroundHost(*extension, (*extension)->background_url());
23 } 23 }
24 } 24 }
25 25
26 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) 26 ExtensionProcessManager::ExtensionProcessManager(Profile* profile)
27 : browsing_instance_(new BrowsingInstance(profile)) { 27 : browsing_instance_(new BrowsingInstance(profile)) {
28 registrar_.Add(this, NotificationType::EXTENSIONS_READY,
29 NotificationService::AllSources());
28 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, 30 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED,
29 NotificationService::AllSources()); 31 NotificationService::AllSources());
30 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 32 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
31 NotificationService::AllSources()); 33 NotificationService::AllSources());
32 34
33 if (profile->GetExtensionsService()) 35 ExtensionsService* service = profile->GetExtensionsService();
34 CreateBackgroundHosts(this, profile->GetExtensionsService()->extensions()); 36 if (service && service->is_ready())
rafaelw 2009/06/24 23:04:22 Can this test ever return true?
Erik does not do reviews 2009/06/25 16:19:08 Good point. It can't any more. I'll fix this in
37 CreateBackgroundHosts(this, service->extensions());
35 } 38 }
36 39
37 ExtensionProcessManager::~ExtensionProcessManager() { 40 ExtensionProcessManager::~ExtensionProcessManager() {
38 // Copy all_hosts_ to avoid iterator invalidation issues. 41 // Copy all_hosts_ to avoid iterator invalidation issues.
39 ExtensionHostSet to_delete(all_hosts_.begin(), 42 ExtensionHostSet to_delete(background_hosts_.begin(),
40 all_hosts_.end()); 43 background_hosts_.end());
41 ExtensionHostSet::iterator iter; 44 ExtensionHostSet::iterator iter;
42 for (iter = to_delete.begin(); iter != to_delete.end(); ++iter) 45 for (iter = to_delete.begin(); iter != to_delete.end(); ++iter)
43 delete *iter; 46 delete *iter;
44 } 47 }
45 48
46 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, 49 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension,
47 const GURL& url, 50 const GURL& url,
48 Browser* browser) { 51 Browser* browser) {
49 DCHECK(extension); 52 DCHECK(extension);
50 DCHECK(browser); 53 DCHECK(browser);
(...skipping 27 matching lines...) Expand all
78 } 81 }
79 82
80 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { 83 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) {
81 return browsing_instance_->GetSiteInstanceForURL(url); 84 return browsing_instance_->GetSiteInstanceForURL(url);
82 } 85 }
83 86
84 void ExtensionProcessManager::Observe(NotificationType type, 87 void ExtensionProcessManager::Observe(NotificationType type,
85 const NotificationSource& source, 88 const NotificationSource& source,
86 const NotificationDetails& details) { 89 const NotificationDetails& details) {
87 switch (type.value) { 90 switch (type.value) {
91 case NotificationType::EXTENSIONS_READY:
92 CreateBackgroundHosts(this,
93 Source<ExtensionsService>(source).ptr()->extensions());
94 break;
95
88 case NotificationType::EXTENSIONS_LOADED: { 96 case NotificationType::EXTENSIONS_LOADED: {
89 const ExtensionList* extensions = Details<ExtensionList>(details).ptr(); 97 ExtensionsService* service = Source<ExtensionsService>(source).ptr();
90 CreateBackgroundHosts(this, extensions); 98 if (service->is_ready()) {
99 const ExtensionList* extensions = Details<ExtensionList>(details).ptr();
100 CreateBackgroundHosts(this, extensions);
101 }
91 break; 102 break;
92 } 103 }
93 104
94 case NotificationType::EXTENSION_UNLOADED: { 105 case NotificationType::EXTENSION_UNLOADED: {
95 Extension* extension = Details<Extension>(details).ptr(); 106 Extension* extension = Details<Extension>(details).ptr();
96 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); 107 for (ExtensionHostSet::iterator iter = background_hosts_.begin();
97 iter != background_hosts_.end(); ++iter) { 108 iter != background_hosts_.end(); ++iter) {
98 ExtensionHost* host = *iter; 109 ExtensionHost* host = *iter;
99 if (host->extension()->id() == extension->id()) { 110 if (host->extension()->id() == extension->id()) {
100 delete host; 111 delete host;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, 148 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host,
138 bool is_background) { 149 bool is_background) {
139 all_hosts_.insert(host); 150 all_hosts_.insert(host);
140 if (is_background) 151 if (is_background)
141 background_hosts_.insert(host); 152 background_hosts_.insert(host);
142 NotificationService::current()->Notify( 153 NotificationService::current()->Notify(
143 NotificationType::EXTENSION_HOST_CREATED, 154 NotificationType::EXTENSION_HOST_CREATED,
144 Source<ExtensionProcessManager>(this), 155 Source<ExtensionProcessManager>(this),
145 Details<ExtensionHost>(host)); 156 Details<ExtensionHost>(host));
146 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698