| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 void EventRouter::DispatchEvent(IPC::Sender* ipc_sender, | 157 void EventRouter::DispatchEvent(IPC::Sender* ipc_sender, |
| 158 void* profile_id, | 158 void* profile_id, |
| 159 const std::string& extension_id, | 159 const std::string& extension_id, |
| 160 const std::string& event_name, | 160 const std::string& event_name, |
| 161 scoped_ptr<ListValue> event_args, | 161 scoped_ptr<ListValue> event_args, |
| 162 const GURL& event_url, | 162 const GURL& event_url, |
| 163 UserGestureState user_gesture, | 163 UserGestureState user_gesture, |
| 164 const EventFilteringInfo& info) { | 164 const EventFilteringInfo& info) { |
| 165 DispatchExtensionMessage(ipc_sender, profile_id, extension_id, event_name, | 165 DispatchExtensionMessage(ipc_sender, profile_id, extension_id, event_name, |
| 166 event_args.get(), event_url, user_gesture, info); | 166 event_args.get(), event_url, user_gesture, info); |
| 167 |
| 168 BrowserThread::PostTask( |
| 169 BrowserThread::UI, |
| 170 FROM_HERE, |
| 171 base::Bind(&EventRouter::IncrementInFlightEventsOnUI, |
| 172 profile_id, |
| 173 extension_id)); |
| 167 } | 174 } |
| 168 | 175 |
| 169 EventRouter::EventRouter(Profile* profile, ExtensionPrefs* extension_prefs) | 176 EventRouter::EventRouter(Profile* profile, ExtensionPrefs* extension_prefs) |
| 170 : profile_(profile), | 177 : profile_(profile), |
| 171 listeners_(this), | 178 listeners_(this), |
| 172 activity_log_(ActivityLog::GetInstance(profile)), | 179 activity_log_(ActivityLog::GetInstance(profile)), |
| 173 dispatch_chrome_updated_event_(false) { | 180 dispatch_chrome_updated_event_(false) { |
| 174 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 181 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 175 content::NotificationService::AllSources()); | 182 content::NotificationService::AllSources()); |
| 176 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 183 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 551 |
| 545 queue->AddPendingTask(profile, extension->id(), | 552 queue->AddPendingTask(profile, extension->id(), |
| 546 base::Bind(&EventRouter::DispatchPendingEvent, | 553 base::Bind(&EventRouter::DispatchPendingEvent, |
| 547 base::Unretained(this), dispatched_event)); | 554 base::Unretained(this), dispatched_event)); |
| 548 return true; | 555 return true; |
| 549 } | 556 } |
| 550 | 557 |
| 551 return false; | 558 return false; |
| 552 } | 559 } |
| 553 | 560 |
| 561 // static |
| 562 void EventRouter::IncrementInFlightEventsOnUI( |
| 563 void* profile_id, |
| 564 const std::string& extension_id) { |
| 565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 566 Profile* profile = reinterpret_cast<Profile*>(profile_id); |
| 567 extensions::EventRouter* event_router = |
| 568 extensions::ExtensionSystem::Get(profile)->event_router(); |
| 569 ExtensionService* extension_service = |
| 570 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 571 const Extension* extension = |
| 572 extension_service->extensions()->GetByID(extension_id); |
| 573 if (!extension) |
| 574 return; |
| 575 event_router->IncrementInFlightEvents(profile, extension); |
| 576 } |
| 577 |
| 554 void EventRouter::IncrementInFlightEvents(Profile* profile, | 578 void EventRouter::IncrementInFlightEvents(Profile* profile, |
| 555 const Extension* extension) { | 579 const Extension* extension) { |
| 556 // Only increment in-flight events if the lazy background page is active, | 580 // Only increment in-flight events if the lazy background page is active, |
| 557 // because that's the only time we'll get an ACK. | 581 // because that's the only time we'll get an ACK. |
| 558 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { | 582 if (BackgroundInfo::HasLazyBackgroundPage(extension)) { |
| 559 ExtensionProcessManager* pm = | 583 ExtensionProcessManager* pm = |
| 560 ExtensionSystem::Get(profile)->process_manager(); | 584 ExtensionSystem::Get(profile)->process_manager(); |
| 561 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); | 585 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); |
| 562 if (host) | 586 if (host) |
| 563 pm->IncrementLazyKeepaliveCount(extension); | 587 pm->IncrementLazyKeepaliveCount(extension); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 copy->will_dispatch_callback = will_dispatch_callback; | 743 copy->will_dispatch_callback = will_dispatch_callback; |
| 720 return copy; | 744 return copy; |
| 721 } | 745 } |
| 722 | 746 |
| 723 EventListenerInfo::EventListenerInfo(const std::string& event_name, | 747 EventListenerInfo::EventListenerInfo(const std::string& event_name, |
| 724 const std::string& extension_id) | 748 const std::string& extension_id) |
| 725 : event_name(event_name), | 749 : event_name(event_name), |
| 726 extension_id(extension_id) {} | 750 extension_id(extension_id) {} |
| 727 | 751 |
| 728 } // namespace extensions | 752 } // namespace extensions |
| OLD | NEW |