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 "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 } | 407 } |
408 | 408 |
409 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { | 409 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { |
410 if (!extension->has_lazy_background_page()) | 410 if (!extension->has_lazy_background_page()) |
411 return 0; | 411 return 0; |
412 | 412 |
413 return background_page_data_[extension->id()].lazy_keepalive_count; | 413 return background_page_data_[extension->id()].lazy_keepalive_count; |
414 } | 414 } |
415 | 415 |
416 int ExtensionProcessManager::IncrementLazyKeepaliveCount( | 416 int ExtensionProcessManager::IncrementLazyKeepaliveCount( |
417 const Extension* extension, ShouldCancelSuspend should_cancel_suspend) { | 417 const Extension* extension) { |
418 if (!extension->has_lazy_background_page()) | 418 if (!extension->has_lazy_background_page()) |
419 return 0; | 419 return 0; |
420 | 420 |
421 int& count = background_page_data_[extension->id()].lazy_keepalive_count; | 421 int& count = background_page_data_[extension->id()].lazy_keepalive_count; |
422 bool& is_closing = background_page_data_[extension->id()].is_closing; | 422 if (++count == 1) |
423 if (++count == 1) { | |
424 if (should_cancel_suspend == CANCEL_SUSPEND && is_closing) { | |
425 is_closing = false; | |
426 ExtensionHost* host = GetBackgroundHostForExtension(extension->id()); | |
427 if (host) | |
428 host->render_view_host()->Send( | |
429 new ExtensionMsg_CancelUnload(extension->id())); | |
430 } | |
431 OnLazyBackgroundPageActive(extension->id()); | 423 OnLazyBackgroundPageActive(extension->id()); |
432 } | |
433 | 424 |
434 return count; | 425 return count; |
435 } | 426 } |
436 | 427 |
437 int ExtensionProcessManager::DecrementLazyKeepaliveCount( | 428 int ExtensionProcessManager::DecrementLazyKeepaliveCount( |
438 const Extension* extension) { | 429 const Extension* extension) { |
439 if (!extension->has_lazy_background_page()) | 430 if (!extension->has_lazy_background_page()) |
440 return 0; | 431 return 0; |
441 | 432 |
442 int& count = background_page_data_[extension->id()].lazy_keepalive_count; | 433 int& count = background_page_data_[extension->id()].lazy_keepalive_count; |
(...skipping 13 matching lines...) Expand all Loading... | |
456 void ExtensionProcessManager::IncrementLazyKeepaliveCountForView( | 447 void ExtensionProcessManager::IncrementLazyKeepaliveCountForView( |
457 RenderViewHost* render_view_host) { | 448 RenderViewHost* render_view_host) { |
458 WebContents* web_contents = | 449 WebContents* web_contents = |
459 WebContents::FromRenderViewHost(render_view_host); | 450 WebContents::FromRenderViewHost(render_view_host); |
460 chrome::ViewType view_type = chrome::GetViewType(web_contents); | 451 chrome::ViewType view_type = chrome::GetViewType(web_contents); |
461 if (view_type != chrome::VIEW_TYPE_INVALID && | 452 if (view_type != chrome::VIEW_TYPE_INVALID && |
462 view_type != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 453 view_type != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
463 const Extension* extension = GetExtensionForRenderViewHost( | 454 const Extension* extension = GetExtensionForRenderViewHost( |
464 render_view_host); | 455 render_view_host); |
465 if (extension) | 456 if (extension) |
466 IncrementLazyKeepaliveCount(extension, DONT_CANCEL_SUSPEND); | 457 IncrementLazyKeepaliveCount(extension); |
467 } | 458 } |
468 } | 459 } |
469 | 460 |
470 void ExtensionProcessManager::OnLazyBackgroundPageIdle( | 461 void ExtensionProcessManager::OnLazyBackgroundPageIdle( |
471 const std::string& extension_id, int sequence_id) { | 462 const std::string& extension_id, int sequence_id) { |
472 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 463 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
473 if (host && !background_page_data_[extension_id].is_closing && | 464 if (host && !background_page_data_[extension_id].is_closing && |
474 sequence_id == background_page_data_[extension_id].close_sequence_id) { | 465 sequence_id == background_page_data_[extension_id].close_sequence_id) { |
475 // Tell the renderer we are about to close. This is a simple ping that the | 466 // Tell the renderer we are about to close. This is a simple ping that the |
476 // renderer will respond to. The purpose is to control sequencing: if the | 467 // renderer will respond to. The purpose is to control sequencing: if the |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 if (host) | 512 if (host) |
522 CloseBackgroundHost(host); | 513 CloseBackgroundHost(host); |
523 } | 514 } |
524 } | 515 } |
525 | 516 |
526 void ExtensionProcessManager::OnNetworkRequestStarted( | 517 void ExtensionProcessManager::OnNetworkRequestStarted( |
527 RenderViewHost* render_view_host) { | 518 RenderViewHost* render_view_host) { |
528 ExtensionHost* host = GetBackgroundHostForExtension( | 519 ExtensionHost* host = GetBackgroundHostForExtension( |
529 GetExtensionID(render_view_host)); | 520 GetExtensionID(render_view_host)); |
530 if (host && host->render_view_host() == render_view_host) | 521 if (host && host->render_view_host() == render_view_host) |
531 IncrementLazyKeepaliveCount(host->extension(), DONT_CANCEL_SUSPEND); | 522 IncrementLazyKeepaliveCount(host->extension()); |
532 } | 523 } |
533 | 524 |
534 void ExtensionProcessManager::OnNetworkRequestDone( | 525 void ExtensionProcessManager::OnNetworkRequestDone( |
535 RenderViewHost* render_view_host) { | 526 RenderViewHost* render_view_host) { |
536 ExtensionHost* host = GetBackgroundHostForExtension( | 527 ExtensionHost* host = GetBackgroundHostForExtension( |
537 GetExtensionID(render_view_host)); | 528 GetExtensionID(render_view_host)); |
538 if (host && host->render_view_host() == render_view_host) | 529 if (host && host->render_view_host() == render_view_host) |
539 DecrementLazyKeepaliveCount(host->extension()); | 530 DecrementLazyKeepaliveCount(host->extension()); |
540 } | 531 } |
541 | 532 |
533 void ExtensionProcessManager::CancelSuspend(const Extension* extension) { | |
534 bool& is_closing = background_page_data_[extension->id()].is_closing; | |
535 ExtensionHost* host = GetBackgroundHostForExtension(extension->id()); | |
536 if (host && is_closing) { | |
537 is_closing = false; | |
538 host->render_view_host()->Send( | |
539 new ExtensionMsg_CancelUnload(extension->id())); | |
540 } | |
541 IncrementLazyKeepaliveCount(extension); | |
542 DecrementLazyKeepaliveCount(extension); | |
Matt Perry
2012/07/25 19:21:55
Could you add a comment why this is necessary?
(T
koz (OOO until 15th September)
2012/07/26 00:40:08
I've added a comment and will leave it this way, b
| |
543 } | |
544 | |
542 void ExtensionProcessManager::Observe( | 545 void ExtensionProcessManager::Observe( |
543 int type, | 546 int type, |
544 const content::NotificationSource& source, | 547 const content::NotificationSource& source, |
545 const content::NotificationDetails& details) { | 548 const content::NotificationDetails& details) { |
546 switch (type) { | 549 switch (type) { |
547 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 550 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
548 CreateBackgroundHostsForProfileStartup(this, | 551 CreateBackgroundHostsForProfileStartup(this, |
549 content::Source<Profile>(source).ptr()-> | 552 content::Source<Profile>(source).ptr()-> |
550 GetExtensionService()->extensions()); | 553 GetExtensionService()->extensions()); |
551 break; | 554 break; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 content::Details<RenderViewHost>(details).ptr(); | 620 content::Details<RenderViewHost>(details).ptr(); |
618 WebContents* web_contents = | 621 WebContents* web_contents = |
619 WebContents::FromRenderViewHost(render_view_host); | 622 WebContents::FromRenderViewHost(render_view_host); |
620 // Keep the lazy background page alive while it's being inspected. | 623 // Keep the lazy background page alive while it's being inspected. |
621 // Balanced in response to the CLOSING notification. | 624 // Balanced in response to the CLOSING notification. |
622 if (chrome::GetViewType(web_contents) == | 625 if (chrome::GetViewType(web_contents) == |
623 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 626 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
624 const Extension* extension = GetExtensionForRenderViewHost( | 627 const Extension* extension = GetExtensionForRenderViewHost( |
625 render_view_host); | 628 render_view_host); |
626 if (extension) | 629 if (extension) |
627 IncrementLazyKeepaliveCount(extension, CANCEL_SUSPEND); | 630 IncrementLazyKeepaliveCount(extension); |
628 } | 631 } |
629 break; | 632 break; |
630 } | 633 } |
631 | 634 |
632 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: { | 635 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: { |
633 RenderViewHost* render_view_host = | 636 RenderViewHost* render_view_host = |
634 content::Details<RenderViewHost>(details).ptr(); | 637 content::Details<RenderViewHost>(details).ptr(); |
635 WebContents* web_contents = | 638 WebContents* web_contents = |
636 WebContents::FromRenderViewHost(render_view_host); | 639 WebContents::FromRenderViewHost(render_view_host); |
637 // Balanced in response to the OPENING notification. | 640 // Balanced in response to the OPENING notification. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 if (service && service->is_ready()) | 798 if (service && service->is_ready()) |
796 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 799 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
797 } | 800 } |
798 break; | 801 break; |
799 } | 802 } |
800 default: | 803 default: |
801 ExtensionProcessManager::Observe(type, source, details); | 804 ExtensionProcessManager::Observe(type, source, details); |
802 break; | 805 break; |
803 } | 806 } |
804 } | 807 } |
OLD | NEW |