| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 void EventRouter::DispatchEvent(IPC::Sender* ipc_sender, | 165 void EventRouter::DispatchEvent(IPC::Sender* ipc_sender, |
| 166 void* profile_id, | 166 void* profile_id, |
| 167 const std::string& extension_id, | 167 const std::string& extension_id, |
| 168 const std::string& event_name, | 168 const std::string& event_name, |
| 169 scoped_ptr<ListValue> event_args, | 169 scoped_ptr<ListValue> event_args, |
| 170 const GURL& event_url, | 170 const GURL& event_url, |
| 171 UserGestureState user_gesture, | 171 UserGestureState user_gesture, |
| 172 const EventFilteringInfo& info) { | 172 const EventFilteringInfo& info) { |
| 173 DispatchExtensionMessage(ipc_sender, profile_id, extension_id, event_name, | 173 DispatchExtensionMessage(ipc_sender, profile_id, extension_id, event_name, |
| 174 event_args.get(), event_url, user_gesture, info); | 174 event_args.get(), event_url, user_gesture, info); |
| 175 |
| 176 BrowserThread::PostTask( |
| 177 BrowserThread::UI, |
| 178 FROM_HERE, |
| 179 base::Bind(&EventRouter::IncrementInFlightEventsOnUI, |
| 180 profile_id, |
| 181 extension_id)); |
| 175 } | 182 } |
| 176 | 183 |
| 177 EventRouter::EventRouter(Profile* profile, ExtensionPrefs* extension_prefs) | 184 EventRouter::EventRouter(Profile* profile, ExtensionPrefs* extension_prefs) |
| 178 : profile_(profile), | 185 : profile_(profile), |
| 179 listeners_(this), | 186 listeners_(this), |
| 180 activity_log_(ActivityLog::GetInstance(profile)), | 187 activity_log_(ActivityLog::GetInstance(profile)), |
| 181 dispatch_chrome_updated_event_(false) { | 188 dispatch_chrome_updated_event_(false) { |
| 182 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 189 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 183 content::NotificationService::AllSources()); | 190 content::NotificationService::AllSources()); |
| 184 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 191 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 | 661 |
| 655 queue->AddPendingTask(profile, extension->id(), | 662 queue->AddPendingTask(profile, extension->id(), |
| 656 base::Bind(&EventRouter::DispatchPendingEvent, | 663 base::Bind(&EventRouter::DispatchPendingEvent, |
| 657 base::Unretained(this), dispatched_event)); | 664 base::Unretained(this), dispatched_event)); |
| 658 return true; | 665 return true; |
| 659 } | 666 } |
| 660 | 667 |
| 661 return false; | 668 return false; |
| 662 } | 669 } |
| 663 | 670 |
| 671 // static |
| 672 void EventRouter::IncrementInFlightEventsOnUI( |
| 673 void* profile_id, |
| 674 const std::string& extension_id) { |
| 675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 676 Profile* profile = reinterpret_cast<Profile*>(profile_id); |
| 677 extensions::EventRouter* event_router = |
| 678 extensions::ExtensionSystem::Get(profile)->event_router(); |
| 679 if (!event_router) |
| 680 return; |
| 681 ExtensionService* extension_service = |
| 682 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 683 const Extension* extension = |
| 684 extension_service->extensions()->GetByID(extension_id); |
| 685 if (!extension) |
| 686 return; |
| 687 event_router->IncrementInFlightEvents(profile, extension); |
| 688 } |
| 689 |
| 664 void EventRouter::IncrementInFlightEvents(Profile* profile, | 690 void EventRouter::IncrementInFlightEvents(Profile* profile, |
| 665 const Extension* extension) { | 691 const Extension* extension) { |
| 666 // Only increment in-flight events if the lazy background page is active, | 692 // Only increment in-flight events if the lazy background page is active, |
| 667 // because that's the only time we'll get an ACK. | 693 // because that's the only time we'll get an ACK. |
| 668 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { | 694 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { |
| 669 ExtensionProcessManager* pm = | 695 ExtensionProcessManager* pm = |
| 670 ExtensionSystem::Get(profile)->process_manager(); | 696 ExtensionSystem::Get(profile)->process_manager(); |
| 671 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); | 697 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); |
| 672 if (host) | 698 if (host) |
| 673 pm->IncrementLazyKeepaliveCount(extension); | 699 pm->IncrementLazyKeepaliveCount(extension); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 copy->will_dispatch_callback = will_dispatch_callback; | 854 copy->will_dispatch_callback = will_dispatch_callback; |
| 829 return copy; | 855 return copy; |
| 830 } | 856 } |
| 831 | 857 |
| 832 EventListenerInfo::EventListenerInfo(const std::string& event_name, | 858 EventListenerInfo::EventListenerInfo(const std::string& event_name, |
| 833 const std::string& extension_id) | 859 const std::string& extension_id) |
| 834 : event_name(event_name), | 860 : event_name(event_name), |
| 835 extension_id(extension_id) {} | 861 extension_id(extension_id) {} |
| 836 | 862 |
| 837 } // namespace extensions | 863 } // namespace extensions |
| OLD | NEW |