Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: extensions/browser/event_router.cc

Issue 147923005: Split ExtensionSystem interface from ExtensionSystemImpl implementation, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "extensions/browser/event_router.h" 5 #include "extensions/browser/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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/extensions/extension_host.h" 15 #include "chrome/browser/extensions/extension_host.h"
16 #include "chrome/browser/extensions/extension_system.h"
17 #include "chrome/browser/extensions/extension_util.h" 16 #include "chrome/browser/extensions/extension_util.h"
18 #include "chrome/common/extensions/extension_messages.h" 17 #include "chrome/common/extensions/extension_messages.h"
19 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
21 #include "extensions/browser/extension_prefs.h" 20 #include "extensions/browser/extension_prefs.h"
22 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/browser/extension_system.h"
23 #include "extensions/browser/extensions_browser_client.h" 23 #include "extensions/browser/extensions_browser_client.h"
24 #include "extensions/browser/lazy_background_task_queue.h" 24 #include "extensions/browser/lazy_background_task_queue.h"
25 #include "extensions/browser/process_manager.h" 25 #include "extensions/browser/process_manager.h"
26 #include "extensions/browser/process_map.h" 26 #include "extensions/browser/process_map.h"
27 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
28 #include "extensions/common/extension_api.h" 28 #include "extensions/common/extension_api.h"
29 #include "extensions/common/extension_urls.h" 29 #include "extensions/common/extension_urls.h"
30 #include "extensions/common/manifest_handlers/background_info.h" 30 #include "extensions/common/manifest_handlers/background_info.h"
31 #include "extensions/common/manifest_handlers/incognito_info.h" 31 #include "extensions/common/manifest_handlers/incognito_info.h"
32 32
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 BrowserThread::UI, 75 BrowserThread::UI,
76 FROM_HERE, 76 FROM_HERE,
77 base::Bind(&NotifyExtensionDispatchObserverOnUIThread, 77 base::Bind(&NotifyExtensionDispatchObserverOnUIThread,
78 browser_context_id, base::Passed(&details))); 78 browser_context_id, base::Passed(&details)));
79 } else { 79 } else {
80 BrowserContext* context = 80 BrowserContext* context =
81 reinterpret_cast<BrowserContext*>(browser_context_id); 81 reinterpret_cast<BrowserContext*>(browser_context_id);
82 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) 82 if (!ExtensionsBrowserClient::Get()->IsValidContext(context))
83 return; 83 return;
84 ExtensionSystem* extension_system = 84 ExtensionSystem* extension_system =
85 ExtensionSystem::GetForBrowserContext(context); 85 ExtensionSystem::Get(context);
James Cook 2014/01/28 23:40:57 Can this be rewrapped?
Yoyo Zhou 2014/01/29 00:42:56 Done.
86 EventRouter* event_router = extension_system->event_router(); 86 EventRouter* event_router = extension_system->event_router();
87 if (!event_router) 87 if (!event_router)
88 return; 88 return;
89 if (event_router->event_dispatch_observer_) { 89 if (event_router->event_dispatch_observer_) {
90 event_router->event_dispatch_observer_->OnWillDispatchEvent( 90 event_router->event_dispatch_observer_->OnWillDispatchEvent(
91 details.Pass()); 91 details.Pass());
92 } 92 }
93 } 93 }
94 } 94 }
95 95
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 } 567 }
568 568
569 bool EventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent( 569 bool EventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent(
570 BrowserContext* context, 570 BrowserContext* context,
571 const Extension* extension, 571 const Extension* extension,
572 const linked_ptr<Event>& event) { 572 const linked_ptr<Event>& event) {
573 if (extension->is_ephemeral() && !event->can_load_ephemeral_apps) { 573 if (extension->is_ephemeral() && !event->can_load_ephemeral_apps) {
574 // Most events can only be dispatched to ephemeral apps that are already 574 // Most events can only be dispatched to ephemeral apps that are already
575 // running. 575 // running.
576 ProcessManager* pm = 576 ProcessManager* pm =
577 ExtensionSystem::GetForBrowserContext(context)->process_manager(); 577 ExtensionSystem::Get(context)->process_manager();
James Cook 2014/01/28 23:40:57 ditto? There might be a way to run clang-format j
578 if (!pm->GetBackgroundHostForExtension(extension->id())) 578 if (!pm->GetBackgroundHostForExtension(extension->id()))
579 return false; 579 return false;
580 } 580 }
581 581
582 if (!CanDispatchEventToBrowserContext(context, extension, event)) 582 if (!CanDispatchEventToBrowserContext(context, extension, event))
583 return false; 583 return false;
584 584
585 LazyBackgroundTaskQueue* queue = ExtensionSystem::GetForBrowserContext( 585 LazyBackgroundTaskQueue* queue = ExtensionSystem::Get(
586 context)->lazy_background_task_queue(); 586 context)->lazy_background_task_queue();
587 if (queue->ShouldEnqueueTask(context, extension)) { 587 if (queue->ShouldEnqueueTask(context, extension)) {
588 linked_ptr<Event> dispatched_event(event); 588 linked_ptr<Event> dispatched_event(event);
589 589
590 // If there's a dispatch callback, call it now (rather than dispatch time) 590 // If there's a dispatch callback, call it now (rather than dispatch time)
591 // to avoid lifetime issues. Use a separate copy of the event args, so they 591 // to avoid lifetime issues. Use a separate copy of the event args, so they
592 // last until the event is dispatched. 592 // last until the event is dispatched.
593 if (!event->will_dispatch_callback.is_null()) { 593 if (!event->will_dispatch_callback.is_null()) {
594 dispatched_event.reset(event->DeepCopy()); 594 dispatched_event.reset(event->DeepCopy());
595 dispatched_event->will_dispatch_callback.Run( 595 dispatched_event->will_dispatch_callback.Run(
(...skipping 14 matching lines...) Expand all
610 // static 610 // static
611 void EventRouter::IncrementInFlightEventsOnUI( 611 void EventRouter::IncrementInFlightEventsOnUI(
612 void* browser_context_id, 612 void* browser_context_id,
613 const std::string& extension_id) { 613 const std::string& extension_id) {
614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
615 BrowserContext* browser_context = 615 BrowserContext* browser_context =
616 reinterpret_cast<BrowserContext*>(browser_context_id); 616 reinterpret_cast<BrowserContext*>(browser_context_id);
617 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) 617 if (!ExtensionsBrowserClient::Get()->IsValidContext(browser_context))
618 return; 618 return;
619 ExtensionSystem* extension_system = 619 ExtensionSystem* extension_system =
620 ExtensionSystem::GetForBrowserContext(browser_context); 620 ExtensionSystem::Get(browser_context);
621 EventRouter* event_router = extension_system->event_router(); 621 EventRouter* event_router = extension_system->event_router();
622 if (!event_router) 622 if (!event_router)
623 return; 623 return;
624 const Extension* extension = 624 const Extension* extension =
625 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID( 625 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID(
626 extension_id); 626 extension_id);
627 if (!extension) 627 if (!extension)
628 return; 628 return;
629 event_router->IncrementInFlightEvents(browser_context, extension); 629 event_router->IncrementInFlightEvents(browser_context, extension);
630 } 630 }
631 631
632 void EventRouter::IncrementInFlightEvents(BrowserContext* context, 632 void EventRouter::IncrementInFlightEvents(BrowserContext* context,
633 const Extension* extension) { 633 const Extension* extension) {
634 // Only increment in-flight events if the lazy background page is active, 634 // Only increment in-flight events if the lazy background page is active,
635 // because that's the only time we'll get an ACK. 635 // because that's the only time we'll get an ACK.
636 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { 636 if (BackgroundInfo::HasLazyBackgroundPage(extension)) {
637 ProcessManager* pm = 637 ProcessManager* pm =
638 ExtensionSystem::GetForBrowserContext(context)->process_manager(); 638 ExtensionSystem::Get(context)->process_manager();
639 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); 639 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id());
640 if (host) 640 if (host)
641 pm->IncrementLazyKeepaliveCount(extension); 641 pm->IncrementLazyKeepaliveCount(extension);
642 } 642 }
643 } 643 }
644 644
645 void EventRouter::OnEventAck(BrowserContext* context, 645 void EventRouter::OnEventAck(BrowserContext* context,
646 const std::string& extension_id) { 646 const std::string& extension_id) {
647 ProcessManager* pm = 647 ProcessManager* pm =
648 ExtensionSystem::GetForBrowserContext(context)->process_manager(); 648 ExtensionSystem::Get(context)->process_manager();
649 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id); 649 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id);
650 // The event ACK is routed to the background host, so this should never be 650 // The event ACK is routed to the background host, so this should never be
651 // NULL. 651 // NULL.
652 CHECK(host); 652 CHECK(host);
653 // TODO(mpcomplete): We should never get this message unless 653 // TODO(mpcomplete): We should never get this message unless
654 // HasLazyBackgroundPage is true. Find out why we're getting it anyway. 654 // HasLazyBackgroundPage is true. Find out why we're getting it anyway.
655 if (host->extension() && 655 if (host->extension() &&
656 BackgroundInfo::HasLazyBackgroundPage(host->extension())) 656 BackgroundInfo::HasLazyBackgroundPage(host->extension()))
657 pm->DecrementLazyKeepaliveCount(host->extension()); 657 pm->DecrementLazyKeepaliveCount(host->extension());
658 } 658 }
(...skipping 21 matching lines...) Expand all
680 // Remove all event listeners associated with this renderer. 680 // Remove all event listeners associated with this renderer.
681 listeners_.RemoveListenersForProcess(renderer); 681 listeners_.RemoveListenersForProcess(renderer);
682 break; 682 break;
683 } 683 }
684 case chrome::NOTIFICATION_EXTENSION_ENABLED: { 684 case chrome::NOTIFICATION_EXTENSION_ENABLED: {
685 // If the extension has a lazy background page, make sure it gets loaded 685 // If the extension has a lazy background page, make sure it gets loaded
686 // to register the events the extension is interested in. 686 // to register the events the extension is interested in.
687 const Extension* extension = 687 const Extension* extension =
688 content::Details<const Extension>(details).ptr(); 688 content::Details<const Extension>(details).ptr();
689 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { 689 if (BackgroundInfo::HasLazyBackgroundPage(extension)) {
690 LazyBackgroundTaskQueue* queue = ExtensionSystem::GetForBrowserContext( 690 LazyBackgroundTaskQueue* queue = ExtensionSystem::Get(
691 browser_context_)->lazy_background_task_queue(); 691 browser_context_)->lazy_background_task_queue();
692 queue->AddPendingTask(browser_context_, extension->id(), 692 queue->AddPendingTask(browser_context_, extension->id(),
693 base::Bind(&DoNothing)); 693 base::Bind(&DoNothing));
694 } 694 }
695 break; 695 break;
696 } 696 }
697 case chrome::NOTIFICATION_EXTENSION_LOADED: { 697 case chrome::NOTIFICATION_EXTENSION_LOADED: {
698 // Add all registered lazy listeners to our cache. 698 // Add all registered lazy listeners to our cache.
699 const Extension* extension = 699 const Extension* extension =
700 content::Details<const Extension>(details).ptr(); 700 content::Details<const Extension>(details).ptr();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 EventDispatchInfo::EventDispatchInfo(const std::string& extension_id, 781 EventDispatchInfo::EventDispatchInfo(const std::string& extension_id,
782 const std::string& event_name, 782 const std::string& event_name,
783 scoped_ptr<ListValue> event_args) 783 scoped_ptr<ListValue> event_args)
784 : extension_id(extension_id), 784 : extension_id(extension_id),
785 event_name(event_name), 785 event_name(event_name),
786 event_args(event_args.Pass()) {} 786 event_args(event_args.Pass()) {}
787 787
788 EventDispatchInfo::~EventDispatchInfo() {} 788 EventDispatchInfo::~EventDispatchInfo() {}
789 789
790 } // namespace extensions 790 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698