| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/extensions/extension_process_manager.h" | 6 #include "chrome/browser/extensions/extension_process_manager.h" |
| 7 | 7 |
| 8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #include "content/browser/browsing_instance.h" | 9 #include "content/browser/browsing_instance.h" |
| 10 #if defined(OS_MACOSX) | 10 #if defined(OS_MACOSX) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 97 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 98 Source<Profile>(original_profile)); | 98 Source<Profile>(original_profile)); |
| 99 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 99 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 100 Source<Profile>(profile)); | 100 Source<Profile>(profile)); |
| 101 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 101 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 102 Source<Profile>(profile)); | 102 Source<Profile>(profile)); |
| 103 // We can listen to everything for SITE_INSTANCE_DELETED because we check the | 103 // We can listen to everything for SITE_INSTANCE_DELETED because we check the |
| 104 // |site_instance_id| in UnregisterExtensionSiteInstance. | 104 // |site_instance_id| in UnregisterExtensionSiteInstance. |
| 105 registrar_.Add(this, content::NOTIFICATION_SITE_INSTANCE_DELETED, | 105 registrar_.Add(this, content::NOTIFICATION_SITE_INSTANCE_DELETED, |
| 106 NotificationService::AllBrowserContextsAndSources()); | 106 NotificationService::AllBrowserContextsAndSources()); |
| 107 // Same for NOTIFICATION_RENDERER_PROCESS_CLOSED. |
| 108 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 109 NotificationService::AllBrowserContextsAndSources()); |
| 107 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, | 110 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, |
| 108 NotificationService::AllSources()); | 111 NotificationService::AllSources()); |
| 109 } | 112 } |
| 110 | 113 |
| 111 ExtensionProcessManager::~ExtensionProcessManager() { | 114 ExtensionProcessManager::~ExtensionProcessManager() { |
| 112 CloseBackgroundHosts(); | 115 CloseBackgroundHosts(); |
| 113 DCHECK(background_hosts_.empty()); | 116 DCHECK(background_hosts_.empty()); |
| 114 } | 117 } |
| 115 | 118 |
| 116 ExtensionHost* ExtensionProcessManager::CreateViewHost( | 119 ExtensionHost* ExtensionProcessManager::CreateViewHost( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 extension_ids_[site_instance_id] = extension_id; | 242 extension_ids_[site_instance_id] = extension_id; |
| 240 } | 243 } |
| 241 | 244 |
| 242 void ExtensionProcessManager::UnregisterExtensionSiteInstance( | 245 void ExtensionProcessManager::UnregisterExtensionSiteInstance( |
| 243 int site_instance_id) { | 246 int site_instance_id) { |
| 244 SiteInstanceIDMap::iterator it = extension_ids_.find(site_instance_id); | 247 SiteInstanceIDMap::iterator it = extension_ids_.find(site_instance_id); |
| 245 if (it != extension_ids_.end()) | 248 if (it != extension_ids_.end()) |
| 246 extension_ids_.erase(it++); | 249 extension_ids_.erase(it++); |
| 247 } | 250 } |
| 248 | 251 |
| 252 void ExtensionProcessManager::RegisterProcessHostWithBindings(int host_id) { |
| 253 process_ids_.insert(host_id); |
| 254 } |
| 255 |
| 256 void ExtensionProcessManager::UnregisterProcessHostWithBindings(int host_id) { |
| 257 process_ids_.erase(host_id); |
| 258 } |
| 259 |
| 260 bool ExtensionProcessManager::IsProcessHostWithBindings(int host_id) const { |
| 261 return process_ids_.find(host_id) != process_ids_.end(); |
| 262 } |
| 263 |
| 249 RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( | 264 RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( |
| 250 const GURL& url) { | 265 const GURL& url) { |
| 251 if (!browsing_instance_->HasSiteInstance(url)) | 266 if (!browsing_instance_->HasSiteInstance(url)) |
| 252 return NULL; | 267 return NULL; |
| 253 scoped_refptr<SiteInstance> site( | 268 scoped_refptr<SiteInstance> site( |
| 254 browsing_instance_->GetSiteInstanceForURL(url)); | 269 browsing_instance_->GetSiteInstanceForURL(url)); |
| 255 if (site->HasProcess()) | 270 if (site->HasProcess()) |
| 256 return site->GetProcess(); | 271 return site->GetProcess(); |
| 257 return NULL; | 272 return NULL; |
| 258 } | 273 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 background_hosts_.erase(host); | 343 background_hosts_.erase(host); |
| 329 break; | 344 break; |
| 330 } | 345 } |
| 331 | 346 |
| 332 case content::NOTIFICATION_SITE_INSTANCE_DELETED: { | 347 case content::NOTIFICATION_SITE_INSTANCE_DELETED: { |
| 333 SiteInstance* site_instance = Source<SiteInstance>(source).ptr(); | 348 SiteInstance* site_instance = Source<SiteInstance>(source).ptr(); |
| 334 UnregisterExtensionSiteInstance(site_instance->id()); | 349 UnregisterExtensionSiteInstance(site_instance->id()); |
| 335 break; | 350 break; |
| 336 } | 351 } |
| 337 | 352 |
| 353 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
| 354 RenderProcessHost* process_host = |
| 355 Source<RenderProcessHost>(source).ptr(); |
| 356 UnregisterProcessHostWithBindings(process_host->id()); |
| 357 break; |
| 358 } |
| 359 |
| 338 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { | 360 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { |
| 339 ExtensionHost* host = Details<ExtensionHost>(details).ptr(); | 361 ExtensionHost* host = Details<ExtensionHost>(details).ptr(); |
| 340 if (host->extension_host_type() == ViewType::EXTENSION_BACKGROUND_PAGE) { | 362 if (host->extension_host_type() == ViewType::EXTENSION_BACKGROUND_PAGE) { |
| 341 delete host; | 363 delete host; |
| 342 // |host| should deregister itself from our structures. | 364 // |host| should deregister itself from our structures. |
| 343 CHECK(background_hosts_.find(host) == background_hosts_.end()); | 365 CHECK(background_hosts_.find(host) == background_hosts_.end()); |
| 344 } | 366 } |
| 345 break; | 367 break; |
| 346 } | 368 } |
| 347 | 369 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 if (service && service->is_ready()) | 521 if (service && service->is_ready()) |
| 500 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 522 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
| 501 } | 523 } |
| 502 break; | 524 break; |
| 503 } | 525 } |
| 504 default: | 526 default: |
| 505 ExtensionProcessManager::Observe(type, source, details); | 527 ExtensionProcessManager::Observe(type, source, details); |
| 506 break; | 528 break; |
| 507 } | 529 } |
| 508 } | 530 } |
| OLD | NEW |