OLD | NEW |
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" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( | 78 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( |
79 Extension* extension, const GURL& url) { | 79 Extension* extension, const GURL& url) { |
80 ExtensionHost* host = | 80 ExtensionHost* host = |
81 new ExtensionHost(extension, GetSiteInstanceForURL(url), url); | 81 new ExtensionHost(extension, GetSiteInstanceForURL(url), url); |
82 host->CreateRenderView(NULL); // create a RenderViewHost with no view | 82 host->CreateRenderView(NULL); // create a RenderViewHost with no view |
83 OnExtensionHostCreated(host, true); | 83 OnExtensionHostCreated(host, true); |
84 return host; | 84 return host; |
85 } | 85 } |
86 | 86 |
87 void ExtensionProcessManager::RegisterExtensionProcess( | 87 void ExtensionProcessManager::RegisterExtensionProcess( |
88 std::string extension_id, int process_id) { | 88 const std::string& extension_id, int process_id) { |
89 ProcessIDMap::const_iterator it = process_ids_.find(extension_id); | 89 ProcessIDMap::const_iterator it = process_ids_.find(extension_id); |
90 if (it != process_ids_.end() && (*it).second == process_id) | 90 if (it != process_ids_.end() && (*it).second == process_id) |
91 return; | 91 return; |
92 | 92 |
93 process_ids_[extension_id] = process_id; | 93 process_ids_[extension_id] = process_id; |
94 | 94 |
95 ExtensionsService* extension_service = | 95 ExtensionsService* extension_service = |
96 browsing_instance_->profile()->GetExtensionsService(); | 96 browsing_instance_->profile()->GetExtensionsService(); |
97 | 97 |
98 std::vector<std::string> page_action_ids; | 98 std::vector<std::string> page_action_ids; |
(...skipping 11 matching lines...) Expand all Loading... |
110 void ExtensionProcessManager::UnregisterExtensionProcess(int process_id) { | 110 void ExtensionProcessManager::UnregisterExtensionProcess(int process_id) { |
111 ProcessIDMap::iterator it = process_ids_.begin(); | 111 ProcessIDMap::iterator it = process_ids_.begin(); |
112 while (it != process_ids_.end()) { | 112 while (it != process_ids_.end()) { |
113 if (it->second == process_id) | 113 if (it->second == process_id) |
114 process_ids_.erase(it++); | 114 process_ids_.erase(it++); |
115 else | 115 else |
116 ++it; | 116 ++it; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
| 120 RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( |
| 121 const std::string& extension_id) { |
| 122 ProcessIDMap::const_iterator it = process_ids_.find(extension_id); |
| 123 if (it == process_ids_.end()) |
| 124 return NULL; |
| 125 |
| 126 RenderProcessHost* rph = RenderProcessHost::FromID(it->second); |
| 127 DCHECK(rph) << "We should have unregistered this host."; |
| 128 return rph; |
| 129 } |
| 130 |
120 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { | 131 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { |
121 return browsing_instance_->GetSiteInstanceForURL(url); | 132 return browsing_instance_->GetSiteInstanceForURL(url); |
122 } | 133 } |
123 | 134 |
124 void ExtensionProcessManager::Observe(NotificationType type, | 135 void ExtensionProcessManager::Observe(NotificationType type, |
125 const NotificationSource& source, | 136 const NotificationSource& source, |
126 const NotificationDetails& details) { | 137 const NotificationDetails& details) { |
127 switch (type.value) { | 138 switch (type.value) { |
128 case NotificationType::EXTENSIONS_READY: | 139 case NotificationType::EXTENSIONS_READY: |
129 CreateBackgroundHosts(this, | 140 CreateBackgroundHosts(this, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, | 187 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, |
177 bool is_background) { | 188 bool is_background) { |
178 all_hosts_.insert(host); | 189 all_hosts_.insert(host); |
179 if (is_background) | 190 if (is_background) |
180 background_hosts_.insert(host); | 191 background_hosts_.insert(host); |
181 NotificationService::current()->Notify( | 192 NotificationService::current()->Notify( |
182 NotificationType::EXTENSION_HOST_CREATED, | 193 NotificationType::EXTENSION_HOST_CREATED, |
183 Source<ExtensionProcessManager>(this), | 194 Source<ExtensionProcessManager>(this), |
184 Details<ExtensionHost>(host)); | 195 Details<ExtensionHost>(host)); |
185 } | 196 } |
OLD | NEW |