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 std::set<int>::iterator it = process_ids_.find(host_id); | |
jam
2011/09/26 15:46:16
nit: you can also just write process_ids_.erase(ho
| |
258 if (it != process_ids_.end()) | |
259 process_ids_.erase(it); | |
260 } | |
261 | |
262 bool ExtensionProcessManager::IsProcessHostWithBindings(int host_id) const { | |
263 return process_ids_.find(host_id) != process_ids_.end(); | |
264 } | |
265 | |
249 RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( | 266 RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( |
250 const GURL& url) { | 267 const GURL& url) { |
251 if (!browsing_instance_->HasSiteInstance(url)) | 268 if (!browsing_instance_->HasSiteInstance(url)) |
252 return NULL; | 269 return NULL; |
253 scoped_refptr<SiteInstance> site( | 270 scoped_refptr<SiteInstance> site( |
254 browsing_instance_->GetSiteInstanceForURL(url)); | 271 browsing_instance_->GetSiteInstanceForURL(url)); |
255 if (site->HasProcess()) | 272 if (site->HasProcess()) |
256 return site->GetProcess(); | 273 return site->GetProcess(); |
257 return NULL; | 274 return NULL; |
258 } | 275 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 background_hosts_.erase(host); | 345 background_hosts_.erase(host); |
329 break; | 346 break; |
330 } | 347 } |
331 | 348 |
332 case content::NOTIFICATION_SITE_INSTANCE_DELETED: { | 349 case content::NOTIFICATION_SITE_INSTANCE_DELETED: { |
333 SiteInstance* site_instance = Source<SiteInstance>(source).ptr(); | 350 SiteInstance* site_instance = Source<SiteInstance>(source).ptr(); |
334 UnregisterExtensionSiteInstance(site_instance->id()); | 351 UnregisterExtensionSiteInstance(site_instance->id()); |
335 break; | 352 break; |
336 } | 353 } |
337 | 354 |
355 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | |
356 RenderProcessHost* process_host = | |
357 Source<RenderProcessHost>(source).ptr(); | |
358 UnregisterProcessHostWithBindings(process_host->id()); | |
359 break; | |
360 } | |
361 | |
338 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { | 362 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { |
339 ExtensionHost* host = Details<ExtensionHost>(details).ptr(); | 363 ExtensionHost* host = Details<ExtensionHost>(details).ptr(); |
340 if (host->extension_host_type() == ViewType::EXTENSION_BACKGROUND_PAGE) { | 364 if (host->extension_host_type() == ViewType::EXTENSION_BACKGROUND_PAGE) { |
341 delete host; | 365 delete host; |
342 // |host| should deregister itself from our structures. | 366 // |host| should deregister itself from our structures. |
343 CHECK(background_hosts_.find(host) == background_hosts_.end()); | 367 CHECK(background_hosts_.find(host) == background_hosts_.end()); |
344 } | 368 } |
345 break; | 369 break; |
346 } | 370 } |
347 | 371 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 if (service && service->is_ready()) | 523 if (service && service->is_ready()) |
500 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 524 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
501 } | 525 } |
502 break; | 526 break; |
503 } | 527 } |
504 default: | 528 default: |
505 ExtensionProcessManager::Observe(type, source, details); | 529 ExtensionProcessManager::Observe(type, source, details); |
506 break; | 530 break; |
507 } | 531 } |
508 } | 532 } |
OLD | NEW |