| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/lazy_instance.h" |
| 8 #include "chrome/browser/extensions/extension_event_router.h" |
| 7 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
| 8 | |
| 9 #include "chrome/browser/extensions/extension_event_router.h" | |
| 10 #include "chrome/browser/ui/browser_window.h" | |
| 11 #if defined(OS_MACOSX) | |
| 12 #include "chrome/browser/extensions/extension_host_mac.h" | |
| 13 #endif | |
| 14 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| 15 #include "chrome/browser/extensions/extension_info_map.h" | 11 #include "chrome/browser/extensions/extension_info_map.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/chrome_view_type.h" | 18 #include "chrome/common/chrome_view_type.h" |
| 22 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 24 #include "content/browser/renderer_host/render_view_host.h" | 21 #include "content/browser/renderer_host/render_view_host.h" |
| 25 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 28 #include "content/public/browser/render_view_host_delegate.h" | 25 #include "content/public/browser/render_view_host_delegate.h" |
| 29 #include "content/public/browser/site_instance.h" | 26 #include "content/public/browser/site_instance.h" |
| 30 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/common/renderer_preferences.h" | 28 #include "content/public/common/renderer_preferences.h" |
| 32 | 29 |
| 30 #if defined(OS_MACOSX) |
| 31 #include "chrome/browser/extensions/extension_host_mac.h" |
| 32 #endif |
| 33 |
| 33 using content::BrowserThread; | 34 using content::BrowserThread; |
| 34 using content::OpenURLParams; | 35 using content::OpenURLParams; |
| 35 using content::Referrer; | 36 using content::Referrer; |
| 36 using content::SiteInstance; | 37 using content::SiteInstance; |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 // An accessor for an extension's lazy_keepalive_count. | 41 // An accessor for an extension's lazy_keepalive_count. |
| 41 // TODO(mpcomplete): Should we store this on ExtensionHost instead? | 42 // TODO(mpcomplete): Should we store this on ExtensionHost instead? |
| 42 static base::LazyInstance<base::PropertyAccessor<int> > | 43 static base::LazyInstance<base::PropertyAccessor<int> > |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 257 |
| 257 ExtensionHost* ExtensionProcessManager::GetBackgroundHostForExtension( | 258 ExtensionHost* ExtensionProcessManager::GetBackgroundHostForExtension( |
| 258 const std::string& extension_id) { | 259 const std::string& extension_id) { |
| 259 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 260 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
| 260 iter != background_hosts_.end(); ++iter) { | 261 iter != background_hosts_.end(); ++iter) { |
| 261 ExtensionHost* host = *iter; | 262 ExtensionHost* host = *iter; |
| 262 if (host->extension_id() == extension_id) | 263 if (host->extension_id() == extension_id) |
| 263 return host; | 264 return host; |
| 264 } | 265 } |
| 265 return NULL; | 266 return NULL; |
| 266 | |
| 267 } | 267 } |
| 268 | 268 |
| 269 std::set<RenderViewHost*> | 269 std::set<RenderViewHost*> |
| 270 ExtensionProcessManager::GetRenderViewHostsForExtension( | 270 ExtensionProcessManager::GetRenderViewHostsForExtension( |
| 271 const std::string& extension_id) { | 271 const std::string& extension_id) { |
| 272 std::set<RenderViewHost*> result; | 272 std::set<RenderViewHost*> result; |
| 273 | 273 |
| 274 SiteInstance* site_instance = GetSiteInstanceForURL( | 274 SiteInstance* site_instance = GetSiteInstanceForURL( |
| 275 Extension::GetBaseURLFromExtensionId(extension_id)); | 275 Extension::GetBaseURLFromExtensionId(extension_id)); |
| 276 if (!site_instance) | 276 if (!site_instance) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 325 |
| 326 return count; | 326 return count; |
| 327 } | 327 } |
| 328 | 328 |
| 329 int ExtensionProcessManager::DecrementLazyKeepaliveCount( | 329 int ExtensionProcessManager::DecrementLazyKeepaliveCount( |
| 330 const Extension* extension) { | 330 const Extension* extension) { |
| 331 if (extension->background_page_persists()) | 331 if (extension->background_page_persists()) |
| 332 return 0; | 332 return 0; |
| 333 | 333 |
| 334 int& count = ::GetLazyKeepaliveCount(GetProfile(), extension); | 334 int& count = ::GetLazyKeepaliveCount(GetProfile(), extension); |
| 335 DCHECK(count > 0); | 335 DCHECK_GT(count, 0); |
| 336 if (--count == 0) | 336 if (--count == 0) |
| 337 OnLazyBackgroundPageIdle(extension->id()); | 337 OnLazyBackgroundPageIdle(extension->id()); |
| 338 | 338 |
| 339 return count; | 339 return count; |
| 340 } | 340 } |
| 341 | 341 |
| 342 void ExtensionProcessManager::OnLazyBackgroundPageIdle( | 342 void ExtensionProcessManager::OnLazyBackgroundPageIdle( |
| 343 const std::string& extension_id) { | 343 const std::string& extension_id) { |
| 344 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 344 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
| 345 if (host && !HasVisibleViews(extension_id)) | 345 if (host && !HasVisibleViews(extension_id)) |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 if (service && service->is_ready()) | 554 if (service && service->is_ready()) |
| 555 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 555 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
| 556 } | 556 } |
| 557 break; | 557 break; |
| 558 } | 558 } |
| 559 default: | 559 default: |
| 560 ExtensionProcessManager::Observe(type, source, details); | 560 ExtensionProcessManager::Observe(type, source, details); |
| 561 break; | 561 break; |
| 562 } | 562 } |
| 563 } | 563 } |
| OLD | NEW |