Chromium Code Reviews| 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" | 7 #include "base/lazy_instance.h" |
| 8 #include "chrome/browser/extensions/extension_event_router.h" | 8 #include "chrome/browser/extensions/extension_event_router.h" |
| 9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 } | 366 } |
| 367 | 367 |
| 368 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { | 368 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { |
| 369 return site_instance_->GetRelatedSiteInstance(url); | 369 return site_instance_->GetRelatedSiteInstance(url); |
| 370 } | 370 } |
| 371 | 371 |
| 372 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { | 372 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { |
| 373 return all_hosts_.find(host) != all_hosts_.end(); | 373 return all_hosts_.find(host) != all_hosts_.end(); |
| 374 } | 374 } |
| 375 | 375 |
| 376 bool ExtensionProcessManager::IsBackgroundHostClosing( | |
|
Yoyo Zhou
2012/04/19 21:47:13
It seems like you could simplify the usage here (i
Matt Perry
2012/04/19 22:21:53
I thought about doing something like that, but I t
Yoyo Zhou
2012/04/19 22:32:55
I don't either, since it's not that convenient eit
| |
| 377 const std::string& extension_id) { | |
| 378 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | |
| 379 return (host && background_page_data_[extension_id].is_closing); | |
| 380 } | |
| 381 | |
| 376 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { | 382 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { |
| 377 if (!extension->has_lazy_background_page()) | 383 if (!extension->has_lazy_background_page()) |
| 378 return 0; | 384 return 0; |
| 379 | 385 |
| 380 return background_page_data_[extension->id()].lazy_keepalive_count; | 386 return background_page_data_[extension->id()].lazy_keepalive_count; |
| 381 } | 387 } |
| 382 | 388 |
| 383 int ExtensionProcessManager::IncrementLazyKeepaliveCount( | 389 int ExtensionProcessManager::IncrementLazyKeepaliveCount( |
| 384 const Extension* extension) { | 390 const Extension* extension) { |
| 385 if (!extension->has_lazy_background_page()) | 391 if (!extension->has_lazy_background_page()) |
| 386 return 0; | 392 return 0; |
| 387 | 393 |
| 388 int& count = background_page_data_[extension->id()].lazy_keepalive_count; | 394 int& count = background_page_data_[extension->id()].lazy_keepalive_count; |
| 389 if (++count == 1) | 395 if (++count == 1) |
| 390 OnLazyBackgroundPageActive(extension->id()); | 396 OnLazyBackgroundPageActive(extension->id()); |
| 391 | 397 |
| 392 return count; | 398 return count; |
| 393 } | 399 } |
| 394 | 400 |
| 395 int ExtensionProcessManager::DecrementLazyKeepaliveCount( | 401 int ExtensionProcessManager::DecrementLazyKeepaliveCount( |
| 396 const Extension* extension) { | 402 const Extension* extension) { |
| 397 if (!extension->has_lazy_background_page()) | 403 if (!extension->has_lazy_background_page()) |
| 398 return 0; | 404 return 0; |
| 399 | 405 |
| 400 // Don't decrement the count if the background page has gone away. This can | 406 // This should never be called if the background page isn't active. |
| 401 // happen e.g. if an event was dispatched while unloading the page, or if | 407 // Otherwise, the count can get out of sync, because we reset it when the |
| 402 // the process is killed/closed while a message port remains open. | 408 // page unloads. |
| 403 // TODO(mpcomplete): This might be insufficient.. what if the page goes away | 409 CHECK(GetBackgroundHostForExtension(extension->id())); |
| 404 // and comes back before we get here? Then we'll have an imbalanced | |
| 405 // keepalive count. | |
| 406 ExtensionHost* host = GetBackgroundHostForExtension(extension->id()); | |
| 407 if (!host) | |
| 408 return 0; | |
| 409 | 410 |
| 410 int& count = background_page_data_[extension->id()].lazy_keepalive_count; | 411 int& count = background_page_data_[extension->id()].lazy_keepalive_count; |
| 411 DCHECK_GT(count, 0); | 412 DCHECK_GT(count, 0); |
| 412 if (--count == 0) | 413 if (--count == 0) |
| 413 OnLazyBackgroundPageIdle(extension->id()); | 414 OnLazyBackgroundPageIdle(extension->id()); |
| 414 | 415 |
| 415 return count; | 416 return count; |
| 416 } | 417 } |
| 417 | 418 |
| 418 void ExtensionProcessManager::OnLazyBackgroundPageIdle( | 419 void ExtensionProcessManager::OnLazyBackgroundPageIdle( |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 if (service && service->is_ready()) | 690 if (service && service->is_ready()) |
| 690 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 691 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
| 691 } | 692 } |
| 692 break; | 693 break; |
| 693 } | 694 } |
| 694 default: | 695 default: |
| 695 ExtensionProcessManager::Observe(type, source, details); | 696 ExtensionProcessManager::Observe(type, source, details); |
| 696 break; | 697 break; |
| 697 } | 698 } |
| 698 } | 699 } |
| OLD | NEW |