Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/extensions/extension_process_manager.h" | 5 #include "chrome/browser/extensions/extension_process_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/browser_window.h" | 7 #include "chrome/browser/ui/browser_window.h" |
| 8 #include "content/browser/browsing_instance.h" | 8 #include "content/browser/browsing_instance.h" |
| 9 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
| 10 #include "chrome/browser/extensions/extension_host_mac.h" | 10 #include "chrome/browser/extensions/extension_host_mac.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 : browsing_instance_(new BrowsingInstance(profile)) { | 88 : browsing_instance_(new BrowsingInstance(profile)) { |
| 89 Profile* original_profile = profile->GetOriginalProfile(); | 89 Profile* original_profile = profile->GetOriginalProfile(); |
| 90 registrar_.Add(this, NotificationType::EXTENSIONS_READY, | 90 registrar_.Add(this, NotificationType::EXTENSIONS_READY, |
| 91 Source<Profile>(original_profile)); | 91 Source<Profile>(original_profile)); |
| 92 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 92 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 93 Source<Profile>(original_profile)); | 93 Source<Profile>(original_profile)); |
| 94 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 94 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 95 Source<Profile>(original_profile)); | 95 Source<Profile>(original_profile)); |
| 96 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, | 96 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, |
| 97 Source<Profile>(profile)); | 97 Source<Profile>(profile)); |
| 98 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, | |
| 99 NotificationService::AllSources()); | |
| 100 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, | |
| 101 NotificationService::AllSources()); | |
| 102 registrar_.Add(this, NotificationType::APP_TERMINATING, | 98 registrar_.Add(this, NotificationType::APP_TERMINATING, |
| 103 NotificationService::AllSources()); | 99 NotificationService::AllSources()); |
| 104 } | 100 } |
| 105 | 101 |
| 106 ExtensionProcessManager::~ExtensionProcessManager() { | 102 ExtensionProcessManager::~ExtensionProcessManager() { |
| 107 VLOG_IF(1, g_log_bug53991) << "~ExtensionProcessManager: " << this; | 103 VLOG_IF(1, g_log_bug53991) << "~ExtensionProcessManager: " << this; |
| 108 CloseBackgroundHosts(); | 104 CloseBackgroundHosts(); |
| 109 DCHECK(background_hosts_.empty()); | 105 DCHECK(background_hosts_.empty()); |
| 110 } | 106 } |
| 111 | 107 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 const Extension* extension) { | 209 const Extension* extension) { |
| 214 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 210 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
| 215 iter != background_hosts_.end(); ++iter) { | 211 iter != background_hosts_.end(); ++iter) { |
| 216 ExtensionHost* host = *iter; | 212 ExtensionHost* host = *iter; |
| 217 if (host->extension() == extension) | 213 if (host->extension() == extension) |
| 218 return host; | 214 return host; |
| 219 } | 215 } |
| 220 return NULL; | 216 return NULL; |
| 221 } | 217 } |
| 222 | 218 |
| 223 void ExtensionProcessManager::RegisterExtensionProcess( | |
| 224 const std::string& extension_id, int process_id) { | |
| 225 // TODO(mpcomplete): This is the only place we actually read process_ids_. | |
| 226 // Is it necessary? | |
| 227 ProcessIDMap::const_iterator it = process_ids_.find(extension_id); | |
| 228 if (it != process_ids_.end() && (*it).second == process_id) | |
| 229 return; | |
| 230 | |
| 231 // Extension ids should get removed from the map before the process ids get | |
| 232 // reused from a dead renderer. | |
| 233 DCHECK(it == process_ids_.end()); | |
| 234 process_ids_[extension_id] = process_id; | |
| 235 } | |
| 236 | |
| 237 void ExtensionProcessManager::UnregisterExtensionProcess(int process_id) { | |
| 238 ProcessIDMap::iterator it = process_ids_.begin(); | |
| 239 while (it != process_ids_.end()) { | |
| 240 if (it->second == process_id) | |
| 241 process_ids_.erase(it++); | |
| 242 else | |
| 243 ++it; | |
| 244 } | |
| 245 } | |
| 246 | |
| 247 RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( | 219 RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( |
| 248 const GURL& url) { | 220 const GURL& url) { |
| 249 if (!browsing_instance_->HasSiteInstance(url)) | 221 if (!browsing_instance_->HasSiteInstance(url)) |
| 250 return NULL; | 222 return NULL; |
| 251 scoped_refptr<SiteInstance> site( | 223 scoped_refptr<SiteInstance> site( |
| 252 browsing_instance_->GetSiteInstanceForURL(url)); | 224 browsing_instance_->GetSiteInstanceForURL(url)); |
|
Matt Perry
2011/07/08 22:18:35
What will happen here for hosted apps?
Charlie Reis
2011/07/08 22:49:50
This doesn't appear to be called for hosted apps--
| |
| 253 if (site->HasProcess()) | 225 if (site->HasProcess()) |
| 254 return site->GetProcess(); | 226 return site->GetProcess(); |
| 255 return NULL; | 227 return NULL; |
| 256 } | 228 } |
| 257 | 229 |
| 258 RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( | 230 RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( |
| 259 const std::string& extension_id) { | 231 const std::string& extension_id) { |
| 260 return GetExtensionProcess( | 232 return GetExtensionProcess( |
| 261 Extension::GetBaseURLFromExtensionId(extension_id)); | 233 Extension::GetBaseURLFromExtensionId(extension_id)); |
| 262 } | 234 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 break; | 277 break; |
| 306 } | 278 } |
| 307 | 279 |
| 308 case NotificationType::EXTENSION_HOST_DESTROYED: { | 280 case NotificationType::EXTENSION_HOST_DESTROYED: { |
| 309 ExtensionHost* host = Details<ExtensionHost>(details).ptr(); | 281 ExtensionHost* host = Details<ExtensionHost>(details).ptr(); |
| 310 all_hosts_.erase(host); | 282 all_hosts_.erase(host); |
| 311 background_hosts_.erase(host); | 283 background_hosts_.erase(host); |
| 312 break; | 284 break; |
| 313 } | 285 } |
| 314 | 286 |
| 315 case NotificationType::RENDERER_PROCESS_TERMINATED: | |
| 316 case NotificationType::RENDERER_PROCESS_CLOSED: { | |
| 317 RenderProcessHost* host = Source<RenderProcessHost>(source).ptr(); | |
| 318 UnregisterExtensionProcess(host->id()); | |
| 319 break; | |
| 320 } | |
| 321 | |
| 322 case NotificationType::APP_TERMINATING: { | 287 case NotificationType::APP_TERMINATING: { |
| 323 // Close background hosts when the last browser is closed so that they | 288 // Close background hosts when the last browser is closed so that they |
| 324 // have time to shutdown various objects on different threads. Our | 289 // have time to shutdown various objects on different threads. Our |
| 325 // destructor is called too late in the shutdown sequence. | 290 // destructor is called too late in the shutdown sequence. |
| 326 CloseBackgroundHosts(); | 291 CloseBackgroundHosts(); |
| 327 break; | 292 break; |
| 328 } | 293 } |
| 329 | 294 |
| 330 default: | 295 default: |
| 331 NOTREACHED(); | 296 NOTREACHED(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 if (service && service->is_ready()) | 422 if (service && service->is_ready()) |
| 458 CreateBackgroundHosts(this, service->extensions()); | 423 CreateBackgroundHosts(this, service->extensions()); |
| 459 } | 424 } |
| 460 break; | 425 break; |
| 461 } | 426 } |
| 462 default: | 427 default: |
| 463 ExtensionProcessManager::Observe(type, source, details); | 428 ExtensionProcessManager::Observe(type, source, details); |
| 464 break; | 429 break; |
| 465 } | 430 } |
| 466 } | 431 } |
| OLD | NEW |