| 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 "chrome/browser/extensions/event_router.h" | 5 #include "chrome/browser/extensions/event_router.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/extensions/extension_system.h" | 24 #include "chrome/browser/extensions/extension_system.h" |
| 25 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 25 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 26 #include "chrome/browser/extensions/process_map.h" | 26 #include "chrome/browser/extensions/process_map.h" |
| 27 #include "chrome/browser/extensions/system_info_event_router.h" | 27 #include "chrome/browser/extensions/system_info_event_router.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
| 30 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
| 31 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/common/extensions/api/extension_api.h" | 32 #include "chrome/common/extensions/api/extension_api.h" |
| 33 #include "chrome/common/extensions/background_info.h" |
| 33 #include "chrome/common/extensions/extension.h" | 34 #include "chrome/common/extensions/extension.h" |
| 34 #include "chrome/common/extensions/extension_messages.h" | 35 #include "chrome/common/extensions/extension_messages.h" |
| 35 #include "chrome/common/view_type.h" | 36 #include "chrome/common/view_type.h" |
| 36 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/render_process_host.h" | 38 #include "content/public/browser/render_process_host.h" |
| 38 | 39 |
| 39 using base::Value; | 40 using base::Value; |
| 40 using content::BrowserThread; | 41 using content::BrowserThread; |
| 41 | 42 |
| 42 namespace extensions { | 43 namespace extensions { |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 return true; | 551 return true; |
| 551 } | 552 } |
| 552 | 553 |
| 553 return false; | 554 return false; |
| 554 } | 555 } |
| 555 | 556 |
| 556 void EventRouter::IncrementInFlightEvents(Profile* profile, | 557 void EventRouter::IncrementInFlightEvents(Profile* profile, |
| 557 const Extension* extension) { | 558 const Extension* extension) { |
| 558 // Only increment in-flight events if the lazy background page is active, | 559 // Only increment in-flight events if the lazy background page is active, |
| 559 // because that's the only time we'll get an ACK. | 560 // because that's the only time we'll get an ACK. |
| 560 if (extension->has_lazy_background_page()) { | 561 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { |
| 561 ExtensionProcessManager* pm = | 562 ExtensionProcessManager* pm = |
| 562 ExtensionSystem::Get(profile)->process_manager(); | 563 ExtensionSystem::Get(profile)->process_manager(); |
| 563 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); | 564 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); |
| 564 if (host) | 565 if (host) |
| 565 pm->IncrementLazyKeepaliveCount(extension); | 566 pm->IncrementLazyKeepaliveCount(extension); |
| 566 } | 567 } |
| 567 } | 568 } |
| 568 | 569 |
| 569 void EventRouter::OnEventAck(Profile* profile, | 570 void EventRouter::OnEventAck(Profile* profile, |
| 570 const std::string& extension_id) { | 571 const std::string& extension_id) { |
| 571 ExtensionProcessManager* pm = | 572 ExtensionProcessManager* pm = |
| 572 ExtensionSystem::Get(profile)->process_manager(); | 573 ExtensionSystem::Get(profile)->process_manager(); |
| 573 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id); | 574 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id); |
| 574 // The event ACK is routed to the background host, so this should never be | 575 // The event ACK is routed to the background host, so this should never be |
| 575 // NULL. | 576 // NULL. |
| 576 CHECK(host); | 577 CHECK(host); |
| 577 // TODO(mpcomplete): We should never get this message unless | 578 // TODO(mpcomplete): We should never get this message unless |
| 578 // has_lazy_background_page is true. Find out why we're getting it anyway. | 579 // HasLazyBackgroundPage is true. Find out why we're getting it anyway. |
| 579 if (host->extension() && host->extension()->has_lazy_background_page()) | 580 if (host->extension() && |
| 581 BackgroundInfo::HasLazyBackgroundPage(host->extension())) |
| 580 pm->DecrementLazyKeepaliveCount(host->extension()); | 582 pm->DecrementLazyKeepaliveCount(host->extension()); |
| 581 } | 583 } |
| 582 | 584 |
| 583 void EventRouter::DispatchPendingEvent(const linked_ptr<Event>& event, | 585 void EventRouter::DispatchPendingEvent(const linked_ptr<Event>& event, |
| 584 ExtensionHost* host) { | 586 ExtensionHost* host) { |
| 585 if (!host) | 587 if (!host) |
| 586 return; | 588 return; |
| 587 | 589 |
| 588 if (listeners_.HasProcessListener(host->render_process_host(), | 590 if (listeners_.HasProcessListener(host->render_process_host(), |
| 589 host->extension()->id())) { | 591 host->extension()->id())) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 607 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 609 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
| 608 // We're done restarting Chrome after an update. | 610 // We're done restarting Chrome after an update. |
| 609 dispatch_chrome_updated_event_ = false; | 611 dispatch_chrome_updated_event_ = false; |
| 610 break; | 612 break; |
| 611 } | 613 } |
| 612 case chrome::NOTIFICATION_EXTENSION_ENABLED: { | 614 case chrome::NOTIFICATION_EXTENSION_ENABLED: { |
| 613 // If the extension has a lazy background page, make sure it gets loaded | 615 // If the extension has a lazy background page, make sure it gets loaded |
| 614 // to register the events the extension is interested in. | 616 // to register the events the extension is interested in. |
| 615 const Extension* extension = | 617 const Extension* extension = |
| 616 content::Details<const Extension>(details).ptr(); | 618 content::Details<const Extension>(details).ptr(); |
| 617 if (extension->has_lazy_background_page()) { | 619 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { |
| 618 LazyBackgroundTaskQueue* queue = | 620 LazyBackgroundTaskQueue* queue = |
| 619 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); | 621 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); |
| 620 queue->AddPendingTask(profile_, extension->id(), | 622 queue->AddPendingTask(profile_, extension->id(), |
| 621 base::Bind(&DoNothing)); | 623 base::Bind(&DoNothing)); |
| 622 } | 624 } |
| 623 } | 625 } |
| 624 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 626 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 625 // Add all registered lazy listeners to our cache. | 627 // Add all registered lazy listeners to our cache. |
| 626 const Extension* extension = | 628 const Extension* extension = |
| 627 content::Details<const Extension>(details).ptr(); | 629 content::Details<const Extension>(details).ptr(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 copy->will_dispatch_callback = will_dispatch_callback; | 722 copy->will_dispatch_callback = will_dispatch_callback; |
| 721 return copy; | 723 return copy; |
| 722 } | 724 } |
| 723 | 725 |
| 724 EventListenerInfo::EventListenerInfo(const std::string& event_name, | 726 EventListenerInfo::EventListenerInfo(const std::string& event_name, |
| 725 const std::string& extension_id) | 727 const std::string& extension_id) |
| 726 : event_name(event_name), | 728 : event_name(event_name), |
| 727 extension_id(extension_id) {} | 729 extension_id(extension_id) {} |
| 728 | 730 |
| 729 } // namespace extensions | 731 } // namespace extensions |
| OLD | NEW |